Skip to content

Choose the SCC block container from the specialization level, and precompile a multi-block SCC initialization - #5202

Draft
ChrisRackauckas wants to merge 5 commits into
masterfrom
scc-container-by-specialization
Draft

ChrisRackauckas wants to merge 5 commits into
masterfrom
scc-container-by-specialization

Conversation

@ChrisRackauckas

@ChrisRackauckas ChrisRackauckas commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

🚧 UNREVIEWED — awaiting review by @ChrisRackauckas. Opened by an AI agent running as @ChrisRackauckas; Chris has not reviewed this change.
Harness: Claude Code 2.1.280 · Model: claude-opus-5-5[1m]
Conversation: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH

Please ignore until reviewed by @ChrisRackauckas.

Depends on an SCCNonlinearSolve release. At AutoDespecialize, small homotopy initialization problems now take SCCNonlinearSolve's vector path, which threw MethodError: no method matching probvec(::HomotopyProblem). Fixed in SciML/NonlinearSolve.jl#1321 and released by SciML/NonlinearSolve.jl#1323. Until 1.15.4 is registered, test/homotopy_initialization_scc.jl will error on CI here. The SCCNonlinearSolve floor (currently "1.13") must be raised to "1.15.4" before merging. I left it unchanged so CI can resolve now.

What changed and why

SCCNonlinearProblem now picks its block container from the specialization level: AutoDespecialize always stores the blocks in a vector, FullSpecialize always in a tuple, and AutoSpecialize keeps the existing heuristic (tuple for ≤ 5 blocks). Previously every level used the heuristic, so an initialization problem with 2–5 blocks had a type specific to its block count and the kind of each block, and no precompile workload could cover a user's model. Initialization problems built by ODEProblem are AutoDespecialize by default, so they now share one type across models.

The DAE precompile workload also never reached this path: precompile_dae_problem has a single algebraic block, which builds a plain NonlinearProblem initialization (its docstring said SCC; corrected). This adds precompile_scc_dae_problem — a nonlinear block followed by a linear block — built in the package workload and solved in the FBDF, Rodas5P and default-algorithm extension workloads.

Verification

Julia 1.12.6, aarch64-linux (Jetson AGX Orin), --startup-file=no.

New tests fail without the container change and pass with it. test/scc_nonlinear_problem.jl, the two added testsets, run with src/problems/sccnonlinearproblem.jl reverted to master:

SCC block container follows the specialization level:  Test Failed
  Expression: prob.probs isa container          (x2)
Test Summary: ... | Pass 16  Fail 2  Total 18

container actually produced on master, by level:
  n=2  FullSpecialize -> Tuple    AutoSpecialize -> Tuple    AutoDespecialize -> Tuple
  n=7  FullSpecialize -> Vector   AutoSpecialize -> Vector   AutoDespecialize -> Vector

Initialization `SCCNonlinearProblem` type does not depend on the block count:  Test Failed
  Expression: allequal(typeof.(initprobs))
  Expression: typeof(workload) === typeof(initprobs[1])
Test Summary: ... | Pass 7  Fail 2  Total 9

With the change: 18/18 and 9/9 pass.

First solve of a user model in a fresh session, this checkout at master versus master + this PR, everything else identical, pkgimages built before each timed run. Chain DAE with array parameters, FBDF:

model master this PR
DAE, 3 init blocks, no kwargs 5.58 s 4.17 s
DAE, 6 init blocks, no kwargs 6.09 s 3.96 s
DAE, 6 init blocks, abstol/reltol 6.47 s 5.87 s
ODE, no init blocks (control) 1.13 s 1.22 s

The 6-block case improves too although it was already a vector on master, because nothing precompiled the SCC path before. The row with tolerances barely moves: the workloads solve without keyword arguments, and passing abstol/reltol re-specializes __init's keyword body — a separate, finite axis for a follow-up.

Runtime cost of the vector container, the same blocks stored as a tuple versus a vector, warm solve(prob, NewtonRaphson()), 10th percentile of 2000 (medians were noisier; a test suite was running alongside):

blocks tuple vector
2 66.98 µs 78.15 µs
3 115.36 µs 127.55 µs
5 200.90 µs 219.84 µs

About 10–20 µs per initialization solve, once per solve. FullSpecialize keeps the tuple for anyone for whom that matters.

