ComputationalPhysiology / gotran

Library for declaring and translating ODEs
http://computationalphysiology.github.io/gotran/
GNU Lesser General Public License v3.0
2 stars 1 forks source link

Flaky KeyError when loading ode #24

Open finsberg opened 2 years ago

finsberg commented 2 years ago

When loading some odes I sometimes get the following error

Loaded ODE model 'tentusscher_panfilov_2006_M_cell' with:
     Num full states: 19
      Num parameters: 53
Traceback (most recent call last):
  File "/Users/henriknf/local/src/goss/demo/tentusscher_panfilov_2006_M_cell/demo.py", line 6, in <module>
    ode = goss.ODE(gotran_ode)
  File "/Users/henriknf/local/src/goss/python/goss/ode.py", line 22, in __init__
    self._cpp_object = jit(args[0], **kwargs)
  File "/Users/henriknf/local/src/goss/python/goss/compilemodule.py", line 108, in jit
    python_object = cppyy_jit(
  File "/Users/henriknf/local/src/goss/python/goss/compilemodule.py", line 59, in cppyy_jit
    cpp_code = cgen.file_code()
  File "/Users/henriknf/local/src/goss/python/goss/codegeneration.py", line 360, in file_code
    self.file_form["CLASS_DECLARATION"] = self.class_code()
  File "/Users/henriknf/local/src/goss/python/goss/codegeneration.py", line 349, in class_code
    self._eval_linearized_code()
  File "/Users/henriknf/local/src/goss/python/goss/codegeneration.py", line 561, in _eval_linearized_code
    lin = linearized_derivatives(
  File "/Users/henriknf/local/src/gotran/gotran/codegeneration/algorithmcomponents.py", line 232, in linearized_derivatives
    return LinearizedDerivativeComponent(
  File "/Users/henriknf/local/src/gotran/gotran/codegeneration/algorithmcomponents.py", line 1049, in __init__
    self.add_indexed_expression(
  File "/Users/henriknf/local/src/gotran/gotran/codegeneration/codecomponent.py", line 249, in add_indexed_expression
    self._register_component_object(expr, dependent)
  File "/Users/henriknf/local/src/gotran/gotran/model/odecomponent.py", line 769, in _register_component_object
    self.root.register_ode_object(obj, self, dependent)
  File "/Users/henriknf/local/src/gotran/gotran/model/ode.py", line 681, in register_ode_object
    expression_added |= self._expand_single_derivative(
  File "/Users/henriknf/local/src/gotran/gotran/model/ode.py", line 1113, in _expand_single_derivative
    var_obj = self.present_ode_objects[sympycode(der_expr.args[1])]
KeyError: '_xi_5'

However, the error is very flaky, meaning that running the command again might succeed.

finsberg commented 1 year ago

The following program

import gotran

path = "demo/gotran2c/tentusscher_panfilov_2006_M_cell.ode"

ode = gotran.load_ode(path)
lin = gotran.codegeneration.algorithmcomponents.linearized_derivatives(ode)

fails in about 10% of the cases. Note however that

import gotran

path = "demo/gotran2c/tentusscher_panfilov_2006_M_cell.ode"

for _ range(100):
    ode = gotran.load_ode(path)
    lin = gotran.codegeneration.algorithmcomponents.linearized_derivatives(ode)

works fine, so it seems to be some state that is carried from the import.

finsberg commented 1 year ago

Still a problem https://github.com/ComputationalPhysiology/goss/actions/runs/4124734861/jobs/7124354344#step:6:868