Skip to content

fix: keep incidence of variables made observed by inline linear SCCs - #199

Draft
cmhyett wants to merge 1 commit into
mainfrom
cmh/inline-scc-observed-incidence
Draft

cmhyett wants to merge 1 commit into
mainfrom
cmh/inline-scc-observed-incidence

Conversation

@cmhyett

@cmhyett cmhyett commented Dec 1, 2026

Copy link
Copy Markdown

When inline_linear_sccs = true, an algebraic variable solved by an inline linear SCC becomes observed. contract_variables recovers the incidence of an eliminated variable from its matched equation, but this variable is solved from the whole block, so equations that used it lost their dependencies. The torn system's jacobian sparsity, which MTK reads off this graph, then dropped nonzero entries, e.g. D(x) ~ xˍt with xˍt a function of x and y.

Make every other equation incident on such a variable also incident on the variables of the block's solution, as is already done for derivative variables.

License: AGPL-3.0-only
Copyright: JuliaHub, Inc.

When `inline_linear_sccs = true`, an algebraic variable solved by an inline
linear SCC becomes observed. `contract_variables` recovers the incidence of an
eliminated variable from its matched equation, but this variable is solved from
the whole block, so equations that used it lost their dependencies. The torn
system's jacobian sparsity, which MTK reads off this graph, then dropped
nonzero entries, e.g. `D(x) ~ xˍt` with `xˍt` a function of `x` and `y`.

Make every other equation incident on such a variable also incident on the
variables of the block's solution, as is already done for derivative variables.

License: AGPL-3.0-only
Copyright: JuliaHub, Inc.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ambujone ambujone left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that the new testset fails without the change (4/4 S .| iszero.(J) cases) and passes with it, and the full MTKTearing suite passes on 1.13. The invariant (the reported sparsity covers every nonzero of the ForwardDiff Jacobian) is the right one to test.

Two small comments:

  1. In the algebraic branch the loop also visits the other equations of the same block (they are neighbours of iv). That only over-approximates the incidence, but it is different from what a reader of the derivative branch above expects. Is that intentional? A short comment would help.
  2. The derivative branch does rem_edge!(graph, e, iv) and this one deliberately does not, because iv stays observed. Please say so in the comment, since the two branches now look almost identical.

Nothing blocking from my side; looks right.

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