Suite (this branch, with SCCNonlinearSolve from SciML/NonlinearSolve.jl#1321 dev'd):

  • GROUP=InterfaceII: Pass 1367, Broken 7 — Testing ModelingToolkit tests passed.
  • GROUP=Initialization: Pass 922, Broken 12 — Testing ModelingToolkit tests passed. Against registered SCCNonlinearSolve 1.15.3 the same group has one error, the probvec(::HomotopyProblem) above.
  • GROUP=QA: Pass 39, Fail 1. The failure is No unapproved public reexports for [:ap_var, :canonical_constraints, :constraint_residual], none of which this PR touches. Master's own CI fails identically at e167d97: https://github.com/SciML/ModelingToolkit.jl/actions/runs/35838708180/job/107109419276
  • Docs (docs/make.jl): builds through doctests, @docs expansion and cross-references. The only error is linkcheck on https://docs.sciml.ai/PDEBase/stable/interface/ in docs/src/API/PDESystem.md (not touched here), which returns HTTP 403 from this machine with curl too.

Runic: no changes on the touched files. typos: clean on added lines.

Not verified

  • x86-64: all numbers are from one aarch64 machine.
  • Test groups other than InterfaceII and Initialization; no downstream packages.
  • NoSpecialize and FunctionWrapperSpecialize take the vector path here (anything that is not FullSpecialize or the AutoSpecialize heuristic). That was not specified; push back if either should keep the heuristic.

🤖 Posted by an AI agent — harness: Claude Code 2.1.280 · model: claude-opus-5-5[1m]
Conversation: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH

Independent review (Codex CLI 0.162.1 gpt-6.1-sol, head e2cdc69)

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

VERDICT: CHANGES
The container tests detect the intended change, and the targeted solves pass, but the new dispatch hook depends on a private upstream function. The failed CI checks also lack an independently verified comparison against master.

  1. src/problems/sccnonlinearproblem.jl:831 — confirmed by running: with SCCNonlinearSolve 1.16.0, Base.ispublic(ModelingToolkit.SCCNonlinearSolve, :iteratively_build_sols) returns false. This method both extends that private function and calls its private four-argument specialization. test/qa/qa.jl:344 explicitly exempts the access from verification. This violates the required public-API boundary and couples default initialization solves to an implementation detail that upstream can change without an API break. Put the Enzyme-safe aggregation in SCCNonlinearSolve, or establish a documented public extension point there and require the release providing it; remove the new private-access exemption.

Verification: Julia 1.12.7, four threads and four precompile tasks, startup files disabled, 3600-second shell timeouts. Ran the two added testsets extracted unchanged from test/scc_nonlinear_problem.jl in an isolated environment using the head checkout: specialization/container checks 30/30 passed; initialization-type checks 9/9 passed. Ran the same script against a scratch copy of merge-base 9082f85 with the same resolved dependency versions: the first testset reported 26 passed, 4 failed, 0 errored. Failures were the problem and solution container assertions for two-block AutoDespecialize and seven-block FullSpecialize. Execution stopped at that failed testset, so the second testset was not run on the base. The original checkout's tracked files were not modified. No linked issues were supplied or listed in the PR metadata.

Gates: G1 has independent equation-residual assertions for the nonlinear chains; no numerical formula or tolerance changes appear in the diff. G2 has a passing SciMLSensitivity/Core8 entry in the supplied CI snapshot, which the supplied thread identifies as exercising Enzyme initialization; I did not independently rerun AD. G3 is not applicable: this changes container representation and precompile workloads, without adding shared mutable cache state.

CI comparison: the snapshot reports failures for SciMLBase.jl/SymbolicIndexingInterface and documentation build. The thread attributes these to a pre-existing bounds error and an external-link timeout, respectively, but supplies no independently inspected matching master logs here. GitHub log retrieval failed in this environment. Neither failure is established as a regression or cleared as pre-existing by this review. Two optimization checks were also pending in the snapshot.

Risk criteria matched: L1 documentation, L2 added assertions, ML7 new documented public workload helper, M1 a new method on another package's function, and MH1 changed initialization solve dispatch on a widely used problem-construction path. The change reaches default multi-block DAE initialization, including differentiation through initialization. The performance-only ML11 exception is not established while the downstream failure comparison remains unverified; MH1 sets the rating.

Not verified: full InterfaceII/Initialization/QA groups, local Enzyme or other AD execution, FBDF/default-solver precompile workloads, documentation build, independent performance measurements, complete supported dependency/version matrix, and failed/pending CI jobs against master. The second new testset was not reached on the base.

🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: Codex exec session 01a14b58-ce17-79e3-b048-d42084bc9366 (no public URL)

Codex CLI gpt-6.1-sol rated it medium-high (MH1) at head e2cdc69

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

Risk assessment (independent review, Codex gpt-6.1-sol, head e2cdc69)

  • Verdict: CHANGES
  • Risk: medium-high (MH1: changes types and solver dispatch on the default SCC initialization path used by ModelingToolkit problem construction, including forcing previously vector-solved large systems through generated tuple solvers). Lower matched criteria include L1/L2 (docs/tests), ML7 (additive public helper), M1 (method on another package's function), and M3 (measured latency regression).
  • Blast radius: Multi-block SCC problems, single linear-block SCC initialization, and ODE/DAE initialization using those problems; all vector-storage specialization policies receive the new tuple-solver dispatch. The new precompile helper reaches BDF, default-algorithm, and Rosenbrock extension workloads. No dependency is added, no numerical assertion is loosened or skipped, and the new public helper has a docstring and an @docs entry. Container fields remain documented as collections, so I found no established public storage guarantee requiring a major release; the additive public name needs minor-release handling under repository policy.
  • Evidence: Read pr.txt, the complete git diff origin/HEAD...HEAD, repository instructions, and the entire risk rubric. Read the linked prerequisite PRs and the current author follow-up; the PR has no closing issue reference. Used scratch archives of head e2cdc69 and default 808a4f1 with identical resolved dependencies (Julia 1.12.4, SCCNonlinearSolve 1.16.0, four threads).
    • python3 RUN/scratch/validate.py ran the extracted added testsets with timeout 3600 julia --startup-file=no --project=RUN/scratch/{head,base}-env RUN/scratch/added-tests.jl, serialized, with the requested depot. Head: 39/39 pass. Base: container test 26 pass / 4 fail; initialization test 5 pass / 1 fail / 1 error, the error being the absent new workload helper. The container assertions and block-count type-equality assertion genuinely fail before the change. An initial reduced-environment run omitted OrdinaryDiffEqNonlinearSolve; loading that extension, supplied by the original test's OrdinaryDiffEq import, resolved those harness errors without changing assertions.
    • timeout 3600 julia --startup-file=no --project=RUN/scratch/{head,base}-env RUN/scratch/probe.jl demonstrated equal outer problem types across head block counts but compiled tuple specializations for 2, 7 and 12 blocks; base retained vector solving above five blocks. It also printed Base.ispublic(SCCNonlinearSolve, :iteratively_build_sols) == false.
    • python3 RUN/scratch/probe-serial.py ran same-block-probe.jl in separate head/base processes, using identical repeated nonlinear blocks and checking the independent polynomial residual. After warming seven blocks, head compilation was 0.165786 s (12 blocks), 0.359705 s (20 blocks); base compilation was 0.0 s for both. First-solve wall times were 0.166685/0.360444 s on head versus 0.000480/0.000542 s on base. All accuracy checks passed. These are single-run latency measurements, supported by the observed generated specializations.
    • G1 pass: added nonlinear-chain residual assertions and the isolated polynomial-root checks provide accuracy evidence independent of solver output; both representations satisfy the same equations. G2 pass: the affected Enzyme path is exercised by head CI: SciMLSensitivity Core8 logged 209 pass / 5 pre-existing broken, and its group includes desauty_dae_mwe.jl / “Enzyme through init.” No GPU, Reactant, or MPI path is changed. G3 not applicable: no shared mutable cache, threading implementation, or global-default mutation is introduced; this changes storage, dispatch and static precompile workloads.
    • Live checks contradicted the saved “0 failing” snapshot. Compared actual logs: the SciMLBase indexing job fails identically on head and current default (3747 pass / 2 errors, BoundsErrors at comprehensive_indexing.jl:127,164), and the head docs job's openmodelica.org curl timeout also occurs on default commit 9082f85. The later default docs run succeeded, consistent with an intermittent external-link failure. The requested separate read-only investigation could not establish a trustworthy introducing commit because older indexing runs abort earlier. git diff --check origin/HEAD...HEAD passed and the reviewed checkout remained clean.
  • Merge: needs changes (remove shape-dependent tuple solving from the despecialized vector path and replace the private dependency hook with a supported upstream fix or documented public extension point).

Findings

  1. [P2] Vector storage still invokes a generated solver specialized on every block count — src/problems/sccnonlinearproblem.jl:834-835 — confirmed by running. Tuple(probs) and Val(length(probs)) dispatch every vector-backed SCC into SCCNonlinearSolve's generated tuple implementation. Equal typeof(initializeprob) therefore does not make the solve independent of block count or block kinds. This also affects AutoSpecialize above five blocks, which already used a vector solver on the base. The identical-block probe isolates the resulting regression: after warming seven blocks, moving to twelve/twenty compiles nothing on base but adds 0.166/0.360 seconds on head, while numerical results agree. The two-block workload cannot cover these generated specializations, and the added outer-type assertions cannot detect this failure. Fix the Enzyme-unsafe vector aggregation upstream while preserving vector iteration, then repeat fresh-shape latency validation on the final implementation.
  2. [P2] The workaround relies on an unsupported dependency extension point — src/problems/sccnonlinearproblem.jl:831-835; test/qa/qa.jl:344 — confirmed by running and source inspection. iteratively_build_sols is not public (Base.ispublic returned false), yet ModelingToolkit extends it and calls its private four-argument tuple overload. The QA change exempts this access rather than providing a public contract. An upstream patch can change either signature without a public API break, affecting ordinary SCC initialization downstream. This contradicts the explicit public-API-only instruction; “has no public spelling” does not establish an irreducible exception. Put the aggregation fix in SCCNonlinearSolve, or first publish and document an appropriate extension hook there, then depend on that release and remove this exemption.

What I did not verify

I did not rerun complete test groups, the complete docs build, broad downstream suites, package-image startup benchmarks, or local AD/GPU/Reactant/MPI tests. Relevant head CI and the failing default-branch logs were inspected directly; the two isolated probe sessions do not establish performance across platforms or all models. I did not verify the eventual release version or claim an exact bisected cause for the pre-existing CI failures. No GitHub writes, pushes, commits, or edits to the reviewed checkout were made; all started commands completed.

RUN above denotes <review directory, kept by the fleet master> scripts, full outputs and the base-failure investigation are under its scratch/ directory.

Links:


🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol (independent reviewer; appended by Claude Code 2.1.302 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_0133iSjsLBByPU93BDEQkNDF (fleet master); the review ran as a local headless Codex session with no public URL.

ChrisRackauckas and others added 2 commits September 23, 2026 17:51
AutoDespecialize always stores the blocks of an SCCNonlinearProblem in a vector,
FullSpecialize always in a tuple, and AutoSpecialize keeps the tuple-for-at-most-5-blocks
heuristic. A tuple makes the problem type depend on the block count and on each block's
kind, so initialization problems (AutoDespecialize by default) could not share compiled
code across models.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code 2.1.280
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH
Claude-Session: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH
precompile_dae_problem has a single algebraic block, so its initialization is a plain
NonlinearProblem and the SCC path was never precompiled (its docstring said SCC; fixed).
precompile_scc_dae_problem builds a nonlinear block followed by a linear block and is
solved in the FBDF, Rodas5P and default-algorithm workloads. Tests pin the container per
specialization level and that initialization problems with 2, 3 and 7 blocks share the
workload's type.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code 2.1.280
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH
Claude-Session: https://claude.ai/code/session_01Wt79fZeNaZxiwQ3LagMYXH
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia vlts)

Time benchmarks
master e2cdc69... master / e2cdc69...
ODEProblem 6.72 ± 1 ms 6.72 ± 0.47 ms 0.999 ± 0.17
init 0.114 ± 0.037 ms 0.112 ± 0.035 ms 1.02 ± 0.46
large_parameter_init/ODEProblem 20.7 ± 2 ms 20.7 ± 1.6 ms 0.996 ± 0.12
large_parameter_init/init 0.112 ± 0.015 ms 0.11 ± 0.0073 ms 1.02 ± 0.15
mtkcompile 13.5 ± 1.3 ms 13.7 ± 1.3 ms 0.983 ± 0.13
sparse_analytical_jacobian/ODEProblem 25 ± 2 ms 26.7 ± 1.6 ms 0.938 ± 0.093
sparse_analytical_jacobian/f_iip 0.07 ± 0.01 μs 0.07 ± 0.01 μs 1 ± 0.2
sparse_analytical_jacobian/f_oop 0.362 ± 0.011 ms 0.361 ± 0.0078 ms 1 ± 0.037
time_to_load 7.71 ± 0.17 s 8.07 ± 0.19 s 0.955 ± 0.031
Memory benchmarks
master e2cdc69... master / e2cdc69...
ODEProblem 0.0343 M allocs: 1.8 MB 0.0343 M allocs: 1.8 MB 1
init 0.486 k allocs: 0.0779 MB 0.486 k allocs: 0.0779 MB 1
large_parameter_init/ODEProblem 0.145 M allocs: 5.42 MB 0.145 M allocs: 5.42 MB 1
large_parameter_init/init 0.618 k allocs: 0.172 MB 0.618 k allocs: 0.172 MB 1
mtkcompile 0.0619 M allocs: 3.43 MB 0.0619 M allocs: 3.43 MB 1
sparse_analytical_jacobian/ODEProblem 0.106 M allocs: 5.32 MB 0.106 M allocs: 5.32 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.634 k allocs: 19.6 kB 0.634 k allocs: 19.6 kB 1
time_to_load 0.153 k allocs: 14.6 kB 0.153 k allocs: 14.6 kB 1

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master e2cdc69... master / e2cdc69...
ODEProblem 7.99 ± 1.1 ms 4.84 ± 0.23 ms 1.65 ± 0.23
init 0.0796 ± 0.026 ms 0.0697 ± 0.025 ms 1.14 ± 0.55
large_parameter_init/ODEProblem 24.9 ± 3.5 ms 14.5 ± 1.6 ms 1.72 ± 0.31
large_parameter_init/init 0.0958 ± 0.016 ms 0.0708 ± 0.0041 ms 1.35 ± 0.24
mtkcompile 14.3 ± 1.2 ms 8.99 ± 0.98 ms 1.6 ± 0.22
sparse_analytical_jacobian/ODEProblem 27.6 ± 2 ms 17 ± 1.5 ms 1.62 ± 0.18
sparse_analytical_jacobian/f_iip 0.06 ± 0 μs 0.06 ± 0 μs 1 ± 0
sparse_analytical_jacobian/f_oop 0.101 ± 0.014 ms 0.101 ± 0.014 ms 0.997 ± 0.2
time_to_load 5.47 ± 0.18 s 5.37 ± 0.14 s 1.02 ± 0.042
Memory benchmarks
master e2cdc69... master / e2cdc69...
ODEProblem 0.0334 M allocs: 1.56 MB 0.0334 M allocs: 1.58 MB 0.99
init 0.477 k allocs: 0.0602 MB 0.477 k allocs: 0.0602 MB 1
large_parameter_init/ODEProblem 0.139 M allocs: 4.64 MB 0.139 M allocs: 4.64 MB 1
large_parameter_init/init 0.759 k allocs: 0.166 MB 0.759 k allocs: 0.166 MB 1
mtkcompile 0.058 M allocs: 2.7 MB 0.0581 M allocs: 2.68 MB 1.01
sparse_analytical_jacobian/ODEProblem 0.102 M allocs: 4.23 MB 0.102 M allocs: 4.23 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.848 k allocs: 27 kB 0.848 k allocs: 27 kB 1
time_to_load 0.201 k allocs: 12.1 kB 0.201 k allocs: 12.1 kB 1

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Sep 30, 2026
Address independent review of SciML#5221: leave the Homotopy SCC container
policy to SciML#5202, return InitializeprobParameterMap only under
AutoDespecialize, retarget type-equality to DAE sizes (6, 9), and cover
non-tunable array-parameter indices in CopyParamsByTemplate.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/initdata/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas and others added 3 commits October 16, 2026 04:28
…ecialization

# Conflicts:
#	ext/MTKOrdinaryDiffEqBDFExt.jl
`SCCNonlinearSolve._scc_solve` only keeps its block aggregation inside
Enzyme's type-analysis limits when `sols` is a tuple: the AbstractVector
specialization of `iteratively_build_sols` splats a
`Vector{NonlinearSolution}` into `vcat`, which Enzyme cannot compile,
while the Tuple specialization unrolls instead. This regressed
SciMLSensitivity Core8 (`desauty_dae_mwe`: EnzymeInternalError inside
`map` over `Vector{NonlinearSolution}`) for the vector-stored problems
this branch introduces below `FullSpecialize`.

Vector-stored problems now wrap `explicitfuns!` in `SCCExplicitFuns`, a
local `AbstractVector` marker, and a dispatch on
`iteratively_build_sols(alg, probs::AbstractVector,
explicitfuns::SCCExplicitFuns)` converts both to tuples and delegates to
upstream's numerically identical tuple specialization. `prob.probs` and
the problem attached to the returned solution keep `Vector` storage, so
the container optimization is unchanged and no solver internals are
copied. The marker also keeps the method out of type piracy.

The container test now checks the solved nonlinear-chain residual and
that `sol.prob.probs` preserves the caller's container representation.
`iteratively_build_sols` has no public spelling, so it is added to the
curated ExplicitImports ignore list.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.92
Agent-Model: swe-2-max
Agent-Session: local Devin CLI session 9ad876fae94240bd
@ChrisRackauckas

Copy link
Copy Markdown
Member Author

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

What was wrong

SciMLSensitivity.jl / Core8 failed on test/Core8/desauty_dae_mwe.jl: the "Enzyme through init" test threw EnzymeInternalError inside map(::SCCNonlinearSolve.var"#17#18", ::Vector{SciMLBase.NonlinearSolution{...}}).

This PR makes SCCNonlinearProblem store its blocks in a Vector{Any} below FullSpecialize (and for small AutoSpecialize SCCs). Upstream SCCNonlinearSolve._scc_solve keeps its block aggregation inside Enzyme's type-analysis limits only when sols is a tuple: the AbstractVector specialization of iteratively_build_sols collects Vector{NonlinearSolution} and splats it into vcat(map(s -> s.u, sols)...), which Enzyme cannot compile. The Tuple specialization unrolls instead and is what master always exercised. I verified in isolation that the splatted vcat(map(...)...) over a concrete Vector{NonlinearSolution} is the sole failing operation — Tuple(::Vector{Any}), reduce(vcat, ...), and tuple splats are all Enzyme-safe. This failure is absent on master and on unrelated branches, so it is introduced by this PR.

What changed

  • src/problems/sccnonlinearproblem.jl: vector-stored problems now wrap explicitfuns! in SCCExplicitFuns, an AbstractVector marker owned by ModelingToolkit. A new SCCNonlinearSolve.iteratively_build_sols(alg, probs::AbstractVector, explicitfuns::SCCExplicitFuns) method converts both arguments to tuples and delegates to upstream's numerically identical Tuple specialization. prob.probs stays Vector{Any} and the prob attached to the returned solution keeps Vector storage, so the container optimization is unchanged and no solver internals are copied. The owned marker type also keeps the method out of type piracy (an earlier scc_solve_up variant failed Aqua's piracy check and touched the non-public SCCAlg).
  • test/scc_nonlinear_problem.jl: the specialization/container test now solves each representation, checks the nonlinear-chain residual sol.u[i]^3 + sol.u[i] ≈ (i == 1 ? 1 : sol.u[i - 1]), and asserts sol.prob.probs isa container.
  • test/qa/qa.jl: iteratively_build_sols has no public spelling, so it is added to the curated NONPUBLIC_QUALIFIED_ACCESSES list with a comment.
  • Merged origin/master (9082f85877, +5 commits) as a merge commit; resolved one conflict in ext/MTKOrdinaryDiffEqBDFExt.jl by keeping both this PR's solve(sccprob, FBDF()) workload and master's two tolerance-solve workloads. No rebase, no force-push.

Validation (all run on the post-merge tree at e2cdc69a0c unless noted)

  • GROUP=QA JULIA_NUM_THREADS=4 JULIA_NUM_PRECOMPILE_TASKS=4 julia --project=. -e 'import Pkg; Pkg.test()' → QA | 40 | 40 passed.
  • GROUP=InterfaceII ... julia --project=. -e 'import Pkg; Pkg.test()' → InterfaceII | 1479 pass, 7 broken, 0 fail (the 7 broken are pre-existing @test_brokens).
  • GROUP=Initialization ... julia --project=. -e 'import Pkg; Pkg.test()' → Initialization | 953 pass, 12 broken, 0 fail.
  • SciMLSensitivity test/Core8/desauty_dae_mwe.jl in a dedicated env with this branch dev'd:
    • unfixed tree → "Enzyme through init" errors with EnzymeInternalError inside map over Vector{NonlinearSolution} — identical signature to CI;
    • fixed tree → 21 pass, 0 errors, 5 broken (the 5 broken are pre-existing @test_brokens), re-verified after the master merge.
  • Runic (julia +release --project=@runic -m Runic --inplace on all changed files) → no changes needed.
  • typos over the diff → clean.

Pre-existing failures left alone (fail identically on master or unrelated branches)

  • build (docs): linkcheck of https://openmodelica.org/ times out; master's own Documentation job fails the same way.
  • SciMLBase.jl / SymbolicIndexingInterface downstream: identical bounds-error on master's latest IntegrationTest run.
  • SciMLSensitivity.jl / Core8 mtk.jl:216 BoundsError in the Gauss adjoint checkpoint code: identical signature on unrelated branches; unrelated to SCC.
  • downgrade-mtkbase (Optimization): hits the 6-hour cap inside Ipopt optimal-control collocation solves; the same job fails/hangs on other branches.

🤖 Posted by an AI agent — harness: Devin CLI 3000.11.92 · model: swe-2-max
Conversation: local Devin CLI session 9ad876fae94240bd

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

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

Contractor review (ai-requests#58) of this PR, copied by the posting agent without change to its findings: reviewer Codex CLI 0.164.0 / gpt-6.1-sol, session 01a18da8-3a3a-7620-b234-342bf3d4309e, reviewed head e2cdc69, round 2, verdict CHANGES, risk medium-high.

Risk assessment (independent review, Codex CLI 0.164.0 gpt-6.1-sol, slot 1, head e2cdc69)

  • Risk: medium-high (MH1: Changes default SCC container types and initialization solve dispatch in a core path; performance/downstream validation does not permit a lower classification.)
  • Verdict: CHANGES
  • Session: 01a18da8-3a3a-7620-b234-342bf3d4309e
  • Blocking priorities: P2

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: Changes SCC block containers and routes despecialized solve aggregation through a tuple bridge. The changed tests pass locally, but direct base/head measurements confirm new-shape compilation regressions and the nonpublic upstream hook remains a blocker.

Blast radius: SCCNonlinearProblem containers, initialization problem types, solve-time aggregation and OrdinaryDiffEq extension precompile workloads.

Evidence: Julia 1.13.2: both added testsets pass on the head (30+9 assertions); the first reports 26 passes and 4 failures on origin/master. The real SCC solve probe passes six analytic residual/retcode assertions on each ref. After seven-block warmup, base 12/20-block solve compilation is 0/0 s, head is 0.257194/0.514061 s, confirming the tuple-bridge regression. G1 uses the explicit x^3+x-1 residual. G2 is exercised locally for ordinary solves and by the cited same-head passing Core8 Enzyme/Mooncake CI. G3 includes cross-model/type tests; their pass does not cover compile-latency regression or waive public-API standards.

Blocking findings

  1. [P2] src/problems/sccnonlinearproblem.jl:831 and test/qa/qa.jl:341 — suspected from reading: the new iteratively_build_sols overload/delegation depends on a nonpublic SCCNonlinearSolve implementation method. The added QA exemption explicitly states that the hook has no public spelling. A locally owned marker prevents type piracy, but does not make the dependency hook public. Move the Enzyme-safe aggregation fix upstream behind a supported public API, require its compatible release, and remove the exemption/direct internal access.

  2. [P2] src/problems/sccnonlinearproblem.jl:834 — confirmed by running: converting every vector problem to Tuple(probs) and dispatching with Val(length(probs)) specializes solve aggregation on fresh block counts. After warming seven blocks, the same 12/20-block probe reports base compile times 0.0/0.0 s and head compile times 0.257194/0.514061 s; head elapsed times are 0.258956/0.516731 s versus base 0.000622/0.000833 s. Both versions satisfy independently calculated cubic residuals. Preserve vector iteration in the upstream AD-safe aggregation repair and include this final-head new-shape benchmark; outer type equality misses the regression. The probe was prompted by the earlier same-head review and is now independently rerun.

Non-blocking findings

None.

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.

git fetch origin +refs/pull/5202/head:refs/remotes/pr/5202 +refs/heads/master:refs/remotes/origin/master
git checkout --detach pr/5202
git rev-parse HEAD
git rev-parse origin/master
git diff --check origin/master...HEAD
git log -1 --no-merges --format=%B
git diff origin/master...HEAD

Read-only GitHub inspection (PR views exit 0; pr checks exits 1 because failures exist):

gh pr view 5202 --repo SciML/ModelingToolkit.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid,title,files,commits,statusCheckRollup
gh pr view 5202 --repo SciML/ModelingToolkit.jl --json body,closingIssuesReferences
gh pr checks 5202 --repo SciML/ModelingToolkit.jl

gh run view 39049155620 --repo SciML/ModelingToolkit.jl --log-failed
gh run view 39049155633 --repo SciML/ModelingToolkit.jl --log-failed
gh run list --repo SciML/ModelingToolkit.jl --branch master --event push --limit 5 --json databaseId,headSha,conclusion,url,name
gh run view 38950292025 --repo SciML/ModelingToolkit.jl --log-failed
gh run view --repo SciML/ModelingToolkit.jl --job 117444013781 --log

CI check rollup at the captured head: {"FAILURE": 2, "SKIPPED": 4, "SUCCESS": 79}. 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.

SciMLSensitivity Core8 CI log ends with tests passed, exercising Enzyme/Mooncake initialization integration; Downstream and InterfaceII checks also pass. SII failure matches historical master 38950292025. The body's older benchmark tables and Homotopy vector-path prerequisite predate this head's tuple bridge and were not revalidated locally.

Inspected CI URLs: https://github.com/SciML/ModelingToolkit.jl/actions/runs/39049155620, https://github.com/SciML/ModelingToolkit.jl/actions/runs/39049155633, https://github.com/SciML/ModelingToolkit.jl/actions/runs/39049155620/job/117444013781, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38950292025.

After freezing the complete initial review, compared both same-head Codex reviews. The final review adds prior-reported latency evidence to the independently noted tuple-bridge concern; no local timing is claimed.

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) and Pkg.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=existing reuses available dependency caches and loads uncached PR source; it does not disable tests.

base-master-rootcontext-retry: detached 550a27cca63cbe6d7b64bcb2920440aaff9eaa55 (origin/master), process exit 1, 487.54 s.

git -C ModelingToolkit.jl checkout --detach origin/master
REVIEW_CASES='5182,5190,5190-bench,5202,5205-root,5205-contract,5205-ad,5213,5221,5202-bench,5221-bench' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing --depwarn=yes tmp/rerun/driver.jl

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-5202: detached e2cdc69a0ce41f04b766758ef52bceb54123df81 (pr/5202), process exit 0, 248.19 s.

git -C ModelingToolkit.jl checkout --detach pr/5202
REVIEW_CASES='5202,5202-bench' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing --depwarn=yes tmp/rerun/driver.jl

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.

The two exact new testsets were extracted unchanged from test/scc_nonlinear_problem.jl. Base: first block 26 passes / 4 failures; head: 30+9 passes. A separate real MTK SCC problem with identical cubic blocks is solved at 7, 12 and 20 blocks using NewtonRaphson; all six independent residual/retcode assertions pass per ref. Output:

base blocks=7 seconds=0.751599704 compile=0.749141435
base blocks=12 seconds=0.000622246 compile=0.0
base blocks=20 seconds=0.000832649 compile=0.0
head blocks=7 seconds=0.650158797 compile=0.647860494
head blocks=12 seconds=0.258956051 compile=0.257194192
head blocks=20 seconds=0.51673113 compile=0.514061303

These are reviewer measurements on the exact recorded refs, not the earlier review or author timings. The base batch exits 1 for its requested regressions; the head process exits 0.

Exact reviewer script 5202-bench.jl:

using ModelingToolkit, NonlinearSolve, SciMLBase, Test
function same_block_problem(n)
 @variables x[1:n]
 sys=mtkcompile(System([0 ~ x[i]^3+x[i]-1 for i in 1:n];name=:same_block))
 return SCCNonlinearProblem{true,SciMLBase.AutoDespecialize}(sys,[x=>fill(.6,n)];combine_sccs=false)
end
@testset "New-shape SCC solve accuracy and compilation" begin
 for n in [7,12,20]
  prob=same_block_problem(n)
  stat=@timed solve(prob,NewtonRaphson())
  @test SciMLBase.successful_retcode(stat.value)
  @test maximum(abs,stat.value.u.^3+stat.value.u.-1) < 1e-7
  println("SCC_BENCH blocks=",n," seconds=",stat.time," compile=",stat.compile_time," recompile=",stat.recompile_time," bytes=",stat.bytes)
 end
end

What I did not verify

No whole suite, HomotopyContinuation scenario, GPU, Reactant or MPI run was performed. Enzyme/Mooncake integration is supported by the cited passing same-head Core8 CI, not claimed as a local run. The measurements cover the new-shape real SCC path; they are not a comprehensive latency or solver-throughput benchmark. 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

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Oct 31, 2026
Keep CopyParamsByTemplate index containers as Vectors, erase ObservedWrapper
to Any, and replace the split initprobpmap closure with a named callable so
chain DAE OverrideInitData types match across model sizes. Also vectorize SCC
blocks under AutoDespecialize (HomotopyProblem exception), overlapping SciML#5202.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/initdata/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Oct 31, 2026
Address independent review of SciML#5221: leave the Homotopy SCC container
policy to SciML#5202, return InitializeprobParameterMap only under
AutoDespecialize, retarget type-equality to DAE sizes (6, 9), and cover
non-tunable array-parameter indices in CopyParamsByTemplate.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/initdata/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas added a commit that referenced this pull request Oct 31, 2026
* Make AutoDespecialize initialization data model-independent

Keep CopyParamsByTemplate index containers as Vectors, erase ObservedWrapper
to Any, and replace the split initprobpmap closure with a named callable so
chain DAE OverrideInitData types match across model sizes. Also vectorize SCC
blocks under AutoDespecialize (HomotopyProblem exception), overlapping #5202.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/initdata/log.txt on amdci2.julia.csail.mit.edu

* Drop SCC hunk; keep AutoSpecialize initprobpmap closure

Address independent review of #5221: leave the Homotopy SCC container
policy to #5202, return InitializeprobParameterMap only under
AutoDespecialize, retarget type-equality to DAE sizes (6, 9), and cover
non-tunable array-parameter indices in CopyParamsByTemplate.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/initdata/log.txt on amdci2.julia.csail.mit.edu

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>

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

bot-generated Filed by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants