Repository navigation
Preserve array flow balances when expanding connections - #5239
ChrisRackauckas-Claude wants to merge 7 commits into
Conversation
`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
left a comment
There was a problem hiding this comment.
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
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 |
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19817-b88b-78b1-ac2c-f136093d7867, reviewed head d24d090
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 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 findingsNone. Non-blocking findings
What I ranThe 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: All Julia commands used
CI inspection: 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 Author trailers were read from commit What I did not verifyNo 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 |
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)
PR: #5239 Reviewed head: 1d1ffcd Risk assessment
Review reportVERDICT: CHANGES Riskhigh (H1: array-flow systems accepted by the base now fail in direct ODE problem construction or in Blocking findings
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
endNon-blocking findings
What I ran
What I did not verifyThe 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 |
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)
PR: #5239 Reviewed head: 9cedabc Risk assessment
Review reportVERDICT: CHANGES Riskhigh (H1: two public problem constructors reject previously working models with an open array-flow port) Blocking findings
Non-blocking findingsNone. What I ran
What I did not verifyI 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 |
Please ignore until reviewed by @ChrisRackauckas.
Adopts stalled #5135 onto current master:
expand_connectionswas 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-pickedf393dd60with 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):
Regression
lib/ModelingToolkitBase/test/array_flow_connections.jl:Verification commands
InterfaceI tail:
The single InterfaceI failure is unrelated:
`full_equations` doesn't recurse infinitelyinodesystem.jl:1681(!(process_running(proc))after ~3 min under heavy machine load). Stream Connect and Array Flow Connections both passed fully.Not verified
GROUP=All/ QA / other Interface groupsodesystem.jlrecursion-guard flake reproduces on clean master (strongly suspected load flake; not touched by this PR)Reviewer pushback
0 .* wrap(v) ~ ±f₁ .+ ±f₂ …the preferred array form vs keeping scalarized equations and fixing structure later in Compile and generate code for whole-array equation models without scalarizing per element (tracking) #5139?Fixes #5119
Please ignore this draft until reviewed by @ChrisRackauckas.
Risk assessment
expand_connectionsFlow branch /_flow_equations_from_idxs!onlyHarness: Cursor Agent CLI 2026.09.28-64d2043 · Model: auto · Transcript: /log.txt
Risk assessment (orchestrator)
expand_connectionschanges its pre-compile form (e.g.broadcast(*, 0, Q) ~ broadcast(+, Q, Q')), which reverses the earlier deliberate choice of scalar equations.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)
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.JULIA_NUM_THREADS=4, the committed array-flow regression passed 1250/1250, and the extracted VecPin assertion fromstream_connectors.jlpassed (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, atallequal(counts)andallequal(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.🤖 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
Fix by Codex CLI 0.170.0 gpt-6.2-sol (head 1d1ffcd)
Merged current
upstream/masterinto 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 runAdded 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=4andOPENBLAS_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.jl50.texmismatched. At the upstream compatibility commit, variable parsing passed 48/48 and50.texpassed. The officialRegressionIrun compared the tracked50.texand generated four references absent from the default branch.UndefVarError: Reexport not defined in FMIBaseon 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[: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 jobNext 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)
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.
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 QANext 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)
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, andJULIA_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).The separate port replay on reviewed head
1d1ffcda8creproduced the nondifferentiated-LHS and empty-array errors. The three assertions passed on clean master and04f9cb8384, 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 existingfull_equations180-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)