Replace min/max disguised as piecewise#3053
Merged
dweindl merged 1 commit intoAMICI-dev:mainfrom Nov 18, 2025
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3053 +/- ##
==========================================
- Coverage 78.14% 77.47% -0.68%
==========================================
Files 311 311
Lines 20593 20602 +9
Branches 1499 1499
==========================================
- Hits 16092 15961 -131
- Misses 4491 4631 +140
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
FFroehlich
reviewed
Nov 18, 2025
| # piecewise to heavisides | ||
| if piecewise_to_heaviside: | ||
| try: | ||
| expr = expr.replace(sp.Piecewise, _piecewise_to_minmax) |
Member
There was a problem hiding this comment.
also add small test with actual model to make sure that we are not reverting this substitution someplace else?
FFroehlich
approved these changes
Nov 18, 2025
During model import, simplify piecewise functions that can be expressed as min()/max(). So far, all piecewise constructs are treated as discontinuous (see also AMICI-dev#2049). For min/max, only the derivative is discontinuous, which currently does not receive any special treatment in amici (see also https://amici.readthedocs.io/en/latest/implementation_discontinuities.html). So this change prevents root tracking for some unnecessary piecewises. Addresses some aspects of AMICI-dev#2049.
315b6f0 to
2f96fa0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During model import, simplify piecewise functions that can be expressed as min()/max().
So far, all piecewise constructs are treated as discontinuous (see also #2049). For min/max, only the derivative is discontinuous, which currently does not receive any special treatment in amici (see also https://amici.readthedocs.io/en/latest/implementation_discontinuities.html).
So this change prevents root tracking for some unnecessary piecewises. Addresses some aspects of #2049.