Skip to content

fix: backshift additional_observed when generating equations#52

Merged
AayushSabharwal merged 3 commits into
mainfrom
as/backshift-additional-observed
Mar 25, 2026
Merged

fix: backshift additional_observed when generating equations#52
AayushSabharwal merged 3 commits into
mainfrom
as/backshift-additional-observed

Conversation

@AayushSabharwal
Copy link
Copy Markdown
Member

No description provided.

@oscardssmith
Copy link
Copy Markdown
Member

Can this get a comment explaining the purpose (and ideally a test?)

@AayushSabharwal
Copy link
Copy Markdown
Member Author

The additional_observed field of TearingState contains observed equations identified through processes other than tearing. Typically, this was only populated by the trivial_tearing! pass in StateSelection. However, MTK handles discrete systems by shifting them forward by a step (x(k) becomes x(k+1)). It omitted doing so on ::TearingState.original_eqs, which is what trivial_tearing! relies on. As a result, trivial_tearing! never did anything on discrete systems (since the equations didn't match what it expected) and additional_observed was never tested for such systems. SciML/ModelingToolkit.jl#4402 utilizes additional_observed for all systems, which exposed this bug. This PR now appropriately shifts original_eqs, which means trivial_tearing! does its job (also part of the test) and additional_observed is backshifted in reassembly to generate appropriate observed equations.

@AayushSabharwal
Copy link
Copy Markdown
Member Author

Minor bug in the test. I'll let CI run, and if everything else passes push the fix and merge once that one job completes.

@AayushSabharwal AayushSabharwal force-pushed the as/backshift-additional-observed branch from 9def746 to d6e558c Compare March 25, 2026 08:04
@AayushSabharwal AayushSabharwal force-pushed the as/backshift-additional-observed branch from d6e558c to 6474cdd Compare March 25, 2026 08:23
@AayushSabharwal AayushSabharwal merged commit 2a65cd3 into main Mar 25, 2026
11 of 23 checks passed
@AayushSabharwal AayushSabharwal deleted the as/backshift-additional-observed branch March 25, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants