sys-bio / antimony

BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Order of event assignments #98

Closed dweindl closed 5 months ago

dweindl commented 5 months ago

Hi, I noticed that event assignments from an antimony model are written to SBML in reverse order. Is this intended and something to rely on?

Example (antimony==2.14.0):

import libsbml
import antimony as ant

ant_model = """
compartment C = 1
species S in C = 1
at S > 1, fromTrigger=false: C = 2, S = 1
"""
assert ant.loadAntimonyString(ant_model) >= 0
assert (main_module_name := ant.getMainModuleName()) is not None
sbml_str = ant.getSBMLString(main_module_name)
print(sbml_str)

sbml_reader = libsbml.SBMLReader()
sbml_doc = sbml_reader.readSBMLFromString(sbml_str)
sbml_model = sbml_doc.getModel()
event = sbml_model.getEvent(0)
assert event.getNumEventAssignments() == 2

# That's what happens, but not what I expected:
assert event.getEventAssignment(0).getVariable() == "S"
assert event.getEventAssignment(1).getVariable() == "C"

I'm not sure – is the ordering of event assignments in SBML models even meant to be significant? Or would this have to be handled via separate events and priority to be unambiguous?

luciansmith commented 5 months ago

It's not particularly intentional, but it is consistent? It's not supposed to matter either way mathematically. If it makes a difference, I could probably switch it to work the other way.

-Lucian

On Mon, May 6, 2024 at 12:59 PM Daniel Weindl @.***> wrote:

Hi, I noticed that event assignments from an antimony model are written to SBML in reverse order. Is this intended and something to rely on?

Example (antimony==2.14.0):

import libsbmlimport antimony as ant ant_model = """compartment C = 1species S in C = 1at S > 1, fromTrigger=false: C = 2, S = 1"""assert ant.loadAntimonyString(ant_model) >= 0assert (main_module_name := ant.getMainModuleName()) is not Nonesbml_str = ant.getSBMLString(main_module_name)print(sbml_str) sbml_reader = libsbml.SBMLReader()sbml_doc = sbml_reader.readSBMLFromString(sbml_str)sbml_model = sbml_doc.getModel()event = sbml_model.getEvent(0)assert event.getNumEventAssignments() == 2

That's what happens, but not what I expected:assert event.getEventAssignment(0).getVariable() == "S"assert event.getEventAssignment(1).getVariable() == "C"

— Reply to this email directly, view it on GitHub https://github.com/sys-bio/antimony/issues/98, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANH3VXDKC6HTDZSP3XDMATZA7OKZAVCNFSM6AAAAABHJUTIOGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4DCNRVGAZDKMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dweindl commented 5 months ago

It's not particularly intentional, but it is consistent?

Yes, it's consistent.

It's not supposed to matter either way mathematically.

Thanks for the clarification. That wasn't immediately clear to me from the SBML specs. After checking again this makes sense.

• A model variable that is the target of one or more event assignments can change more than once when simultaneous events are processed at some time point t.

Initially, I didn't interpret this as "if and only if".

In other words, a single event cannot have multiple EventAssignment children assigning the same variable. (All of them would be performed at the same time, when that particular Event triggers, resulting in indeterminacy.)

Here it becomes clear.