Skip to content

Commit 9028595

Browse files
authored
SBML import: support == operator (#2708)
* SBML import: support `==` operator Adds support the the equality operator in piecewise conditions or event triggers. * Update SBML test suite results This is the combined increase from using sbmlmath, supporting xor, and supporting ==.
1 parent 9a90c24 commit 9028595

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

doc/python_interface.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AMICI can import :term:`SBML` models via the
2626
Status of SBML support in Python-AMICI
2727
++++++++++++++++++++++++++++++++++++++
2828

29-
Python-AMICI currently **passes 1252 out of the 1821 (~68%) test cases** from
29+
Python-AMICI currently **passes 1268 out of the 1821 (~70%) test cases** from
3030
the semantic
3131
`SBML Test Suite <https://github.com/sbmlteam/sbml-test-suite/>`_
3232
(`current status <https://github.com/AMICI-dev/AMICI/actions>`_).

python/sdist/amici/import_utils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ def _parse_heaviside_trigger(trigger: sp.Expr) -> sp.Expr:
533533

534534
# rewrite n-ary XOR to OR to be handled below:
535535
trigger = trigger.replace(sp.Xor, _xor_to_or)
536-
537-
# TODO: x == y
536+
# rewrite equality
537+
trigger = trigger.replace(sp.Eq, _eq_to_and)
538538

539539
# or(x,y) = not(and(not(x),not(y))
540540
if isinstance(trigger, sp.Or):
@@ -573,6 +573,18 @@ def _xor_to_or(*args):
573573
return res.simplify()
574574

575575

576+
def _eq_to_and(*args):
577+
"""
578+
Replace equality expression with numerical arguments by inequalities.
579+
580+
``Eq(x, y) = (x >= y) & (x <= y)``.
581+
582+
to be used in ``trigger = trigger.replace(sp.Eq, _eq_to_and)``.
583+
"""
584+
x, y = args
585+
return (x >= y) & (x <= y)
586+
587+
576588
def grouper(
577589
iterable: Iterable, n: int, fillvalue: Any = None
578590
) -> Iterable[tuple[Any]]:

python/sdist/amici/sbml_import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
generate_flux_symbol,
5454
_parse_piecewise_to_heaviside,
5555
_xor_to_or,
56+
_eq_to_and,
5657
)
5758
from .logging import get_logger, log_execution_time, set_log_level
5859
from .sbml_utils import SBMLException
@@ -3216,6 +3217,8 @@ def _parse_event_trigger(trigger: sp.Expr) -> sp.Expr:
32163217

32173218
# rewrite n-ary XOR to OR to be handled below:
32183219
trigger = trigger.replace(sp.Xor, _xor_to_or)
3220+
# rewrite equality
3221+
trigger = trigger.replace(sp.Eq, _eq_to_and)
32193222

32203223
# or(x,y): any of {x,y} is > 0: sp.Max(x, y)
32213224
if isinstance(trigger, sp.Or):

0 commit comments

Comments
 (0)