Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events with trigger that has an initial value of False are not supported #1760

Closed
matthiaskoenig opened this issue Apr 4, 2022 · 9 comments
Labels
enhancement SBML SBML import related

Comments

@matthiaskoenig
Copy link

What did you expect to happen?
AMICI should support events which trigger at time 0. Often one wants to change values at time zero via events, for instance to set dosing protocols.

To Reproduce
Example attached.
icg_body_flat_v2.zip

yaml_file: Path = "icg.yaml"
petab_problem = petab.Problem.from_yaml(yaml_file)
amici_model = amici.petab_import.import_petab_problem(petab_problem)

results in

Traceback (most recent call last):
  File "/home/mkoenig/git/pkdb_models/pkdb_models/models/icg/fit_petab/icg_amici.py", line 28, in <module>
    amici_model = amici.petab_import.import_petab_problem(petab_problem)
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/petab_import.py", line 305, in import_petab_problem
    import_model_sbml(
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/logging.py", line 194, in wrapper_timer
    rval = func(*args, **kwargs)
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/petab_import.py", line 579, in import_model_sbml
    sbml_importer.sbml2amici(
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/sbml_import.py", line 358, in sbml2amici
    self._process_sbml(constant_parameters)
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/logging.py", line 194, in wrapper_timer
    rval = func(*args, **kwargs)
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/sbml_import.py", line 406, in _process_sbml
    self.check_support()
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/sbml_import.py", line 469, in check_support
    self.check_event_support()
  File "/home/mkoenig/envs/pkdb_models/lib/python3.8/site-packages/amici/sbml_import.py", line 515, in check_event_support
    raise SBMLException(
amici.sbml_import.SBMLException: Event event_IVDOSE_icg_0 has a trigger that has an initial value of False. This is currently not supported in AMICI.

How to fix
Read out the initialValue flag of the event which sets the initialValue to either false or true. Evaluate the event trigger at time zero and if it is true fire the event. This is just an event at time 0 which used the initialValue to decide about the transition. AMICI already supports events, this is just the special case of events at time 0 (which is a very typical scenario).

Best Matthias

@matthiaskoenig matthiaskoenig added the new Newly created label Apr 4, 2022
@matthiaskoenig
Copy link
Author

Here some context form the SBML specification. As mentioned above the initalValue flag just allows to handle events at t=0.

An event triggers when the mathematical expression in its Trigger object transitions in value from false to true. An unanswered question concerns what happens at the start of a simulation: can event triggers make this transition at t = 0, where t stands for time? In order to determine whether an event may trigger at t = 0, it is necessary to know what value the Trigger object’s math expression had immediately prior to t = 0. This starting value of the trigger expression is determined by the value of the boolean attribute initialValue. A value of true means the trigger expression is taken to have the value true immediately prior to t = 0. In that case, the trigger cannot transition in value from false to true at the moment simulation begins (because it has the value true both before and after t = 0), and can only make the transition from “false” to “true” sometime after t = 0. Conversely, if initialValue=false, then the trigger expression is assumed to start with
the value false, and therefore may trigger at t = 0 if the expression evaluates to true at that moment.

@FFroehlich
Copy link
Member

Was not implemented primarily because nobody wanted to use it so far. I can definitely see the utility.

I wasn't aware of the initial value field, but it sounds like it shouldn't be too difficult to implement support (but we generally allow t0≠0 in amici, but that hopefully doesn't matter).

@matthiaskoenig
Copy link
Author

Yes, the t0≠0 should not matter. You already have support for events, so this is just a corner case to handle which I would need for most of my applications.
As far as I understand the status of PETab and AMICI multiple changes at different times are not supported at the moment (see PEtab-dev/PEtab#540). I cannot change parameters/initial conditions at t=0, t=t1, t=t2, .... So the solution is to encode the time dependent condition changes as events. This is what I am currently working on.

In this context the support for the t=0 events with the initialValue field would be important. E.g. to set in multiple dosing experiments the t=0 dose correctly.

@dweindl dweindl added enhancement SBML SBML import related and removed new Newly created labels Apr 7, 2022
@FFroehlich
Copy link
Member

The quick workaround would be to directly encode events at t==t0 in the condition table.

I looked at the code and I should be doable to also implement native support. Looks like the sbml testsuite also has a couple of testcases that cover initial assignments for events. Will try to get this in over the weekend.

@matthiaskoenig
Copy link
Author

@FFroehlich Thanks.

@matthiaskoenig
Copy link
Author

Hi all, any update on this issue?
Unfortunately most of my models require events which trigger at t=0, e.g., to switch between different model versions or to encode dosing protocols. Supporting initial events would be great.

FFroehlich added a commit that referenced this issue May 2, 2022
@FFroehlich
Copy link
Member

sorry, this fell off my radar. should hopefully be able to fix this on develop this week.

@FFroehlich
Copy link
Member

Events with initialValues are now supported on the develop branch.

@dweindl dweindl closed this as completed in 82d0b5f May 6, 2022
@matthiaskoenig
Copy link
Author

Thanks so much. This is helping me a lot.

Sorry for the slow response. I am in the process of evaluating simulation results between roadrunner/COPASI/AMICI for the events models and have to check identity of results. Models are now loading and can be simulated in AMICI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement SBML SBML import related
Projects
None yet
Development

No branches or pull requests

3 participants