From c0c0cdf6f54b8d39e39cd6a0541aecc67de933d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Fr=C3=B6hlich?= Date: Fri, 31 Jan 2025 21:14:20 +0000 Subject: [PATCH] fixup --- python/sdist/amici/sbml_import.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/python/sdist/amici/sbml_import.py b/python/sdist/amici/sbml_import.py index 1ae00d1486..796af2507b 100644 --- a/python/sdist/amici/sbml_import.py +++ b/python/sdist/amici/sbml_import.py @@ -2292,16 +2292,25 @@ def _make_initial( sym_math, rateof_to_dummy = _rateof_to_dummy(sym_math) + # we can't rely on anything else being properly initialized at this point, so we need to + # compute all initial values from scratch, recursively for var in sym_math.free_symbols: + element_id = str(var) # already recursive since _get_element_initial_assignment calls _make_initial - ia = self._get_element_initial_assignment(str(var)) - if ia is not None: + if ( + ia := self._get_element_initial_assignment(element_id) + ) is not None: sym_math = sym_math.subs(var, ia) - - elif (species := self.sbml.getSpecies(str(var))) is not None: + elif (species := self.sbml.getSpecies(element_id)) is not None: # recursive! init = self._make_initial(get_species_initial(species)) sym_math = sym_math.subs(var, init) + elif ( + element := self.sbml.getElementBySId(element_id) + ) and self.is_rate_rule_target(element): + # no need to recurse here, as value is numeric + init = sp.Float(element.getValue()) + sym_math = sym_math.subs(var, init) sym_math = smart_subs(sym_math, sbml_time_symbol, sp.Float(0))