Repository navigation
Conversation
`get_linear_scc_linsol` checks each residual for linearity in one unknown of the linear system at a time. A product of two of them, such as `z * y`, is linear in each separately, so both checks pass and the coefficient of one in `A` contains the other. After `__reduce_linear_system!` eliminates the matched unknowns, the solution for an unknown depends on itself, and `mtkcompile` fails with "The equations have at least one cycle." Treat the SCC as nonlinear when a coefficient contains an unknown of the linear system, as `calculate_A_b` in ModelingToolkitBase does, so it is torn and solved as it is without `inline_linear_sccs`. Coefficients may still contain unknowns outside the linear system. License: Apache-2.0 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.
Fixes #165
get_linear_scc_linsolchecks linearity one unknown at a time, so a product of two SCC unknowns such asz * ypasses, and one unknown ends up in the other's coefficient. In the issue's model that leavesTwinsideAwhen solving forTw, andtopsort_equationsreports a cycle.This treats the SCC as nonlinear when a coefficient contains an unknown of the linear system, so it is torn as it is without
inline_linear_sccs. ModelingToolkitBase'scalculate_A_buses the same check. Coefficients that depend on states or earlier SCCs are still inlined. The affected systems never compiled before, so output for systems that did compile is unchanged.Test:
D(x) ~ y - x, z ~ 2 - y, 0 ~ z * y + y - xwithinline_linear_sccs = truenow compiles to the same equations as the defaultmtkcompile; before, it errored with "The equations have at least one cycle". The issue's model also compiles, andT(20)matches the default atalpha = 0, 0.01, 0.05. The ModelingToolkitTearing tests and ModelingToolkit v11.47.0test/structural_transformationpass locally on Julia 1.13.4.Prepared with Claude Code.