Skip to content

Commit

Permalink
Don't eliminate parameters that are initial assignment targets (pt2)
Browse files Browse the repository at this point in the history
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 AMICI-dev#2304) as amici expressions.
Those static expressions will be handled more efficiently after AMICI-dev#2303.

Related to AMICI-dev#2150.
  • Loading branch information
dweindl committed Feb 23, 2024
1 parent 4334557 commit 3e1f906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 11 additions & 10 deletions python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def _gather_base_locals(
"INF": sp.oo,
"NaN": sp.nan,
"rem": sp.Mod,
"time": symbol_with_assumptions("time"),
"time": sbml_time_symbol,
# SBML L3 explicitly defines this value, which is not equal
# to the most recent SI definition.
"avogadro": sp.Float(6.02214179e23),
Expand Down Expand Up @@ -1095,13 +1095,14 @@ def _process_parameters(
}

# Parameters that need to be turned into expressions
# so far, this concerns parameters with initial assignments containing rateOf(.)
# (those have been skipped above)
# so far, this concerns parameters with symbolic initial assignments
# (those have been skipped above) that are not rate rule targets
for par in self.sbml.getListOfParameters():
if (
ia := self._get_element_initial_assignment(par.getId())
) is not None and ia.find(
sp.core.function.UndefinedFunction("rateOf")
(ia := self._get_element_initial_assignment(par.getId()))
is not None
and not ia.is_Number
and not self.is_rate_rule_target(par)
):
self.symbols[SymbolId.EXPRESSION][
_get_identifier_symbol(par)
Expand Down Expand Up @@ -1877,7 +1878,9 @@ def _process_initial_assignments(self):
for ia in self.sbml.getListOfInitialAssignments():
identifier = _get_identifier_symbol(ia)
if identifier in itt.chain(
self.symbols[SymbolId.SPECIES], self.compartments
self.symbols[SymbolId.SPECIES],
self.compartments,
self.symbols[SymbolId.EXPRESSION],
):
continue

Expand Down Expand Up @@ -1951,9 +1954,7 @@ def _make_initial(
if "init" in species:
sym_math = smart_subs(sym_math, species_id, species["init"])

sym_math = smart_subs(
sym_math, self._local_symbols["time"], sp.Float(0)
)
sym_math = smart_subs(sym_math, sbml_time_symbol, sp.Float(0))

sym_math = _dummy_to_rateof(sym_math, rateof_to_dummy)

Expand Down
4 changes: 3 additions & 1 deletion tests/testSBMLSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ def verify_results(settings, rdata, expected, wrapper, model, atol, rtol):
# collect parameters
for par in model.getParameterIds():
simulated[par] = rdata["ts"] * 0 + model.getParameterById(par)
# collect fluxes
# collect fluxes and other expressions
for expr_idx, expr_id in enumerate(model.getExpressionIds()):
if expr_id.startswith("flux_"):
simulated[expr_id.removeprefix("flux_")] = rdata.w[:, expr_idx]
else:
simulated[expr_id] = rdata.w[:, expr_idx]
# handle renamed reserved symbols
simulated.rename(
columns={c: c.replace("amici_", "") for c in simulated.columns},
Expand Down

0 comments on commit 3e1f906

Please sign in to comment.