Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5692 closed defect (invalid)

segfault after "Invalid root".

Reported by: john.pye@… Owned by: Lennart Ochel
Priority: high Milestone: 1.16.0
Component: Run-time Version: v.1.15.0-dev
Keywords: Cc:

Description

I have a simulation which fails due to an 'Invalid root' in one of my equations (specifically, trying to solve T(h) for the properties of an incompressible substance, through calls to omc_SolarTherm_Media_SolidParticles_CarboHSPutilities_Th).

The output I get from my test script is as follows. We've previously reported the warning messages about the floating-point constant, so that's a different issue. The issue here is something is causing the model executable to segfault here, when it should really just be exiting with an error code (or continuing, even).

Something is apparently causing the solver to segfault from the 'solveNewton' function in libSimulationRuntimeC.so. Surely that isn't intended?

The actually command-line being run here (after compilation of the model) is

./PhysicalParticleSystem -override startTime=0.0,stopTime=31536000.0,stepSize=300.0 -s dassl -lv -LOG_SUCCESS,-stdout -f PhysicalParticleSystem_init.xml -r PhysicalParticleSystem_res.mat -nls newton

The version is OpenModelica 1.15.0~dev-9-g34505da.

And here is the output, including some extra output from the compilation process, wrapper script, etc.:

<env>john@thunder:~/src/solartherm/tests$ python TestPhysicalParticleSystem.py
Notification: Automatically loaded package Complex 3.2.2 due to uses annotation.
Notification: Automatically loaded package ModelicaServices 3.2.2 due to uses annotation.

[/usr/lib/omlibrary/Modelica 3.2.2/Blocks/Sources.mo:2346:7-2347:66:readonly] Warning: Unused input variable tableAvailable in function .Modelica.Blocks.Sources.CombiTimeTable$data$table.getDerTableValue.
[/usr/lib/omlibrary/Modelica 3.2.2/Blocks/Sources.mo:2312:7-2313:66:readonly] Warning: Unused input variable tableAvailable in function .Modelica.Blocks.Sources.CombiTimeTable$data$table.getTableValue.
[/usr/lib/omlibrary/Modelica 3.2.2/Blocks/Sources.mo:2358:7-2359:66:readonly] Warning: Unused input variable tableAvailable in function .Modelica.Blocks.Sources.CombiTimeTable$data$table.getTableTimeTmin.
[/usr/lib/omlibrary/Modelica 3.2.2/Blocks/Sources.mo:2369:7-2370:66:readonly] Warning: Unused input variable tableAvailable in function .Modelica.Blocks.Sources.CombiTimeTable$data$table.getTableTimeTmax.

PhysicalParticleSystem.c:850:98: warning: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]
    tmp11 = Less(data->localData[0]->realVars[163] /* data.table.nextTimeEventScaled DISCRETE */,1.797693134862316e+308);
                                                                                                 ^
PhysicalParticleSystem.c:851:168: warning: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]
  .../* data.table.nextTimeEvent DISCRETE */ = (tmp11?data->localData[0]->realVars[163] /* data.table.nextTimeEventScaled DISCRETE */:1.797693134862316e+308);
                                                                                                                                      ^
PhysicalParticleSystem_06inz.c:2121:96: warning: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]
  tmp50 = Less(data->localData[0]->realVars[163] /* data.table.nextTimeEventScaled DISCRETE */,1.797693134862316e+308);
                                                                                               ^
PhysicalParticleSystem_06inz.c:2122:166: warning: magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308 [-Wliteral-range]
  .../* data.table.nextTimeEvent DISCRETE */ = (tmp50?data->localData[0]->realVars[163] /* data.table.nextTimeEventScaled DISCRETE */:1.797693134862316e+308);
                                                                                                                                      ^
