Skip to content

Preserve array flow balances when expanding connections - #5239

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

ChrisRackauckas-Claude wants to merge 7 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

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head 1d1ffcd)

Merged current upstream/master into the feature branch. It contains the Symbolics compatibility fixes for Parsing and Latexify and the OpenModelica link fix. The two downstream BoundsErrors also occurred on the historical default-branch run. The latest matching default-branch jobs passed all seven checks that were red on the old PR head. Compatibility fixes · OpenModelica link fix · Historical downstream run

Added symbolic conservation assertions for three inner ports and for two inner ports connected to an outer port. Keeping the equation block bounded serves callers that use expanded equations before tearing, including array DAE assembly.

Validation

Commands used with JULIA_NUM_THREADS=4 and OPENBLAS_NUM_THREADS=1:

julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/connectors.jl lib/ModelingToolkitBase/test/{array_flow_connections,runtests,stream_connectors}.jl
git diff upstream/master --unified=0 -- lib/ModelingToolkitBase | typos -
GROUP=InterfaceI julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=RegressionI julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA julia +1.13.3 --startup-file=no --compiled-modules=no --project -e 'using Pkg; Pkg.test()'
xvfb-run -a julia +1.10.12 --startup-file=no --compiled-modules=no --project=docs docs/make.jl
Runic exit 0
Spelling and whitespace checks passed
InterfaceI    | 3465       5   3470  23m39.9s
Testing ModelingToolkitBase tests passed
Latexify recipes Test |    1      1  1m18.2s
Testing ModelingToolkitBase tests passed
Array flow connections retain equation blocks | 1250   1250  43.3s
Signed array flow conservation                |    8      8   2.3s
  • Isolated negative controls on the new assertions gave four failures for an unsigned outer term and eight for an omitted third term. The production implementation passed all eight. On clean historical master with CI's pinned dependencies, variable parsing errored and 50.tex mismatched. At the upstream compatibility commit, variable parsing passed 48/48 and 50.tex passed. The official RegressionI run compared the tracked 50.tex and generated four references absent from the default branch.
  • ModelingToolkitBase QA exited 1. JET passed 54/54 and Aqua's reexport check failed for the same five Symbolics 7.49 names seen on master. Root QA exited 1 with UndefVarError: Reexport not defined in FMIBase on both the merged tree and a clean current master checkout. The latest root master CI reached its reexport check and failed it. Master sublibrary QA · Master root QA
  • The docs build completed doctests and examples, then exited 1 with [:linkcheck] after GitHub returned HTTP 429 for the PDEBase interface and ColPrac links. Direct retries reproduced the 429s. Both links returned HTTP 200 in the latest master docs job. Downstream verification here used CI logs. Master docs job

Next counted review must come from a smart model in a fresh session, not this fix session.


🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a20010-0843-7be1-b0c6-185a0b47b772 (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head 04f9cb8)

Array flow balances use a lazy, axis-preserving constant zero. Direct mass-matrix ODE construction recognizes it as the algebraic left-hand side. Empty flow sets emit zero equations. The regression tests check the rank-six mass matrix and RHS of an open 2×3 port and the compiled RHS of a model that contains a zero-width port. Compact block size and signed conservation checks also passed.

Validation

The standalone runs used Julia 1.12.4 and identical resolved dependencies. The environment pointed at the reviewed head, clean master, or the fixed tree. The driver displayed concise exceptions and ran the same two regression testsets.

julia --startup-file=no --compiled-modules=existing --project="$flow_env" "$regression_driver"
julia --startup-file=no --compiled-modules=existing --project="$flow_env" -e 'using ModelingToolkitBase; @show pathof(ModelingToolkitBase); include("lib/ModelingToolkitBase/test/array_flow_connections.jl")'
GROUP=InterfaceI julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA julia +1.13.3 --startup-file=no --compiled-modules=existing --project -e 'using Pkg; Pkg.test()'
julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/{systems/codegen.jl,systems/connectors.jl,utils.jl} lib/ModelingToolkitBase/test/array_flow_connections.jl
git diff --no-ext-diff --no-color --unified=0 upstream/master...HEAD | awk '/^\+[^+]/ { print substr($0,2) }' | typos -
git diff --check upstream/master...HEAD
Reviewed head, exit 1
  The LHS cannot contain nondifferentiated variables.
  TypeError: in typeassert ... got a value of type Matrix{Any}
  Array flow port edge cases | 2 errors / 2 total

Clean master and fixed head, exit 0
  Array flow port edge cases | 3 passed / 3 total

Fixed head connector tests, exit 0
  Array flow connections retain equation blocks | 1250 passed / 1250 total
  Signed array flow conservation               |    8 passed /    8 total

Full InterfaceI, exit 0
  InterfaceI | 3468 passed, 5 existing broken, 3473 total | 24m53.9s
  Testing ModelingToolkitBase tests passed

Runic, typos, and Git whitespace checks exited 0. An offset-axis probe passed 9/9. ModelingToolkitBase QA exited 1 with JET 54/54 and Aqua 20 passed, one failed. Aqua reported the same five Symbolics reexports as master. Root QA exited 1 during fixture loading with UndefVarError: Reexport not defined in FMIBase, also observed in the earlier fix run on clean master. Both red InterfaceII jobs matched the JumpProcesses deprecation failure on master CI. The other red jobs matched the root and downgrade QA reexport failures. Master sublibrary CI · Master root QA · Master downgrade QA

Next counted review must come from a smart model in a fresh session, not this fix session.


🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a2018d-daf0-7cf1-9098-bbf108f2988a (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.170.0 gpt-6.2-sol (head 9cedabc)

Array-flow balances use an axis-preserving constant fill that scalarizes on Julia LTS. The open-port mass matrix and zero-width structural-compilation regressions pass, along with a new offset-port test that checks the expanded axes and every scalar balance. The preceding head's LTS CI failed inside FillArrays' unary broadcast while checking for a symbolic zero. Failing PR job · Passing master job

Local validation

Commands used Juliaup for version selection and set JULIA_NUM_THREADS=4, OPENBLAS_NUM_THREADS=1, and JULIA_NUM_PRECOMPILE_TASKS=1. The connector replay verified the package source and used the same tests and dependencies on both revisions (FillArrays 1.19.0, SymbolicUtils 4.56.2, Symbolics 7.49.0).

timeout 3600 julia +1.10.12 --startup-file=no --compiled-modules=no --project="$flow_env" "$driver" "$package" lib/ModelingToolkitBase/test/array_flow_connections.jl
GROUP=InterfaceI JULIA_PKG_PRECOMPILE_AUTO=1 timeout 7200 julia +1.10.12 --startup-file=no --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA timeout 3600 julia +1.13.3 --startup-file=no --compiled-modules=existing --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA timeout 3600 julia +1.13.3 --startup-file=no --compiled-modules=existing --project=. -e 'using Pkg; Pkg.test()'
mapfile -t files < <(git diff --name-only upstream/master -- '*.jl')
timeout 3600 julia --project=@runic -m Runic --inplace "${files[@]}"
git diff --no-ext-diff --no-color --unified=0 upstream/master...HEAD | awk '/^\+[^+]/ { print substr($0,2) }' | typos -
git diff --check upstream/master...HEAD
LTS connector replay, 04f9cb8384, exit 1
  TypeError: non-boolean (SymbolicUtils.BasicSymbolicImpl...) used in boolean context
  Array flow connections on Julia LTS | 7 passed, 3 errored
  Offset flow axes survive scalarization | 1 passed, 1 errored

LTS connector replay, fixed tree, exit 0
  Array flow connections on Julia LTS | 1263   1263   1m18.8s

Full LTS InterfaceI, exit 0
  InterfaceI | 3470 passed, 5 existing broken, 3475 total | 23m17.0s
  Testing ModelingToolkitBase tests passed

ModelingToolkitBase QA, exit 1
  JET Tests  | 54 passed / 54 total
  Aqua Tests | 20 passed, 1 failed

Root QA, exit 1
  QA | 39 passed, 1 failed

Runic, typos, and Git whitespace checks exited 0.

The separate port replay on reviewed head 1d1ffcda8c reproduced the nondifferentiated-LHS and empty-array errors. The three assertions passed on clean master and 04f9cb8384, and are part of the 1,263 passing assertions above. The first full LTS run with compiled modules disabled passed all 1,263 connector assertions and failed the existing full_equations 180-second subprocess check. That check also failed on clean master with compiled modules disabled. The final LTS run used compiled modules and passed.

Both QA failures match the default branch's reexport failures. The two red InterfaceII jobs match the default branch's JumpProcesses deprecation failure. Prerelease, GPU, and downstream suites were outside local validation. Master sublibrary CI · Master root QA · Master downgrade QA

Next counted review must come from a smart model in a fresh session, not this fix session.


🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a201c8-ce54-7fe3-90f0-72bb87e058c7 (no session URL)

`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)

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

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

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19817-b88b-78b1-ac2c-f136093d7867, reviewed head d24d090

  • Verdict: MERGE-WITH-ISSUES
  • Risk: medium-high (MH1: array flow balances change from scalar equations to broadcast array equations used by system compilation and consumers of expanded systems).
  • Round / slot: 1 / 1
  • Blocking priorities: none

Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Preserves matching-shape array flow balances as bounded equation blocks while retaining scalar construction for other shapes. The committed regression fails on the base and passes on the reviewed head; no blocking defect was found, with a non-blocking suggestion to retain broader conservation coverage.

Blast radius: Matching-shape array-valued Flow connection sets in expand_connections and subsequent mtkcompile; scalar flows retain their original construction. No new public names, dependencies, numerical defaults, caches, or AD rules.

Evidence: Independently ran the committed test on Julia 1.13.2: head 1250/1250 passes, exit 0; merge-base 1248 passes and two structural failures, exit 1. CI reports 101 successes, seven failures, and three skipped checks; its Array Flow Connections and Stream Connect tests passed. Additional probe results and CI attribution appear below.

Blocking findings

None.

Non-blocking findings

  1. non-blocking [P3] lib/ModelingToolkitBase/test/array_flow_connections.jl:23: Retain a mixed inner/outer connection and a three-member connection in the committed regression. The new numerical assertions cover a two-member inner connection at a uniform equilibrium, so they do not directly protect the outer negation or the full multi-member reduction at lib/ModelingToolkitBase/src/systems/connectors.jl:847. Add symbolic checks against the independently specified signed sums, ideally with nonuniform component values.

What I ran

The blind diff assessment was written and hashed before reading author context. The PR body subsequently exposed embedded earlier-review summaries; the separate prior-review file remained unread until this review was finished and frozen.

Git inspection, exit 0: git fetch origin '+refs/pull/5239/head:refs/remotes/pr/5239' master; git checkout --detach pr/5239; git rev-parse HEAD origin/master; git merge-base origin/master HEAD; git diff origin/master...HEAD; git diff bf209c9c2b761da61774a46c421ef179d99cfd2e...HEAD --stat. The merge-base is the Base above; the fetched master tip is 661303665a43b215c059a7eacbc753a169106056.

All Julia commands used JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600, where REVIEW_DEPOT denotes the shared depot specified in TARGET.md. Environments and scripts were outside the source checkout; no package suite or Pkg.test() was run.

  • Head, exit 0: julia +1.13.2 --startup-file=no --compiled-modules=existing run-head.jl. The script activates a temporary environment, develops the exact head's ModelingToolkitBase, adds Symbolics, and includes lib/ModelingToolkitBase/test/array_flow_connections.jl unchanged. Output: Array flow connections retain equation blocks | 1250 1250 36.6s. Resolved Symbolics version: 7.48.0.

  • Base, exit 1: julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env run-base.jl. The script develops a full git archive bf209c9c2b761da61774a46c421ef179d99cfd2e snapshot in the same environment and includes the unchanged added test. Output: 1248 passed, 2 failed, 0 errored, 0 broken; only allequal(counts) and allequal(sizes) fail at lib/ModelingToolkitBase/test/array_flow_connections.jl:58 and lib/ModelingToolkitBase/test/array_flow_connections.jl:59. Counts: [2, 3, 4, 7, 101, 201]; expression sizes: [16, 28, 40, 76, 1204, 2404].

  • Final probe, exit 1: julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env run-probe.jl. The extracted, unchanged VecPin assertion from lib/ModelingToolkitBase/test/stream_connectors.jl:309 completed before the next testset failed. The independent signed-conservation testset reported 0 passed, 9 failed, 0 errored: its helper incorrectly compares a symbolic constant with integer 0 using isequal. Dependency source inspection shows that BasicSymbolic-versus-Number structural equality returns false. Printed actual equations contain the expected 0 ~ A.q[i] + B.q[i] + C.q[i], 0 ~ B.q[i] + C.q[i] - outer.q[i], and 0 ~ lone.q[i] for all three elements. These are observed equations, not passing assertions; the probe's later compiled heat-balance test was never reached. No fourth Julia invocation or rerun was made.

CI inspection: gh pr checks 5239 --repo SciML/ModelingToolkit.jl exits 1 for seven failed jobs. Read failed logs with gh run view RUN --repo SciML/ModelingToolkit.jl --log-failed, using a writable cache after the default cache was sandbox-blocked. The sublibrary run records Array Flow Connections 1250/1250 and Stream Connect 20/20 passing; failures are Parsing Test's Variable x must have default of matching size and Latexify recipes' reference mismatch at lib/ModelingToolkitBase/test/latexify.jl:68. Those sites do not exercise the changed flow-emission branch. I did not establish matching master failures for these four jobs.

The PR integration failures match both base integration logs and latest master integration logs: SciMLBase State indexing/Observed accesses a one-element vector at indices [1, 2]; SciMLSensitivity MTK Forward Mode accesses element 3601 of a 3600-element vector. PR documentation and base documentation both terminate for [:linkcheck]; identical individual broken links were not established. The five most recent push runs on master were inspected; latest Sublibrary CI and Tests succeeded. Both benchmark jobs succeeded, but I did not establish a measured speedup or absence of performance regressions from their logs.

Author trailers were read from commit 597949980c6f3d4ee134648479f8fa1e6b8632b3, the last non-merge entry returned by gh api --paginate repos/SciML/ModelingToolkit.jl/pulls/5239/commits, rather than from merged base history.

What I did not verify

No full package, downstream, GPU, MPI, Reactant, or AD suites were run locally; this diff adds no specialized GPU/AD/cluster path. The standalone signed-conservation assertions were inconclusive because of my comparison helper; I inspected their printed equations instead. The compiled heat-balance probe was not reached. Mixed-axis fallback, zero-length arrays, and unknown symbolic dimensions were not executed locally. I did not reproduce the four sublibrary CI failures on base, nor claim they also fail on master. A contemporary master sublibrary failure log was unavailable. No independent performance benchmark or integration over time was run. The PR remains a draft; this verdict assesses the implementation and does not authorize upstream writes.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

@ChrisRackauckas-Claude
ChrisRackauckas-Claude marked this pull request as ready for review November 2, 2026 02:07
ChrisRackauckas and others added 2 commits November 21, 2026 18:26
Pick up the Symbolics compatibility and docs link fixes.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.170.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__ModelingToolkit.jl__5239--20261121T214107Z-codex-gpt-6.2-sol
Agent-Session: local session 01a20010-0843-7be1-b0c6-185a0b47b772 (no session URL)
Check all-inner and mixed inner/outer balances element by element.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.170.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__ModelingToolkit.jl__5239--20261121T214107Z-codex-gpt-6.2-sol
Agent-Session: local session 01a20010-0843-7be1-b0c6-185a0b47b772 (no session URL)
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

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

PR: #5239

Reviewed head: 1d1ffcd
Raw SHA-256: 26f3e516763a091a99d5cba83e74df44ea8a6f430e71bf0d5bb5aaa681e6e44b
Source SHA-256: ff70a3ee82128a0683ee6632d9b66a135efa8393f24e6e27e67e3a5138083472
Source: standard-review-v1 (harness-log)
Reviewer session: 01a20162-36c6-7e40-a3a5-fc37edf690c1
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: high (H1)
  • Verdict: CHANGES
  • Reviewed head: 1d1ffcd

Review report

VERDICT: CHANGES
Round: 1
Head: 1d1ffcd
Slot: 1
CI: noregress
Session: 01a20162-36c6-7e40-a3a5-fc37edf690c1
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

high (H1: array-flow systems accepted by the base now fail in direct ODE problem construction or in mtkcompile)

Blocking findings

  • Blocking priorities: P1, P2
  • [P1] Direct mass-matrix ODE construction rejects open array ports (lib/ModelingToolkitBase/src/systems/connectors.jl:890). The LHS 0 .* j still contains the flow variable in the symbolic expression. With an open 2×3 port and consistent initial conditions, ODEProblem(complete(network), ...) throws “The LHS cannot contain nondifferentiated variables” on the head. The same input on the base constructs a rank-6 mass matrix and evaluates to [-1, -2, -3, -4, -5, -6, 0, 0, 0, 0, 0, 0]. Use a shaped zero that the direct ODE validators and mass-matrix code recognize, and cover this entry point in a regression test.
  • [P2] Zero-width ports introduce an equation that crashes structural compilation (lib/ModelingToolkitBase/src/systems/connectors.jl:881). Adding an unused port with axes (1:0, 1:3) to D(x) ~ -x emits a zero-row flow block. On the head, mtkcompile reaches flatten_equation and throws a TypeError because collecting the empty LHS yields a Matrix{Any}. The base emits only the equation for x, and its compiled RHS at x = 3 is [-3.0]. Skip zero-length flow sets before constructing the block and add a zero-width case.

Both failures can be reproduced with the following setup. The two testsets exercise separate entry points.

using ModelingToolkitBase, Symbolics, SciMLBase, Test
using ModelingToolkitBase: t_nounits as t, D_nounits as D

@connector function Port(; name, ax = 1:2, ay = 1:3, dynamic = false)
    vars = @variables p(t)[ax, ay] j(t)[ax, ay] [connect = Flow]
    eqs = dynamic ? [D(p) ~ (j .- p)] : Equation[]
    return System(eqs, t, vars, []; name)
end

@testset "Array-flow regressions" begin
    @testset "Open port" begin
        @named a = Port(; dynamic = true)
        @named network = System(Equation[], t, [], []; systems = [a])
        p0 = [1.0 3.0 5.0; 2.0 4.0 6.0]
        ODEProblem(complete(network), [a.p => p0, a.j => zeros(2, 3)],
            (0.0, 1.0); build_initializeprob = false)
    end
    @testset "Zero-width port" begin
        @variables x(t)
        @named a = Port(; ax = 1:0)
        @named network = System([D(x) ~ -x], t, [x], []; systems = [a])
        mtkcompile(network)
    end
end

Non-blocking findings

  • lib/ModelingToolkitBase/src/systems/connectors.jl:880 adds another representative lookup for scalar flows. In a warmed benchmark of 250 scalar pairs, median allocated bytes increased from 18,206,120 to 19,066,088 across 15 expansions, with 500 output equations on both revisions. Pass the representative already resolved by the caller and reuse resolved variables within the array path.

What I ran

  • GROUP=ModelingToolkitBase_InterfaceI julia --startup-file=no --project=scratch/head/lib/ModelingToolkitBase -e 'using Pkg; Pkg.test(; allow_reresolve=true)' exited 0. The suite reported 3,465 passes and 5 broken tests in 36m03.9s. The Components, Stream Connect, Array Flow Connections and Domain Connect files also passed 1,355 assertions in a focused run using the resolved test environment.
  • I ran array_flow_connections.jl against both revisions with Julia 1.12.4, Symbolics 7.49.0 and SymbolicUtils 4.56.2. The head passed all 1,258 assertions. On the base, the block-size testset reported 1,248 passes and failed both allequal(counts) and allequal(sizes).
  • I ran scratch/consistent-regressions.jl and scratch/conservation-probe.jl against scratch archives of the head and base using the same resolved dependencies. The regression probe reported 4 passes on the base and 2 errors on the head. The nonuniform conservation probe passed all 10 assertions on each revision and produced matching compiled ODE outputs. Perturbing one flow by 13 produced exactly two DAE residual magnitudes of 13 on both revisions. Matching offset axes passed 13 conservation and source-mask assertions on the head.
  • The warmed scratch/benchmark.jl expansion of a three-port junction with 2,048 elements per port produced 2,050 equations and allocated a median 22,766,480 bytes on the base. The head produced 3 equations and allocated a median 204,232 bytes.
  • git diff --check origin/master...HEAD, Runic in check mode on all four changed files, and typos on the diff exited 0. uv run --locked python --version reported Python 3.13.13 and warned that locking has no effect outside a project. The checkout has no Python project or UV lockfile.

What I did not verify

The Julia version matrix, downstream integration suites, and the scalar fallback for unequal axes. The unequal-axis whole-port probe was rejected during connector validation on both revisions, before flow equation generation.

AUTHOR_GRADE: {"task":"perf","score":2,"difficulty":3,"rounds":1,"author_harness":"Codex CLI 0.170.0","author_model":"gpt-6.2-sol","note":"The change reduces the size and allocation cost of large flow expansions and preserves conservation in the tested connected network. Two public construction paths reject models that pass on the base."}

Head link: 1d1ffcd


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a20162-36c6-7e40-a3a5-fc37edf690c1 (no session URL)

ChrisRackauckas and others added 2 commits November 22, 2026 00:34
Use an axis-preserving constant zero for array flow balances and
recognize it in ODE validation and code generation. Skip empty flow
sets and exercise both cases through problem construction.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.170.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__ModelingToolkit.jl__5239--20261122T043819Z-codex-gpt-6.2-sol
Agent-Session: local session 01a2018d-daf0-7cf1-9098-bbf108f2988a (no session URL)
Use an axis-preserving constant fill for array flow balances so symbolic
scalarization can broadcast its constructor. Check the axes and scalar
balances for an offset array port.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.170.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__ModelingToolkit.jl__5239--20261122T054201Z-codex-gpt-6.2-sol
Agent-Session: local session 01a201c8-ce54-7fe3-90f0-72bb87e058c7 (no session URL)
@ChrisRackauckas

Copy link
Copy Markdown
Member

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

PR: #5239

Reviewed head: 9cedabc
Raw SHA-256: 4cbc39a8af55de18561a34a9fbdd02b9d458bdf42f2a9b37660e3656015d9ef6
Source SHA-256: 987cd235a6316229511109c02ca6b8079058236f70a4b69369a6c2a0f838cedc
Source: standard-review-v1 (harness-log)
Reviewer session: 01a20478-f288-7130-8563-70dbf9238383
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: high (H1)
  • Verdict: CHANGES
  • Reviewed head: 9cedabc

Review report

VERDICT: CHANGES
Round: 1
Head: 9cedabc
Slot: 1
CI: noregress
Session: 01a20478-f288-7130-8563-70dbf9238383
Reviewer: codex-cli 0.169.0; model: gpt-6.2-astra

Risk

high (H1: two public problem constructors reject previously working models with an open array-flow port)

Blocking findings

  • Blocking priorities: P1, P1
  • [P1] lib/ModelingToolkitBase/src/systems/codegen.jl:313 — ImplicitDiscreteFunction returns a nested residual for a flat three-state system. I used an open connector with scalar p(t) and flow f(t)[1:2]. Its only user equation was Shift(t, 1)(port.p) ~ port.p + port.f[1]. With next state [4., 5., 6.] and current state [1., 2., 3.], the transition residual is 1 + 2 - 4 and the open-port residuals are 5 and 6. Calling the generated function returned [-1.0, 5.0, 6.0] on the base and Any[-1.0, [5.0, 6.0]] on the head. The implicit discrete branch shifts the new array balance but emits it as one output. Pack one scalar residual per state, size the residual prototype accordingly, and test the in-place and out-of-place calls.
  • [P1] lib/ModelingToolkitBase/src/systems/connectors.jl:893 — Emitting Fill(0, 2) ~ port.f also makes direct problem construction fail before code generation. ImplicitDiscreteProblem(complete(sys), ...) constructed on the base for the model above. A separate DDEProblem(complete(sys), ...) with D(x(t)) ~ x(t-1) + port.f[1] and D(port.p) ~ port.p + port.f[2] returned residual [4., 6., 3., 4.] and mass diagonal [1., 1., 0., 0.] on the base. On the head both constructors throw ArgumentError: The system has array equations. The connector supplies the only array equation in either model. Preserve direct construction by lowering generated balances at consumers that require scalar equations, or implement block support for those constructors. Cover both public calls.

Non-blocking findings

None.

What I ran

  • Ran GROUP=InterfaceI julia --compiled-modules=existing --project="$test_env" runtests.jl for ModelingToolkitBase with Julia 1.13.2, Symbolics 7.49.0 and SymbolicUtils 4.56.2. The checkout has no Julia manifest, so I resolved the declared test dependencies in scratch and reused them for both revisions. The head had 3,368 passes, one failure, 27 errors and five broken tests. All 1,263 array-flow and 20 stream-connector assertions passed. I reproduced the one failure and 27 errors in struct_variables.jl on the merge base, including the missing Symbolics._literal_getproperty binding. An unrelated full_equations child process initially missed the scratch project. Its exact test body reran with the project active and exited 0 in 123 seconds.
  • Ran both changed test files with ModelingToolkit loaded. All 1,263 array-flow and 22 stream-connector assertions passed. A separate compiled three-channel heat model matched its analytic temperature and conserved flow.
  • Compared the public calls above on the head and merge base 1feb1ec1db7ba4bb6f2afeefe63175c35328b577. ODE, DAE and nonlinear probes returned matching flat residuals. Connected vector and matrix ports with offset axes also scalarized to the expected signed balances on the head.
  • git diff --check origin/master...HEAD passed. uv run --locked python --version reported Python 3.15.0 and warned that --locked has no effect outside a project. The checkout has no uv.lock.

What I did not verify

I did not run the full repository suite, other Julia versions or downstream packages.

AUTHOR_GRADE: {"task":"perf","score":2,"difficulty":4,"rounds":1,"author_harness":"Codex CLI 0.170.0","author_model":"gpt-6.2-sol","note":"The compact balances preserve signed flows in the tested thermal network. They change the implicit discrete residual shape and break two previously working problem constructors."}

Head link: 9cedabc


🤖 Posted by an AI agent — harness: codex-cli 0.169.0 · model: gpt-6.2-astra
Conversation: local session 01a20478-f288-7130-8563-70dbf9238383 (no session URL)

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