Skip to content

Commit

Permalink
Fix piecewise/Heavisides handling
Browse files Browse the repository at this point in the history
* Substitute non-time-dependent Heavisides
* Substitute inside the expanded expression, otherwise not all substitution targets are found

Closes #2231
  • Loading branch information
dweindl committed Dec 12, 2023
1 parent 0bc2f2a commit e0fbeec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions python/sdist/amici/de_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,19 +2757,22 @@ def _process_heavisides(
for tmp_old in tmp_roots_old:
# we want unique identifiers for the roots
tmp_new = self._get_unique_root(tmp_old, roots)
heavisides.append((sp.Heaviside(tmp_old), tmp_new))

Check warning on line 2760 in python/sdist/amici/de_export.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/de_export.py#L2760

Added line #L2760 was not covered by tests

# `tmp_new` is None if the root is not time-dependent.
if tmp_new is None:
continue
# For Heavisides, we need to add the negative function as well
self._get_unique_root(sp.sympify(-tmp_old), roots)
heavisides.append((sp.Heaviside(tmp_old), tmp_new))

if heavisides:
# only apply subs if necessary
for heaviside_sympy, heaviside_amici in heavisides:
dxdt = dxdt.subs(heaviside_sympy, heaviside_amici)
dt_expanded = dt_expanded.subs(

Check warning on line 2771 in python/sdist/amici/de_export.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/de_export.py#L2771

Added line #L2771 was not covered by tests
heaviside_sympy, heaviside_amici
)

return dxdt
return dt_expanded


class DEExporter:
Expand Down

0 comments on commit e0fbeec

Please sign in to comment.