Skip to content

Read each vertex's isouter when interpreting an Equality cset causally - #5317

Merged
AayushSabharwal merged 1 commit into
SciML:masterfrom
pankgeorg:equality-cset-outer-vertex
Oct 30, 2026
Merged

AayushSabharwal merged 1 commit into
SciML:masterfrom
pankgeorg:equality-cset-outer-vertex

Conversation

@pankgeorg

@pankgeorg pankgeorg commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5318.

In generate_connection_equations_and_stream_connections, the loop that tries to read an Equality connection set as a causal one checks cvert.isouter for every member. cvert is the set's first vertex (cvert = cset[1] at the top of the outer loop), not the vertex being visited. So the outer/inner test uses the first member's flag for all members, and the root of the set depends on the order of the arguments to connect.

Example: a component with an outer RealOutput named output, an inner source src.output and an inner sink dst.input, connected in each of the six argument orders:

connect(...) argument order equations on master causal?
output, src.output, dst.input output.u ~ dst.input.u, src.output.u ~ dst.input.u no: the root is an input
output, dst.input, src.output output.u ~ dst.input.u, src.output.u ~ dst.input.u no: the root is an input
src.output, output, dst.input output.u ~ src.output.u, dst.input.u ~ src.output.u yes
src.output, dst.input, output dst.input.u ~ src.output.u, output.u ~ src.output.u yes
dst.input, output, src.output dst.input.u ~ output.u, src.output.u ~ output.u no: the root is the outer output
dst.input, src.output, output dst.input.u ~ src.output.u, output.u ~ src.output.u yes

With this change the loop reads cset[i].isouter, and all six orders give ... ~ src.output.u. The equations are equivalent either way; what changes is the orientation that #3898 introduced (input ~ output, with the source on the right).

#5295 re-enabled the causal root selection (before it, the loop's === nothing sentinel comparisons could never succeed, so it always fell back to base ~ v), which exposed the stale first-vertex lookup.

Unblocks: causal Equality connection sets that orient the same way (input ~ output) whatever the order of the arguments to connect.

Tests

A new testset in lib/ModelingToolkitBase/test/components.jl covers the six orders above. I checked it on Julia 1.13.2 by running the file's top-level code, its testsets whose names start with "Causal", and the "Serial inductor" and "BLT ordering" testsets, which sit inside the file's top-level if block:

  • with this change: the new testset passes for all six orders (12/12);
  • on master: it fails for the three orders marked "no" above (9 pass / 3 fail);
  • "Serial inductor" and "BLT ordering" pass in both runs.

On master, the first assertion of the existing "Causal connections generate causal equations" testset still fails in both runs. #5298 fixes that one; this PR leaves it alone.

🤖 Generated with Claude Code

The loop that interprets an `Equality` connection set as a causal one
checked `cvert.isouter`, where `cvert` is the set's first vertex, so
every member was classified with the first member's flag and the root
depended on the order of the arguments to `connect`. Read
`cset[i].isouter` instead, and test all six orders of an outer output
connected to an inner output and an inner input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AayushSabharwal
AayushSabharwal merged commit 550a27c into SciML:master Oct 30, 2026
97 of 111 checks passed
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.

Equality connection sets interpreted causally depend on connect argument order

2 participants