Skip to content

Incorrect handling of <= and >= in event triggers #2707

@dweindl

Description

@dweindl

In event triggers, < and > are incorrectly interpreted as <= and >= respectively.

This somewhat similar to #2700, but a different issue. Ideally this could be addressed via #2684 and the fixes implemented in #2701.

Reproducer:

import amici
from amici.antimony_import import antimony2amici

antimony2amici("""
a = 1
pp = 0
at time >= a: pp = 1
at time > 2 *a: pp = 2
""", model_name="bla", output_dir="bla")

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

model = model_module.get_model()

model.setTimepoints([0, 1, 2, 3])

solver = model.getSolver()

rdata = amici.runAmiciSimulation(model, solver)
print(model.getStateIds())
print(rdata.by_id("pp"))
# ->        [0. 1. 2. 2.]
# expected: [0. 1. 1. 2.]

This is not just about numerics. The root functions generated for the two events are the same, despite the different comparison operators:

    root[0] = -a + t;
    root[1] = -2*a + t;

Generated here:

# convert relational expressions into trigger functions
if isinstance(
trigger,
sp.core.relational.LessThan | sp.core.relational.StrictLessThan,
):
# y < x or y <= x
return -root
if isinstance(
trigger,
sp.core.relational.GreaterThan
| sp.core.relational.StrictGreaterThan,
):
# y >= x or y > x
return root

Metadata

Metadata

Assignees

No one assigned

    Labels

    SBMLSBML import relatedbugeventsrelated to handing discrete events

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions