Skip to content

Preserve array flow balances when expanding connections - #5239

Draft
ChrisRackauckas-Claude wants to merge 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/5119-adopt-5135
Draft

ChrisRackauckas-Claude wants to merge 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/5119-adopt-5135

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Adopts stalled #5135 onto current master: expand_connections was expanding identical-shape array flow balances into one scalar equation per element (4→103 blocks for 1→100 rows). When every flow variable in a connection set shares the same axes, emit one broadcast conservation equation instead; mixed layouts keep the elementwise fallback. Cherry-picked f393dd60 with original authorship; no further code changes.

Review comments on #5135

Only bot benchmark comments (Julia v1 / vlts); no human review comments. Benchmarks were roughly neutral vs master at the time.

Fail-before / pass-after

Issue reproducer (Julia 1.12.7, scratch env with this checkout's ModelingToolkitBase):

# WITHOUT fix (connectors.jl from origin/master):
(rows = 1, equation_blocks = 4)
(rows = 3, equation_blocks = 6)
(rows = 100, equation_blocks = 103)

# WITH fix:
(rows = 1, equation_blocks = 4)
(rows = 3, equation_blocks = 4)
(rows = 100, equation_blocks = 4)

Regression lib/ModelingToolkitBase/test/array_flow_connections.jl:

# WITHOUT fix:
Array flow connections retain equation blocks | 1248 passed / 2 failed / 1250 total
ERROR: Some tests did not pass: 1248 passed, 2 failed, 0 errored, 0 broken.

# WITH fix:
Array flow connections retain equation blocks | 1250 passed / 1250 total

Verification commands

# Negative control: master connectors.jl + new test
git checkout origin/master -- lib/ModelingToolkitBase/src/systems/connectors.jl
julia +1.12 --project=scratch/env scratch/repro.jl
julia +1.12 --project=scratch/env -e 'include("lib/ModelingToolkitBase/test/array_flow_connections.jl")'
git checkout HEAD -- lib/ModelingToolkitBase/src/systems/connectors.jl
# then reverse of the above

# Owning group
cd lib/ModelingToolkitBase && GROUP=InterfaceI julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
# Runic + typos on touched files (both clean)

InterfaceI tail:

Stream Connect Test         |   20                 20      26.6s
Array Flow Connections      | 1250               1250      11.3s
...
InterfaceI                  | 3018     1       5   3024  119m19.6s

The single InterfaceI failure is unrelated: `full_equations` doesn't recurse infinitely in odesystem.jl:1681 (!(process_running(proc)) after ~3 min under heavy machine load). Stream Connect and Array Flow Connections both passed fully.

Not verified

  • Full GROUP=All / QA / other Interface groups
  • Whether the odesystem.jl recursion-guard flake reproduces on clean master (strongly suspected load flake; not touched by this PR)
  • Downstream ModelingToolkit top-level package tests
  • Performance impact beyond Preserve array flow balances when expanding connections #5135's bot benchmarks

Reviewer pushback

Fixes #5119

Please ignore this draft until reviewed by @ChrisRackauckas.

Risk assessment

  • Risk: low–medium (changes flow-equation emission for array connectors; scalar/mixed paths unchanged)
  • Blast radius: expand_connections Flow branch / _flow_equations_from_idxs! only
  • Evidence: issue reproducer + 1250/1250 regression; InterfaceI Array Flow + Stream Connect green
  • Independent review: pending
  • Merge: needs review

Harness: Cursor Agent CLI 2026.09.28-64d2043 · Model: auto · Transcript: /log.txt

Risk assessment (orchestrator)

  • Independent review: Claude Code + Opus 5.5 (claude-opus-5-5; a different harness from the Cursor author) gave verdict MERGE at medium risk. The code is correct in every case run (inner and outer connectors, mtkcompile results unchanged), the negative control reproduces, and all failing CI checks also fail on master. Risk is medium because every array flow balance from expand_connections changes its pre-compile form (e.g. broadcast(*, 0, Q) ~ broadcast(+, Q, Q')), which reverses the earlier deliberate choice of scalar equations.
  • Merge: needs human review: design decision for Chris (array broadcast flow balances vs scalar equations; see Compile and generate code for whole-array equation models without scalarizing per element (tracking) #5139). Non-blocking follow-ups: test an outer connector and a 3+ member set; the mismatched-axes fallback is unreachable for array connectors.

Head orchestration and review routing: Claude Code (model: claude-opus-5-5[1m]), https://claude.ai/code/session_01H4fXBChQshAwfpLMCpEvAX

Risk assessment (independent review, codex-cli gpt-6.1-sol, reviewed head d24d090)

  • Risk: medium
  • Blast radius: Ordinary array-valued Flow connectors in expand_connections. Equation blocks change from scalar balances to a broadcast balance for matching shapes. Scalar flows and the mixed-shape fallback retain their construction. Numerical conservation is preserved; consumers inspecting unscalarized equations see the intended representation change.
  • Evidence: On Julia 1.13.0 with JULIA_NUM_THREADS=4, the committed array-flow regression passed 1250/1250, and the extracted VecPin assertion from stream_connectors.jl passed (process exit 0). Loading the exact base _flow_equations_from_idxs! implementation into the same package and running the unchanged regression produced 1248 passes, 2 failures, at allequal(counts) and allequal(sizes) (exit 1). Additional local probes passed 10/10 for a three-component connection and 4/4 for mixed inner/outer signs. CI: 42 pass, 3 fail, 63 pending, 1 skipped; the failed jobs match master as detailed below.
  • Independent review: codex-cli 0.163.0 gpt-6.1-sol rated it medium, high confidence: direct negative/positive controls and additional sign checks support the array representation change without lost conservation coverage.
  • Merge: needs human review — the change deliberately affects the public pre-tearing equation representation; approve that design choice before merging. No blocking implementation finding.

🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6.1-sol (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq

`expand_connections` expanded an array flow balance into one scalar
equation per element, so a network with array-valued flow connectors
grew its symbolic equation count with the array size (4 -> 103 equation
blocks from 1 to 100 rows in the reproducer of SciML#5119). When every flow
variable in a connection set has the same shape, emit a single broadcast
conservation equation instead. Connection sets with mixed axes keep the
existing element-wise construction.

The existing stream-connector assertion compared against scalarized
equations, so it now scalarizes the array flow equation before comparing.
Adds `test/array_flow_connections.jl`, which checks that the connection
equation count and symbolic size are independent of the array shape and
that the generated equations still express flow conservation.

Fixes SciML#5119.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.270
Agent-Model: claude-fable-5-1
Agent-Session: local Claude Code session 9b5c3ae5-6a0f-41b8-bd69-03bf3b5e7083

@AayushSabharwal AayushSabharwal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the point? TearingState will immediately scalarize anyway?

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <noreply@cognition.ai>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_ModelingToolkit.jl-5239/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Merged the default branch into this PR (clean merge, no conflicts; head 6a42339) so CI runs on current master.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

This branch has not been deployed

No deployments
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.

Preserve array flow balances when expanding ordinary connector connections

3 participants