Skip to content

Bug in handling events correctly with model changes #983

@matthiaskoenig

Description

@matthiaskoenig

Hi all,
I just noticed the following bug in roadrunner which results in incorrect model results.
If one has a model with an event trigger and parameters are changed in the trigger before simulation the events do not trigger correctly! I.e. it seems that the event triggers are not correctly evaluated, i.e. not using the actual model values, but the values at model loading.

In the example attached two events are triggered if

IVDOSE_icg > 0 mg

I.e. everytime a simulation starts with IVDOSE_icg > 0 the events should be triggered. I set a value in the SBML model of IVDOSE_icg = 32.5 mg, so the event is triggered if just loading the model.

import roadrunner
import pandas as pd
from matplotlib import pyplot as plt
r: roadrunner.RoadRunner = roadrunner.RoadRunner("icg_body_flat.xml")
r.timeCourseSelections = ["time", "[Cve_icg]", "IVDOSE_total_icg", "IVDOSE_icg"]
s = r.simulate(start=0, end=20, steps=2000)
df = pd.DataFrame(s, columns=s.colnames)
plt.plot(df.time, df["[Cve_icg]"])
plt.show()

And the following curve results.
image

When setting the value to 0 and back to 32.5 before simulation the model shows incorrect zero!.

import roadrunner
import pandas as pd
from matplotlib import pyplot as plt
r: roadrunner.RoadRunner = roadrunner.RoadRunner("icg_body_flat.xml")
r.timeCourseSelections = ["time", "[Cve_icg]", "IVDOSE_total_icg", "IVDOSE_icg"]

# just setting the value and back ????!!!! This should not change anything, but events are not working any more
r.setValue("init(IVDOSE_icg)", 0.0)
r.setValue("init(IVDOSE_icg)", 32.5)

s = r.simulate(start=0, end=20, steps=2000)
df = pd.DataFrame(s, columns=s.colnames)
plt.plot(df.time, df["[Cve_icg]"])
plt.show()

image

I have the feeling the underlying problem is that model changes and init changes via setValue do not update the trigger expressions or not reset the trigger expressions (at time zero). I.e. the triggers must be evaluated with the actual values and if a trigger has initalValue=False this must be reset at the beginning of a simulation.

Also when loading the model with IVDOSE_icg = 0 in the SBML file setting the dose via r.setValue("IVDOSE_icg", 32.5) before the simulation does not work to trigger the event. This is how I discovered this originally.

In addition the above example should also work to trigger the event if one sets values in the model, not just the initial values

r.setValue("init(IVDOSE_icg)", 0.0)
r.setValue("init(IVDOSE_icg)", 32.5)

Hope this information helps. But this seems to be a major bug with events in roadrunner.

icg_body_flat.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions