Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky KeyError when loading ode #24

Open
finsberg opened this issue Feb 18, 2022 · 2 comments · Fixed by #40 or #42
Open

Flaky KeyError when loading ode #24

finsberg opened this issue Feb 18, 2022 · 2 comments · Fixed by #40 or #42

Comments

@finsberg
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

finsberg commented Feb 8, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant