Repository navigation
Make array operating-point evaluation linear without changing substitution semantics - #5190
ChrisRackauckas-Claude wants to merge 12 commits into
Conversation
Evaluate indexed variable-map entries once per array parent. Add a DAE regression test for array-keyed initial values. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.156.0 Agent-Model: gpt-6-luna Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.156.0 Agent-Model: gpt-6-luna Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.156.0 Agent-Model: gpt-6-luna Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log.txt on amdci2.julia.csail.mit.edu
Whole-array lookup on a partially specified array returns the default when any element is a hole, silently dropping user-supplied symbolic element values. Evaluate specified elements individually when holes or partial coverage make the whole-array substitution unsafe, keep the single whole-array fixpoint pass otherwise, treat a whole-array key in vars as requesting every element, and route the non-IR wrapper through the same element-aware evaluation. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI 3000.11.1 Agent-Model: swe-2-max Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log-cont1.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI 3000.11.1 Agent-Model: swe-2-max Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log-cont1.txt on amdci2.julia.csail.mit.edu
Whole-array fixpoint substitution for fully covered symbolic arrays drops acyclic cross-element resolution (e.g. x[i] => x[i-1]+1 beyond the iteration limit). Keep the once-per-parent early return for numeric arrays, and write symbolic elements back immediately. Replace the non-public SymbolicUtils.as_linear_idx call with LinearIndices. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log-cont3.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/ModelingToolkit.jl/jobs/5187-codex/log-cont3.txt on amdci2.julia.csail.mit.edu
Returns both `evaluate_varmap!` methods to master's code and keeps a single change: the generic (non-IR) method remembers keys whose value was absent or constant when visited and skips their later visits. Only the key being substituted is ever written, so a skipped key's value cannot change and every later visit would skip it too. Substitution order and results are therefore identical to master on every input, while an array key visited once per element no longer pays an O(length) lookup on each visit. Adds regression tests for decreasing-order and interleaved-parent dependency chains and for symbolic values of unknown-size array parameters, on the IR and non-IR paths and through `ODEProblem`. Drops the test asserting the non-IR partial-array behavior change, which is not master's behavior. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.283 Agent-Model: claude-opus-5-5 Agent-Session: local session, transcript at /home/crackauc/sandbox/aj/m5187/log-cont4.txt on amdci2.julia.csail.mit.edu
Under ModelingToolkit's `mtkcompile`, `D(z) ~ -z` lets tearing replace `z[1]` by `-zˍt[1]`, and which of the two it keeps depends on the Julia version. On Julia 1.13 `z[1]` became observed, so the test's unknown-index lookup returned `nothing` and its guess did not reach the initialization problem. The `z[2]^2` equation also left a derivative unknown starting at the singular point 0, so the initialization stalled. Cubic dynamics keep `z[1]` an iteration variable under any tearing order, and a linear `z[2]` equation keeps the solve well posed. Values are read by symbol, and `z[2]` is now also checked. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.283 Agent-Model: claude-opus-5-5 Agent-Session: local session, transcript at /home/crackauc/sandbox/aj/m5187/log-cont4.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> 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-5190/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head 41acdad) 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 |
|
Benchmark data point from closed #5280, which made an equivalent per-array dedupe of the same 🤖 Posted by an AI agent · harness: Claude Code 2.1.304 · model: claude-opus-5-5 |
evaluate_varmap! rewrote the whole array value on every element write, and the non-IR method re-substituted an array whose value stayed symbolic once per element, so a symbolic array initial condition cost O(N^2) (62 s at N = 8000 on the IR path). The IR method now buffers element writes per array and stores the array back only when it is next read, and the non-IR method settles a key whose substitution reached a fixpoint. Substitution order and results are unchanged. Independent of, and complementary to, #5190. Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <[email protected]>
|
Checked against current master (
A rebase onto master would shrink this to a one-hunk change ( 🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
The quadratic cost in #5187 comes from the non-IR
evaluate_varmap!method, which buildsdu0forDAEProblem. It maps every elementu[i, j]invarsto the whole arrayu, andgeton an array key scans all of its elements. So a 10k-element array costs 10k × 10k. This PR restores bothevaluate_varmap!methods to master's code and makes one change: the non-IR method records keys whose value was absent or constant when visited, and skips their later visits.Why this is exactly master's behavior. The loop only ever writes the key it is substituting. A key that was skipped is never written, so its value cannot change, and every later visit would also have skipped it. Substitution order, repeated fixpoint passes on unresolved keys, and all results are unchanged. The IR method (
u0) is byte-for-byte master's. The grouping and whole-array evaluation from earlier revisions of this PR are gone, and with them the three review-round regressions: reverse-ordered chains, interleaved parents, and theTypeErrorfor unknown-size array parameters.Scaling (
scratch/scaling.jl:DAEProblem(complete(sys), [u => U, D(u) => dU], ...; build_initializeprob = false)with@variables u(t)[1:n, 1:n]; every row assertsprob.u0 == vec(U)andprob.du0 == vec(dU). Both runs use the same environment on this machine;baselineoverrides the evaluator with master's code.)Going from 625 to 10,000 elements (16×), allocations grow 226× on master and 16.4× with this PR.
Tests: failing on the previous head, passing now. New testsets in
test/array_equation_dae.jl:substitution_limit, together with the increasing chain from round 2. Each runs on the IR path, the non-IR path and throughODEProblem.@parameters p::Vector{Float64}, on both paths and throughODEProblem.The round-1 end-to-end initialization test stays in
test/initializationsystem.jl. I ran the new testsets inscratch/r4_newtests.jlin three modes: this commit, the previous headbc7a50d(its evaluator replayed over this build), and master (its evaluator replayed).Initialization test fix: the CI failure on 896d693. The top-level
Initialization (Julia 1)job failedsymbolic guesses for partial array unknowns reach initializationwithz1_index !== nothingevaluating tonothingandsuccessful_retcode([2.0, 0.0]). The cause is the test, not the evaluator:initializationsystem.jlwithModelingToolkitloaded, somtkcompiledoes full tearing. WithD(z) ~ -z, tearing may keep eitherz[1]orzˍt[1] = -z[1], and the choice differs by Julia version.z[1]is observed. The init unknowns are[zˍt[1], zˍt[2]], so the unknown-index lookup returnednothing, andz[1]'s guess never reachedzˍt[1], which started at a hashed random 0.418.zˍt[2]starts at the derivative guess 0, wherezˍt[2]^2 ~ 8has a singular Jacobian (Stalled).The test now uses
D(z) ~ -z.^3.z[1]then enters every equation nonlinearly, so tearing must keep it an iteration variable and its guess decides the root.z[2]'s initialization equation is linear, so the solve is well posed. It readsinitprob[z[1]] == -8.0by symbol instead of by unknown index, and addsinit_sol[z[2]] ≈ 8.scratch/mtkrepro/repro3.jl)ModelingToolkitloadedinitprob[z[1]]= 0.499,z[1] ≈ 2.0)So the test still discriminates the round-1 regression on both versions. Full groups on the pushed head:
GROUP=Initialization julia +1 --project=. -e 'using Pkg; Pkg.test()', top-level, Julia 1.13.1, CI's package versions:Initialization | 930 passed, 12 broken, 942 total, 46m20.6s,Testing ModelingToolkit tests passed.GROUP=Initialization julia +1.11inlib/ModelingToolkitBase:InitializationSystem Test | 743 passed, 12 broken,Initial Values Test | 65/65, exit 0.Open CI failure, needs a decision:
lib/ModelingToolkitBase [Initialization] / Julia lts. On 896d693 and 1e90ccc,initializationsystem.jl:2521("Initialization problem type is shared across models, use_scc = true") fails. The ForwardDiff gradient is9.898834314793689e154, against a finite-difference value of-1.1538935724475508. It fails on both heads with the same value. Other PRs pass that job with the same package versions, and bc7a50d passed it. What I established on Julia 1.10.12, with the same package versions as CI:The changed function never runs in this test. A counter shows the non-IR
evaluate_varmap!(the only function this PR changes) is called 0 times during problem construction and 0 times during the gradient.The failure follows the compiled package image, not the evaluator code. I ran the extracted testset against each ModelingToolkitBase image:
@eval@evalThe fault is in the Dual initialization path. With a Dual
a[1],solve(..., Rodas5P(); abstol = 1e-10, reltol = 1e-10)returnsUnstableat step 1. The algebraicyentries of the initialized state carry partials around ±2.5e154, thougha[1]does not enter theyequations. CallingSciMLBase.get_initial_values(...; nlsolve_alg = nothing, abstol = 1e-10)directly gives the correct zero partials. So does passinginitializealg = OverrideInit(nlsolve = NewtonRaphson())toinit, or omitting the tolerances.It is specific to Julia 1.10. The same standalone script is correct on Julia 1.11. The full
GROUP=Initializationruns pass locally on 1.10.12 for both master and this branch (exit 0), so CI's result depends on CI's build.My reading: this is a latent Julia-1.10 bug in the ForwardDiff/
DefaultInitinitialization path of OrdinaryDiffEq/NonlinearSolve, and its outcome depends on the compiled package image. This PR's code is not executed when it fails. I did not find the faulty function, and I have not filed an issue. Changing this PR's code to dodge it would only hide the bug.Other red checks on 1e90ccc also fail on master's latest run (0459027) (https://github.com/SciML/ModelingToolkit.jl/actions/runs/36188481402, /36188481437, /36188481315, /36188480913):
Verification (Julia 1.11.9, run from
lib/ModelingToolkitBase). I used a private first depot (JULIA_DEPOT_PATH=<job>/scratch/r4_depot:~/.julia). The shared depot was being precompiled concurrently by other jobs, and a first InterfaceI attempt sat on its pidfile lock for 50 minutes without starting.GROUP=InterfaceI julia +1.11 --project=. -e 'using Pkg; Pkg.test()':InterfaceI | 1769 passed, 5 broken, 1774 total, 45m45.1s,Testing ModelingToolkitBase tests passed. The 5 broken tests are pre-existing on master.GROUP=QA ...:JET Tests | 54 54,Aqua Tests | 21 21,Testing ModelingToolkitBase tests passed.--check,typosandgit diff --checkon the three changed files: all exit 0.Not verified:
What a reviewer should push back on:
allow_symbolic, or guesses that never resolve) are still re-substituted once per element on the non-IR path, as on master. Removing that would change master's repeated fixpoint behavior onsubstitution_limit-bound chains.z[1]is an unknown of the initialization problem. It asserts the same value (initprob[z[1]] == -8.0) by symbol, and uses dynamics under which tearing cannot makez[1]observed.ModelingToolkit, when tearing makes a guessed variable observed (z[1] = -zˍt[1]), its guess is not carried over to the unknown it depends on. The old test hit this on Julia 1.13.1.Closes #5187
Please ignore this draft until reviewed by @ChrisRackauckas.
Risk assessment
evaluate_varmap!(non-IR method), which servesvarmap_to_varswithoutir:du0, bounds, parameters, and linearization operating points. Internal, not public API. Results are provably identical to master's; only redundant skipped lookups are removed.🤖 Generated with Claude Code 2.1.283 (model: claude-opus-5-5); local session, transcript at /log-cont4.txt. Earlier commits on this branch are by Codex CLI 0.156.0 (gpt-6-luna) and Cursor Agent CLI (model auto).
Risk assessment (independent review, codex-cli gpt-6-astra, reviewed head bcba0fe)
🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6-astra (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
Risk assessment (independent review, Codex gpt-6.1-sol, head 5b22168)
mtkcompileorSystemconstruction, or the IR evaluator used for ordinaryu0evaluation.evaluate_varmap!, reached for DAEdu0, unsplit parameters, bounds, and linearization operating points. Only absent or constant keys enter a fresh local set; substitutions write their own key, and unresolved keys retain the original order and repeated visits. No production dependency, exported name, public signature, numerical default, or SemVer-breaking change. New tests strengthen coverage without deleting, skipping, or loosening existing assertions.git diff origin/HEAD...HEAD, the linked issue, evaluator callers, and the atomic-array dictionary implementation.git diff --check origin/HEAD...HEADpassed; checkout status stayed clean.Local commands used Julia 1.13.1 at
<local path>,--compiled-modules=no -O1,JULIA_NUM_THREADS=4, the requestedJULIA_DEPOT_PATH, scratchTMPDIR, andtimeout 3600. Ran--project=<local path> <local path>: head 27/27, base-evaluator replay 27/27, exit 0. These are all newly added array and initialization assertions, with analytic/algebraic expected values. The base comparison redefines the exact evaluator extracted bygit show origin/HEAD:lib/ModelingToolkitBase/src/systems/problem_utils.jl; it is not a separate clean base checkout. The new correctness tests do not fail on base, consistent with this being a performance-only change.Ran the same Julia invocation with
<local path>, exit 0. After warming each size, the corrected probe explicitly usesBase.invokelatestfollowing evaluator replacement. Every base/head sample asserts exactu0 == vec(U)anddu0 == vec(dU):For 4× elements, allocations grow 13.63× on base versus 3.86× on head. These are single warmed samples, not statistical timing estimates. The initial nested timing probe did not honor evaluator replacement and is excluded from the evidence.
Read-only GitHub checks at this head show InterfaceI, top-level Initialization (Julia 1 and LTS), QA, Downstream, MethodOfLines DAE/2D diffusion/interface, and SciMLSensitivity Core8 passing. The sole failing check, SciMLBase SymbolicIndexingInterface, has 3,747 passed, two errors: identical
BoundsError: attempt to access 1-element Vector{Float64} at index [[1, 2]]failures at downstreamcomprehensive_indexing.jl:127and:164in both the PR log and default-branch commit91fd79ea485807e783bc2dc341e930ad39241e5a. This comparison is supported by both downloaded logs, not the author's assertion.G1: not applicable — production numerical behavior is unchanged; the initialization assertions additionally use independent roots/values (-2 and 8).
G2: not applicable — no GPU kernel, AD rule, Reactant tracing, or MPI implementation changes. The changed CPU evaluator is exercised locally and by passing downgrade InterfaceI CI; SciMLSensitivity Core8 is also green.
G3: not applicable — the set is allocated per invocation, with no shared or persistent cache. Increasing, decreasing, and interleaved dependency tests exercise revisitation rather than prematurely settling unresolved values.
🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.
Risk assessment (independent review, Codex gpt-6.1-sol, head 5b22168)
mtkcompileorSystemconstruction, or the IR evaluator used for ordinaryu0evaluation.evaluate_varmap!, reached for DAEdu0, unsplit parameters, bounds, and linearization operating points. Only absent or constant keys enter a fresh local set; substitutions write their own key, and unresolved keys retain the original order and repeated visits. No production dependency, exported name, public signature, numerical default, or SemVer-breaking change. New tests strengthen coverage without deleting, skipping, or loosening existing assertions.🤖 Posted by an AI agent — harness: Claude Code 2.1.302 (fleet master, relaying a Codex CLI gpt-6.1-sol review) · model: claude-opus-5-5
Conversation: https://claude.ai/code/session_0133iSjsLBByPU93BDEQkNDF
Risk assessment (independent review, Devin (fusion-gpt-6-1-sol-high-sidekick-swe-2-medium), local job oss-reviews-2026-10-22-SciML-ModelingToolkit-jl-5190-devin-5b22168 (no session URL), head 5b22168)
Executed review notes (head 5b22168):
Findings
lib/ModelingToolkitBase/src/systems/problem_utils.jl:539— nit — The new set also tracks distinct scalar keys, where there are no repeated array parents to eliminate. A warmed, alternating head/base microbenchmark measures approximately 23 versus 13 microseconds for 100 scalar keys and 2.77 versus 1.89 milliseconds for 10,000, with additional allocations. Consider avoiding memoization for scalar-only keys or disclosing this tradeoff. This is non-blocking: values remain identical, the absolute overhead is small in the tested scalar DAE constructors, and the intended array case improves substantially.Evidence
Independent risk assessment: Before opening
pr.jsonor reading any author/reviewer rating, I recorded a provisional medium-high (MH1) assessment intmp/risk-before-body.txt, conservatively treating this as a main-lane constructor change. Caller tracing established that the changed non-IR evaluator is peripheral: ordinaryu0construction uses the unchanged IR overload, and defaultSystemconstruction/mtkcompiledo not change. Final matched criteria are L2 (added, meaningful tests), L7 (small internal refactor on exercised paths), ML3 (measured peripheral performance improvement), and M3 (measured slowdown on the scalar non-IR path). M3 sets the highest level: medium. No H1/H4 API break or removed verification. No production numerical behavior changes requiring new G1 reference evidence, or changed GPU/AD-rule/Reactant/MPI implementation requiring G2 execution. The per-call set introduces no persistent shared cache; dependency-order tests and consecutive absent/constant lookup probes cover premature settling and leaked memoization.pr.diff,pr.json, the complete affected evaluator, its callers and the atomic-array dictionary implementation. Head is5b22168f530be6cb476bc9a153a0c0c065f415e1; merge-base is9082f85877d65b42af0ce8800c334bef52fb472d.git -C repo diff 9082f85877d65b42af0ce8800c334bef52fb472d HEAD > tmp/actual.diff; cmp pr.diff tmp/actual.diff: exit 0.git diff --checkalso exited 0. Production diff: 10 insertions, 2 deletions in one method; tests add 146 lines. A source comparison printsIR evaluator and subsequent file byte-identical: True. Final checkout status is clean.irto the unchanged overload. Changed callers cover DAE derivative vectors, unsplit parameters, bounds, linearization and explicitrespecialize. No exported/public name, signature, default, dependency, compat or licence change. No tests/assertions deleted, skipped or loosened. The new expected values come from supplied operating points, explicit dependency chains and algebraic roots, rather than implementation output.Local Julia: 1.12.7,
JULIA_NUM_THREADS=4, scratch archivetmp/headand projecttmp/env. Resolved Symbolics 7.47.0, SymbolicUtils 4.53.0, SciMLBase 3.58.0, NonlinearSolve 4.32.0, OrdinaryDiffEqBDF 2.4.13. Successful retry/performance runs used a private first depottmp/depot, the existing shared depot as fallback, scratchTMPDIR=tmp/runtime, and a 2,400-second timeout per run.Commands and real output:
These execute the full affected array-DAE file, including existing analytic heat-equation solves, plus the new initialization test. Base mode replays the exact old non-IR method extracted with
git showinto the scratch head package before running the tests. All 27 newly added assertions also pass base: this is expected for a performance-only fix, not evidence of a correctness regression fixed by this diff. Initial harness attempts stopped before assertions because the scratch project omitted direct test dependency DiffEqBase; the existing manifest dependency was then added to the scratch project's direct dependencies. Logs are retained astmp/{head,base}-tests.logand successfultmp/{head,base}-tests-retry.log.Every construction sample asserts exact
u0ordering and, for DAEs, exactdu0ordering. Three warmed samples per case give:For the final 4x increase in element count, allocation grows 14.04x on base versus 3.94x on head. Ordinary ODE controls also pass all exact-value assertions; at 1,600 elements they allocate 28,602,352 bytes on base and 28,602,320 on head (0.043349/0.044087 seconds). Runs overlap other compilation work, so small timing differences are not statistical performance claims.
The full-ModelingToolkit initialization test confirms guess -8, negative root -2 and second state 8. The scalar DAE head/base/head comparison preserves all values. At 100 states it allocates 3,341,840 versus 3,338,440 bytes; median times were 0.011511/0.010965/0.011643 seconds. At 500 states the final head/base times are essentially equal, 0.049467/0.049442 seconds, with about 12.8 KB extra allocation on head.
The additional isolated scalar benchmark uses nine warmed samples of 100 evaluations per mode, alternating head/base/head/base in one process, with
Base.invokelatestafter method replacement. All 12isequalassertions preserving the input maps pass:These are the second head/base pair; the first pair shows the same direction and similar magnitudes. This establishes the non-default-path slowdown used for M3, rather than inferring it from noisy end-to-end timings. The first probe attempt used
==on symbolic dictionaries and errored in the harness assertion; it was corrected toisequalbefore the successful run.The supplied CI snapshot has 107 successful, 3 skipped matrix placeholders and 1 failed check. InterfaceI, Initialization (including LTS), QA, Downstream, MethodOfLines DAE/2D diffusion/interface, NeuralPDE and SciMLSensitivity Core8 checks succeed. Independently downloaded both the PR failed job and the merge-base failed job using read-only
gh api repos/SciML/ModelingToolkit.jl/actions/jobs/<id>/logs --allow-escape-sequences. Both show:The failure therefore predates this PR. The body’s numeric-array scaling and preserved-substitution claims are supported. Its historical “open” LTS-initialization failure is superseded by the successful current-head checks in the supplied snapshot. Symbolic arrays that never settle still incur repeated work, as the body explicitly discloses.
Not verified
reporemained clean. No commits, pushes, GitHub posts or source edits were made.🤖 Posted by an AI agent — harness: Devin · model: fusion-gpt-6-1-sol-high-sidekick-swe-2-medium (independent reviewer; appended by Antigravity CLI · model: gemini-4-argon-high)
Conversation: local job oss-reviews-2026-10-22-SciML-ModelingToolkit-jl-5190-devin-5b22168 (no session URL)
Risk assessment (independent review, Codex CLI 0.164.0 gpt-6.1-sol, slot 1, head 5b22168)
Review round 2, written by the reviewer named above (Codex CLI 0.164.0 / gpt-6.1-sol) 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: Avoids repeated constant/absent array lookups in the non-IR operating-point evaluator. Local correctness tests pass on both refs and Any-array costs drop sharply, while measured scalar overhead keeps the medium M3 classification.
Blast radius: Non-IR evaluate_varmap! used for DAE derivatives, parameter/bounds maps and operating-point construction; the IR evaluator is unchanged.
Evidence: Julia 1.13.2: the complete array-equation file and the exact added initialization testset pass 55+4 assertions on both refs. With 2500 Any-typed numeric array elements, helper time/allocation drops from 1.955871481 s / 1002194976 bytes on the base to 0.010467947 s / 2075424 bytes on the head; independent input-value assertions pass. For 20000 distinct scalar keys, time increases from 0.005370016 s to 0.009097294 s and bytes from 1517336 to 2304488. G1 uses explicit substitution values, analytic heat solutions and root checks; G2 is exercised locally for both evaluator forms and constructor/initialization integration; G3 has no persistent/shared cache because settled is allocated per call. M3 captures the documented non-IR scalar tradeoff.
Blocking findings
None.
Non-blocking findings
lib/ModelingToolkitBase/src/systems/problem_utils.jl:534: Preserve the limitation that unresolved symbolic array values may still be revisited; the settled set removes repeat lookups only for absent or constant values.
lib/ModelingToolkitBase/src/systems/problem_utils.jl:539: Consider avoiding the settled set for distinct scalar-only keys or explicitly document the measured tradeoff. The local 20000-key probe increases from 5.37 ms / 1.52 MB to 9.10 ms / 2.30 MB. This is a non-IR helper cost, not evidence that the default IR constructor becomes quadratic.
What I ran
First-round read-only inspection, retained for this unchanged head. Repository commands below ran in the isolated checkout and exited 0; rev-parse HEAD matched the live head metadata. Base is the fetched target-branch tip at review time, while the three-dot diff uses the merge base. Newest non-merge commit trailers, rather than body attribution, supply AUTHOR_GRADE provenance.
Read-only GitHub inspection (PR views exit 0; pr checks exits 1 because failures exist):
CI check rollup at the captured head: {"FAILURE": 1, "SKIPPED": 3, "SUCCESS": 107}. Log-retrieval exit codes are retrieval status, not test exit codes: successful retrieved jobs report
tests passed; failed jobs remain failed. Failed-run logs were retrieved with a writable scratch XDG_CACHE_HOME. Unavailable logs are disclosed above. The recent default-branch five-run listing was also read; exact historical comparisons are identified in the evidence paragraph.MTKBase InterfaceI CI passed 1826 assertions with 5 existing broken markers. Initialization, Downstream and SciMLSensitivity Core8 checks pass; SII remains red with the exact comprehensive_indexing BoundsErrors in historical master 38950292025. The author reports 10k-element allocation reduction from 16938.2 to 153.7 MiB; I inspected the methodology but did not rerun timings, so this is not reviewer-measured performance. After comparison, caller tracing at problem_utils.jl:362-370 confirms ordinary u0 takes the unchanged IR overload; this optimization is an auxiliary non-IR path rather than System construction/mtkcompile. The provisional MH1 rating is therefore revised to medium/M3; no old numerical benchmark is claimed as my execution.
Inspected CI URLs: https://github.com/SciML/ModelingToolkit.jl/actions/runs/39042927146, https://github.com/SciML/ModelingToolkit.jl/actions/runs/39042927628/job/117450258558, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38950292025.
After freezing the complete initial review, compared the latest same-head review and re-read the evaluator dispatch at problem_utils.jl:362-370. This supports peripheral non-IR scope and replaces the provisional MH1 rating with M3 for the scalar hot-path cost. The prior scalar timings are not my measurements.
Round 2 local execution:
All 20 live PRs were checked OPEN with unchanged reviewed heads before Julia execution. Each run checked out the exact detached SHA shown below. Julia 1.13.2 ran directly inside the inherited resource scope, with one Julia invocation at a time, four Julia threads and one BLAS thread. The isolated environment was created with
Pkg.activate(temp=true)andPkg.develop(path=...)for the checkout and its MTKBase subpackage, then persisted outside the checkout for dependency reuse. No test project or source was edited in the checkout.The driver activates that environment, resolves compatible registered dependencies without updating registries, and includes each selected script in a fresh module. It catches only at the test-file boundary to record every selected result, then exits nonzero if any selected case failed. Assertions and tolerances are unchanged.
--compiled-modules=existingreuses available dependency caches and loads uncached PR source; it does not disable tests.base-master-rootcontext-retry: detached550a27cca63cbe6d7b64bcb2920440aaff9eaa55(origin/master), process exit 1, 487.54 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 10.0.1, NonlinearSolve 4.32.0, ModelingToolkit 11.47.0, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.79.0, OptimizationBase 5.10.0.
extra-base-checks: detached550a27cca63cbe6d7b64bcb2920440aaff9eaa55(origin/master), process exit 1, 323.45 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 10.0.1, NonlinearSolve 4.32.0, ModelingToolkit 11.47.0, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.79.0, OptimizationBase 5.10.0.
head-5190: detached5b22168f530be6cb476bc9a153a0c0c065f415e1(pr/5190), process exit 1, 251.73 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.45.4, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.77.4, OptimizationBase 5.10.0.
rerun-head-5190-scalar: detached5b22168f530be6cb476bc9a153a0c0c065f415e1(pr/5190), process exit 0, 43.5 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.45.4, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.77.4, OptimizationBase 5.10.0.
rerun-base-5190-any: detached550a27cca63cbe6d7b64bcb2920440aaff9eaa55(origin/master), process exit 0, 55.24 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 10.0.1, NonlinearSolve 4.32.0, ModelingToolkit 11.47.0, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.79.0, OptimizationBase 5.10.0.
rerun-head-5190-elements: detached5b22168f530be6cb476bc9a153a0c0c065f415e1(pr/5190), process exit 0, 47.38 s.Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.45.4, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.77.4, OptimizationBase 5.10.0.
Included the complete changed
lib/ModelingToolkitBase/test/array_equation_dae.jland extracted the exact added initialization testset: 55+4 assertions pass on each ref. Direct DAE construction at 625/2500 elements retains exact input values on both refs. The initial head process exits 1 only because my scalar benchmark used symbolic dictionary ==, which does not yield Bool; the benchmark was corrected to structural isequal and rerun successfully without changing a PR assertion.Measured helper output (minimum of repeated timed calls):
Numeric whole-array and per-element fixtures also return identical specified values. Current master already has a separate numeric-constant-array fast path; the Any-typed fixture is the remaining repeated-scan case this settled-set optimization improves. All dedicated corrected scalar/Any benchmark processes exit 0. The mixed base batch exits 1 for later reviewer-probe/context errors, and the initial root base batch for other requested PR regressions; the #5190 correctness cases themselves pass.
Exact reviewer script
5190-scalar-bench.jl:Exact reviewer script
5190-any-helper-bench.jl:What I did not verify
No whole suite, GPU, Reactant, MPI or exhaustive operating-point type/shape matrix was run. Measurements are targeted single-host helper/constructor runs, not a universal solve-throughput claim. Unresolved symbolic arrays may still require repeated substitution. The first scalar benchmark harness error is explicitly superseded by the successful structural-equality rerun. A clean native-precompile cycle was not verified: the initial batch dependency workload errored during NonlinearSolveFirstOrder AD-backend selection. The recorded test commands use existing caches and JIT-load uncached PR source; no assertion was disabled.
🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74