2 warnings generated.
2 warnings generated.
/usr/bin/../lib/x86_64-linux-gnu/omc/libModelicaMatIO.a(ModelicaMatIO.o): In function `Mat_VarDelete':
(.text+0x1e14): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
assert            | debug   | PhysicalParticleSystem_functions.c:488: Invalid root: (-1991.1)^(0.763767)
assert            | debug   | Solving non-linear system 977 failed at time=9040492.36941685.
|                 | |       | For more information please use -lv LOG_NLS.

Limited backtrace at point of segmentation fault
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7ffbb01af390]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(solveNewton+0xda)[0x7ffbb1617385]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(solveNLS+0xb1)[0x7ffbb15f8b05]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(solve_nonlinear_system+0x307)[0x7ffbb15f9057]
./PhysicalParticleSystem(PhysicalParticleSystem_eqFunction_977+0x7f)[0x41ade3]
./PhysicalParticleSystem(PhysicalParticleSystem_functionDAE+0x496)[0x41d676]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(updateDiscreteSystem+0x83)[0x7ffbb1605d0b]
./PhysicalParticleSystem(PhysicalParticleSystem_performSimulation+0xcca)[0x41773a]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(solver_main+0x302)[0x7ffbb160d669]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(+0x86921)[0x7ffbb1632921]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(startNonInteractiveSimulation+0x9f4)[0x7ffbb1631cec]
/usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so(_main_SimulationRuntime+0x73)[0x7ffbb1634181]
./PhysicalParticleSystem(main+0x1ac)[0x41e613]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ffbafdf4830]
./PhysicalParticleSystem(_start+0x29)[0x416999]
E
======================================================================
ERROR: test_sched (__main__.TestPhysicalParticleSystem)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "TestPhysicalParticleSystem.py", line 28, in test_sched
    sim.simulate(start=0, stop='1y', step='5m',solver='dassl', nls='newton')
  File "/home/john/.local/lib/python2.7/site-packages/solartherm/simulation.py", line 360, in simulate
    sp.check_call(['./'+self.model] + sim_args + args)
  File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['./PhysicalParticleSystem', '-override', 'startTime=0.0,stopTime=31536000.0,stepSize=300.0', '-s', 'dassl', '-lv', '-LOG_SUCCESS,-stdout', '-f', 'PhysicalParticleSystem_init.xml', '-r', 'PhysicalParticleSystem_res.mat', '-nls', 'newton']' returned non-zero exit status -11

----------------------------------------------------------------------
Ran 1 test in 5.896s

FAILED (errors=1)

Change History (6)

comment:1 by anonymous, 5 years ago

Here is a little bit more output, when LOG_NLS is turned on, as suggested in the output:

LOG_NLS           | info    | ############ Solve nonlinear system 977 at time 9.04049e+06 ############
|                 | |       | | initial variable values:
|                 | |       | | | [ 1]                 receiver.h_out  =        855003.86		 nom =          1000000
|                 | |       | | Solution status: SOLVED
|                 | |       | | |  number of iterations           : 306720
|                 | |       | | |  number of function evaluations : 2193089
|                 | |       | | |  number of jacobian evaluations : 302875
|                 | |       | | | solution values:
|                 | |       | | | [ 1]                 receiver.h_out  =        854561.55
LOG_NLS           | info    | ############ Solve nonlinear system 977 at time 9.04049e+06 ############
|                 | |       | | initial variable values:
|                 | |       | | | [ 1]                 receiver.h_out  =        854561.55		 nom =          1000000
assert            | debug   | PhysicalParticleSystem_functions.c:488: Invalid root: (-1991.1)^(0.763767)
LOG_NLS           | info    | | Solution status: FAILED
|                 | |       | | |  number of iterations           : 306720
|                 | |       | | |  number of function evaluations : 2193089
|                 | |       | | |  number of jacobian evaluations : 302876
|                 | |       | | | solution values:
|                 | |       | | | [ 1]                 receiver.h_out  =        854561.55
LOG_NLS           | warning | nonlinear system 977 fails: at t=9.04049e+06
assert            | debug   | Solving non-linear system 977 failed at time=9040492.36941685.
|                 | |       | For more information please use -lv LOG_NLS.
LOG_NLS           | info    | ############ Solve nonlinear system 977 at time 9.0402e+06 ############
|                 | |       | | initial variable values:
|                 | |       | | | [ 1]                 receiver.h_out  =        855003.86		 nom =          1000000

Thread 1 "PhysicalParticl" received signal SIGSEGV, Segmentation fault.
0x00007ffff7b58385 in solveNewton () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
(gdb) where
#0  0x00007ffff7b58385 in solveNewton () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#1  0x00007ffff7b39b05 in solveNLS () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#2  0x00007ffff7b3a057 in solve_nonlinear_system () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#3  0x000000000041ade3 in PhysicalParticleSystem_eqFunction_977 ()
#4  0x000000000041d676 in PhysicalParticleSystem_functionDAE ()
#5  0x00007ffff7b46d0b in updateDiscreteSystem () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#6  0x000000000041773a in PhysicalParticleSystem_performSimulation ()
#7  0x00007ffff7b4e669 in solver_main () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#8  0x00007ffff7b73921 in ?? () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#9  0x00007ffff7b72cec in startNonInteractiveSimulation () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#10 0x00007ffff7b75181 in _main_SimulationRuntime () from /usr/bin/../lib/x86_64-linux-gnu/omc/libSimulationRuntimeC.so
#11 0x000000000041e613 in main ()
(gdb) 

comment:2 by Francesco Casella, 5 years ago

First comment, I would suggest you to upgrade the uses annotations of your library to MSL 3.2.3 and related libraries. There's lots of bugfixes there compared with 3.2.2, and it's expected to be fully backwards compatible without any conversion needed.

I'm not sure if that solves your problem.

comment:3 by Francesco Casella, 5 years ago

It would also be good if you locate equation 977 with the declarative debugger (click on the blue bug icon), expand all the involved equations, and post a .png image of that. Than we can try better to figure out what could go wrong in the solution of that nonlinear system.

Also, are the values of receiver.h_out that we see before the crash reasonable or not?

comment:4 by Francesco Casella, 5 years ago

@john, any update?

comment:5 by Martin Sjölund, 5 years ago

Milestone: FutureNeedsInput
Resolution: invalid
Status: newclosed

Closing this until there's enough to reproduce or figure out what goes wrong. I tried a small model to trigger the same root finding error, but it does not crash:

model M
  function f
    input Real r;
    input Real t;
    output Real o;
  algorithm
    o := 1*r;
    o := o*r;
    o := if t > 0.1 then (-2.1) ^ 0.76 else 0.5*o;
  end f;
  Real r;
equation
  r = f(r, time);
end M;

comment:6 by Francesco Casella, 5 years ago

Milestone: NeedsInput1.16.0
Note: See TracTickets for help on using tickets.