Skip to content

Incorrect initial root function values for piecewise-derived events #2724

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

Open
dweindl opened this issue May 14, 2025 · 3 comments
Open

Incorrect initial root function values for piecewise-derived events #2724

dweindl opened this issue May 14, 2025 · 3 comments
Assignees
Labels
bug SBML SBML import related

Comments

@dweindl
Copy link
Member

dweindl commented May 14, 2025

For all Piecewise or Boolean expressions we create root functions to stop at the discontinuities.
Currently, their initial value is incorrectly set to true, leading to incorrect simulation results if a piecewise condition is already true at $t_0$.

@dweindl dweindl self-assigned this May 14, 2025
@dweindl dweindl added bug SBML SBML import related labels May 14, 2025
@dweindl
Copy link
Member Author

dweindl commented May 14, 2025

The issue might be more nuanced than that.

Here a reproducer:

import amici
from amici.antimony_import import antimony2amici

antimony2amici("""
a = 0
b = 1
a' = 0
ge0 := time >= a
ge1 := time >= b
gt0 := time > a
gt1 := time > b
""", model_name="bla", output_dir="bla")

model_module = amici.import_model_module("bla", "bla")

model = model_module.get_model()
model.setTimepoints([0, 1, 2])

solver = model.getSolver()
rdata = amici.runAmiciSimulation(model, solver)

print(rdata)
print("ts", rdata.ts)
print("ge0", rdata.by_id("ge0"))
print("ge1", rdata.by_id("ge1"))
print("gt0", rdata.by_id("gt0"))
print("gt1", rdata.by_id("gt1"))
ts [0. 1. 2.]
ge0 [1. 1. 1.] # ok
ge1 [0. 1. 1.] # ok
gt0 [0. 0. 0.] # INCORRECT! should be [0. 1. 1.] or at least [1. 1. 1.] until there is a solution to https://github.com/AMICI-dev/AMICI/issues/2707
gt1 [0. 1. 1.] # should be [0. 0. 1.] -> https://github.com/AMICI-dev/AMICI/issues/2707

(The test case added in #2725 can also easily be updated to trigger this issue.)

@FFroehlich
Copy link
Member

I thought starting in a root would throw an error. Probably the best way to handle this is start the simulation at 0+eps, but that will make it difficult to make ge0 work at the same time.

In all honesty, I don’t think there is a good way of making this stuff work in general. It might be the better approach to throw informative errors/warnings.

@dweindl
Copy link
Member Author

dweindl commented May 15, 2025

Thanks. I didn't encounter any error/warning there. I will see if I can find where that might have been supposed to happen.

dweindl added a commit that referenced this issue May 18, 2025
Make users aware of some known potential issues (e.g., #18, #2707, #2724, #2673).

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

No branches or pull requests

2 participants