Repository navigation
Add opt-in preferred_states_threshold for priority-driven state selection - #191
Draft
asinghvi17 wants to merge 2 commits into
Draft
asinghvi17 wants to merge 2 commits into
asinghvi17 wants to merge 2 commits into
Conversation
With `preferred_states_threshold = k`, every variable whose state priority is at least `k` and that never appears differentiated is given a derivative before Pantelides (`pantelides!` gains a `present_vars` keyword so these count as present). Dummy derivatives are then chosen by priority over whole blocks of differentiated equations that share highest derivatives, descending levels as in Mattsson & Söderlind, with deterministic tie-breaks, instead of one strongly connected component at a time. This lets models where a preferred coordinate is only an algebraic image of another state (e.g. multibody models where a joint's relative coordinates should be states) pick the preferred variables. Without the keyword the behaviour is unchanged. License: AGPL-3.0-only Copyright: JuliaHub, Inc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`priority_dummy_derivatives!` called the dense `jac(eqs, vars)` on whole priority blocks at every level, which dominates compile time on large nonlinear blocks where `jac` gives up anyway. Build the Jacobian one equation at a time, only over the candidates incident on it in `graph`, and stop at the first row `jac` rejects. Also note in the docstring that any `preferred_states_threshold` enables block-level selection. License: AGPL-3.0-only Copyright: JuliaHub, Inc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
🤖 Automated comment from an AI agent running as @asinghvi17 — not written or reviewed by Anshul.
Adds an opt-in
preferred_states_threshold = k(forwarded bymtkcompile) so variables withstate_priority >= kactually win state selection, e.g. a joint's relative coordinates in a multibody model instead of the body's coordinates.Two things stopped that before. A preferred variable that never appears under
D(saysB ~ s - c) got no derivative from Pantelides, so it was never a candidate; it now gets one up front (pantelides!takespresent_vars). And dummy derivatives were picked one SCC at a time, so in triangular systems the first equation decided alone; with the keyword they are picked by priority over blocks of differentiated equations that share highest derivatives (Mattsson & Söderlind). Without the keyword nothing changes.Open questions: a numeric threshold or a prefer/always attribute (libraries already use small priorities as tie-breakers)? Should block selection ever be the default? The choice is structural, so a preferred variable that is a non-invertible function of the states can become a poor state, and one tied to an input needs
D(u).Performance (62 systems: MTK and Multibody examples, synthetic chains, a few large multibody models; one pinned core, warm median):
mtkcompile: +1–5% on most models (e.g. 60-link planar chain 561 → 591 ms, RC ladder 1000 unchanged); small models are a few ms slower. Block selection first built a dense Jacobian over whole blocks, which made large nonlinear multibody models up to 4.3× slower; it is now built row by row over incident candidates and stops at the first nonlinear row, which brings those back to baseline (0.95–1.00×) with identical states. The first call in a session costs ~2 s more, since the keyword path isn't in MTK's precompile workload.funchanged, Jacobians equal or faster (−30% on one model, 49 → 40 unknowns), 20/60-link planar chains solve 1.5–1.8× faster, two small repros 1.3× slower; results agree to ≤ 1.6e-6.🤖 Posted by an AI agent — harness: Claude 2.1.316 · model: claude-opus-5-5
Conversation: factory head hd_c55d7e33 on m_4242afb3ce622d22c2c40d9e9baf1f9a (no session URL)