Skip to content

Commit

Permalink
Deterministic order of event assignments (AMICI-dev#2242)
Browse files Browse the repository at this point in the history
Ensure event assignments targets are processed in deterministic order.
Otherwise the ordering of state variables may change between subsequent
model imports, which we'd like to avoid.

Closes AMICI-dev#2241.
  • Loading branch information
dweindl committed Dec 18, 2023
1 parent 458efd9 commit bc254c8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,15 +2776,17 @@ def replace_logx(math_str: Union[str, float, None]) -> Union[str, float, None]:
return re.sub(r"(^|\W)log(\d+)\(", r"\g<1>1/ln(\2)*ln(", math_str)


def _collect_event_assignment_parameter_targets(sbml_model: sbml.Model):
targets = set()
def _collect_event_assignment_parameter_targets(
sbml_model: sbml.Model,
) -> list[sp.Symbol]:
targets = []
sbml_parameters = sbml_model.getListOfParameters()
sbml_parameter_ids = [p.getId() for p in sbml_parameters]
for event in sbml_model.getListOfEvents():
for event_assignment in event.getListOfEventAssignments():
target_id = event_assignment.getVariable()
if target_id in sbml_parameter_ids:
targets.add(
targets.append(
_get_identifier_symbol(
sbml_parameters[sbml_parameter_ids.index(target_id)]
)
Expand Down

0 comments on commit bc254c8

Please sign in to comment.