From edc8c45288b4610fd09ac68a9205dbe42a1a9ba1 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Thu, 17 Oct 2024 13:19:41 +0200 Subject: [PATCH] Fix _collect_heaviside_roots for sympy.Heaviside arguments Previously, if dxdt was a sympy.Heaviside, it wasn't correctly processed, because only its arguments were checked. That means, root-finding would not be enabled for this discontinuity. This would happen if a Rule or KineticLaw is a plain Piecewise function (not embedded inside a more complex expression). Fixes #2545. --- python/sdist/amici/de_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/sdist/amici/de_model.py b/python/sdist/amici/de_model.py index ba11687929..8ad2e7a998 100644 --- a/python/sdist/amici/de_model.py +++ b/python/sdist/amici/de_model.py @@ -2226,7 +2226,7 @@ def _get_unique_root( def _collect_heaviside_roots( self, - args: Sequence[sp.Expr], + args: Sequence[sp.Basic], ) -> list[sp.Expr]: """ Recursively checks an expression for the occurrence of Heaviside @@ -2288,7 +2288,7 @@ def _process_heavisides( # replace them later by the new expressions heavisides = [] # run through the expression tree and get the roots - tmp_roots_old = self._collect_heaviside_roots(dxdt.args) + tmp_roots_old = self._collect_heaviside_roots((dxdt,)) for tmp_old in unique_preserve_order(tmp_roots_old): # we want unique identifiers for the roots tmp_new = self._get_unique_root(tmp_old, roots)