Skip to content

Commit 5e386ee

Browse files
authored
Don't eliminate parameters that are initial assignment targets (pt2) (#2305)
Currently, parameters that are targets of initial assignments don't show up as parameters or expressions in the amici model. This is rather not what most users would expect. Therefore, treat all SBML parameters that are initial assignment targets and whose initial assignment does not evaluate to a number (for those that do, see #2304) as amici expressions. Those static expressions will be handled more efficiently after #2303. Related to #2150. See also #2304.
1 parent e679e51 commit 5e386ee

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

python/sdist/amici/sbml_import.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def _gather_base_locals(
722722
"INF": sp.oo,
723723
"NaN": sp.nan,
724724
"rem": sp.Mod,
725-
"time": symbol_with_assumptions("time"),
725+
"time": sbml_time_symbol,
726726
# SBML L3 explicitly defines this value, which is not equal
727727
# to the most recent SI definition.
728728
"avogadro": sp.Float(6.02214179e23),
@@ -1108,11 +1108,13 @@ def _process_parameters(
11081108
}
11091109

11101110
# Parameters that need to be turned into expressions
1111-
# so far, this concerns parameters with initial assignments containing rateOf(.)
1112-
# (those have been skipped above)
1111+
# so far, this concerns parameters with symbolic initial assignments
1112+
# (those have been skipped above) that are not rate rule targets
11131113
for par in self.sbml.getListOfParameters():
1114-
if (ia := par_id_to_ia.get(par.getId())) is not None and ia.find(
1115-
sp.core.function.UndefinedFunction("rateOf")
1114+
if (
1115+
(ia := par_id_to_ia.get(par.getId())) is not None
1116+
and not ia.is_Number
1117+
and not self.is_rate_rule_target(par)
11161118
):
11171119
self.symbols[SymbolId.EXPRESSION][
11181120
_get_identifier_symbol(par)
@@ -1890,6 +1892,7 @@ def _process_initial_assignments(self):
18901892
if identifier in itt.chain(
18911893
self.symbols[SymbolId.SPECIES],
18921894
self.compartments,
1895+
self.symbols[SymbolId.EXPRESSION],
18931896
self.symbols[SymbolId.PARAMETER],
18941897
self.symbols[SymbolId.FIXED_PARAMETER],
18951898
):
@@ -1965,9 +1968,7 @@ def _make_initial(
19651968
if "init" in species:
19661969
sym_math = smart_subs(sym_math, species_id, species["init"])
19671970

1968-
sym_math = smart_subs(
1969-
sym_math, self._local_symbols["time"], sp.Float(0)
1970-
)
1971+
sym_math = smart_subs(sym_math, sbml_time_symbol, sp.Float(0))
19711972

19721973
sym_math = _dummy_to_rateof(sym_math, rateof_to_dummy)
19731974

tests/testSBMLSuite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ def verify_results(settings, rdata, expected, wrapper, model, atol, rtol):
130130
# collect parameters
131131
for par in model.getParameterIds():
132132
simulated[par] = rdata["ts"] * 0 + model.getParameterById(par)
133-
# collect fluxes
133+
# collect fluxes and other expressions
134134
for expr_idx, expr_id in enumerate(model.getExpressionIds()):
135135
if expr_id.startswith("flux_"):
136136
simulated[expr_id.removeprefix("flux_")] = rdata.w[:, expr_idx]
137+
elif expr_id.removeprefix("amici_") not in simulated.columns:
138+
simulated[expr_id] = rdata.w[:, expr_idx]
137139
# handle renamed reserved symbols
138140
simulated.rename(
139141
columns={c: c.replace("amici_", "") for c in simulated.columns},

0 commit comments

Comments
 (0)