Don't analytically integrate variables modified by events#4826
Open
cmhyett wants to merge 1 commit into
Open
Conversation
`mtkcompile`'s zero-variable elimination moves variables with trivial
dynamics (e.g. `D(x) ~ 0`) out of the unknowns, rewriting them as an
observed polynomial in the independent variable with a `missing`-bound
constant-of-integration parameter. This ignored discrete/continuous
events: a variable a callback impulsively modifies is no longer an
unknown, so a functional (`ImperativeAffect`) kick errors at `ODEProblem`
construction ("... refers to missing variable(s) ... reduced away").
Fix it two ways:
- Auto-detect (default): add `variables_modified_by_events(sys)` in
ModelingToolkitBase and extend `__eliminate_zero_variables!` to protect
event-modified variables using the same seam that already retains
`irreducible` variables. Such a variable stays an ordinary numerically
integrated unknown; unrelated trivial dynamics are still integrated.
- Opt-out flag: `mtkcompile(sys; analytic_integration=false)` disables the
transformation wholesale (threaded to `eliminate_mm_zeros`, composed via
AND so the SDE force-off still wins).
Add a regression testset covering equational and imperative kicks, the
flag, selective protection, and the event-free no-regression case.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
Variables modified by standard symbolic events are fine. ImperativeAffect is the issue, since it doesn't run a custom reinitialization after the affect. Analytically integrated variables modified by ImperativeAffect can for now be marked as irreducible to avoid this issue. The flag to disable analytical integration can be useful, but it should specifically disable analytical integration and not the entire |
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.
mtkcompile's zero-variable elimination moves variables with trivial dynamics (e.g.D(x) ~ 0) out of the unknowns, rewriting them as an observed polynomial in the independent variable with amissing-bound constant-of-integration parameter. This ignored discrete/continuous events: a variable a callback impulsively modifies is no longer an unknown, so a functional (ImperativeAffect) kick errors atODEProblemconstruction ("... refers to missing variable(s) ... reduced away").Fix it two ways:
variables_modified_by_events(sys)in ModelingToolkitBase and extend__eliminate_zero_variables!to protect event-modified variables using the same seam that already retainsirreduciblevariables. Such a variable stays an ordinary numerically integrated unknown; unrelated trivial dynamics are still integrated.mtkcompile(sys; analytic_integration=false)disables the transformation wholesale (threaded toeliminate_mm_zeros, composed via AND so the SDE force-off still wins).Add a regression testset covering equational and imperative kicks, the flag, selective protection, and the event-free no-regression case.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Single claude commit, needs deeper review - fix works but may not be most elegant.