Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed May 7, 2024
1 parent 9313cbc commit f6e60ed
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,10 @@ def get_empty_bolus_value() -> sp.Float:
species_def["compartment"]
].append(species)

# Currently, all event assignment targets must exist in
# self.symbols[SymbolId.SPECIES]
state_vector = list(self.symbols[SymbolId.SPECIES].keys())

for ievent, event in enumerate(events):
# get the event id (which is optional unfortunately)
event_id = event.getId()
Expand All @@ -1637,10 +1641,6 @@ def get_empty_bolus_value() -> sp.Float:
trigger_sym = self._sympy_from_sbml_math(trigger_sbml)
trigger = _parse_event_trigger(trigger_sym)

# Currently, all event assignment targets must exist in
# self.symbols[SymbolId.SPECIES]
state_vector = list(self.symbols[SymbolId.SPECIES].keys())

# parse the boluses / event assignments
bolus = [get_empty_bolus_value() for _ in state_vector]
event_assignments = event.getListOfEventAssignments()
Expand Down Expand Up @@ -1759,6 +1759,8 @@ def get_empty_bolus_value() -> sp.Float:
# 1) there is only a single event
# 2) there are multiple events, but they are guaranteed to not
# trigger at the same time
# 3) event assignments from events triggering at the same time
# are independent
# in these cases, the attribute value doesn't matter, as long
# as we don't support delays
# We can't check this in check_event_support without already processing
Expand All @@ -1782,6 +1784,18 @@ def get_empty_bolus_value() -> sp.Float:
# all trigger times are unique
return

# If all events assign to different species, we are fine. This is the
# case if the list of assigned-to variables across all events contains
# only unique values.
assigned_to_species = [
variable
for event in self.symbols[SymbolId.EVENT].values()
for variable, update in zip(state_vector, event["state_update"])
if not update.is_zero
]
if len(assigned_to_species) == len(set(assigned_to_species)):
return

raise SBMLException(
"Events with `useValuesFromTriggerTime=true` are not "
"supported when there are multiple events.\n"
Expand Down

0 comments on commit f6e60ed

Please sign in to comment.