Repository navigation
Preserve Vector container eltype when remaking SCCNonlinearProblem - #1615
Merged
ChrisRackauckas merged 2 commits intoSep 24, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
scc_update_subproblems used map, which narrows the output eltype to the common concrete block type. Remaking a problem with homogeneous blocks then yields a different SCCNonlinearProblem type than remaking one with heterogeneous blocks, splitting solve-time compiled code by block homogeneity. Fill a vector of the same eltype instead, unless the input eltype is concrete. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: opencode <[email protected]> Agent-Harness: opencode 1.18.31 Agent-Model: opencode/muse-spark-1.3-contributor-free Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/residual/log.txt on amdci2.julia.csail.mit.edu
Copying into similar(probs) throws when a remake changes a block's type under a narrow abstract eltype. Compute with map first and only copy into the caller's container when every rebuilt block fits its eltype, so concretely typed and narrow abstract containers keep working as before. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: opencode <[email protected]> Agent-Harness: opencode 1.18.31 Agent-Model: opencode/muse-spark-1.3-contributor-free Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/residual/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas
marked this pull request as ready for review
September 24, 2026 17:42
Merged
ChrisRackauckas
referenced
this pull request
Sep 26, 2026
Agent-Harness: Claude Code Agent-Model: claude-opus-5-5[1m] Agent-Session: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ignore until reviewed by @ChrisRackauckas.
What changed and why
scc_update_subproblems(probs::Vector, ...)rebuilt the block vector withmap, which narrows the output eltype to the common concrete block type.Remaking an
SCCNonlinearProblemwith homogeneous blocks (e.g. MTKinitialization problems with all-
NonlinearProblemblocks) therefore yieldsa different problem type than remaking one with heterogeneous blocks — and a
different type than the problem had at construction (
Vector{Any}).Solve-time compiled code splits by block homogeneity, so MTK's multi-block
SCC precompile workload (nonlinear + linear blocks, see
SciML/ModelingToolkit.jl#5202) cannot cover
all-nonlinear user models on the
remake/_scc_solvepath.The fix fills a vector of the same eltype (
map!intosimilar(probs))unless the input eltype is concrete, in which case
mapis kept soelement-type-changing remakes keep working. Tuple storage is untouched
(handled by the separate
Tuplemethod).Verification
New testset in
test/problem_building_test.jl(homogeneousNonlinearProblemblocks in
Vector{Any}; remake must keepVector{Any}; concrete-typedcontainer still remakes correctly). Full
problem_building_test.jlrunlocally. Before (fix stashed):
After:
Whole file green (exit 0), including the pre-existing SCC testset (7/7).
Runic
--checkandtyposclean on both changed files.Attribution evidence (MTK TTFX residual analysis,
--trace-compilediffs offirst vs second user model, Snoop-free): native-codegen residual for a user
DAE first solve drops 75 → 55 compiled methods (−27%) with this fix and its
SCCNonlinearSolve companion; the 39 vanished lines are SCC-remake-path
codegen. Load caveat: trace batteries ran at loads 23–47; single-run
wall-clock numbers are not comparable across runs, so no wall-clock claim is
made here.
What was NOT verified
Wall-clock improvement, and the per-block dynamic-dispatch cost of iterating
a
Vector{Any}instead of a narrowed vector (expected small vs a Newtonsolve; unmeasured). Full SciMLBase suite not run (only the file containing
the new test); downstream packages not tested.
Part of the MTK TTFX effort; related to SciML/ModelingToolkit.jl#5202.
🤖 Generated with opencode 1.18.31 (model: opencode/muse-spark-1.3-contributor-free); transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/residual/log.txt on amdci2.julia.csail.mit.edu
Risk assessment
Review
VERDICT: MERGE
Review of #1615 at head d544b61 (branch
scc-preserve-container-eltype, base b7076b5).Risk assessment
Low risk, high confidence. The change is 6 lines in
scc_update_subproblems(probs::Vector, ...). It still builds the blocks withmap, which gives the same result as master. It copies intosimilar(probs)only when every rebuilt blockisa eltype(probs), so the copy cannot throw. When a block changes type, the function returns the narrowedmapresult, exactly as master does. TheTuplemethod is untouched. The guard matches SciML/NonlinearSolve.jl#1328scc_solve_upline for line. #1328 has an extraprobs isa AbstractVectorcheck because itsprob.probscan be a Tuple; here dispatch on::Vectoralready rules that out. I ran before/after probes and they behave as intended. Every red CI job also fails on unrelated PRs from the same day.Blocking findings
None.
Non-blocking findings
map!intosimilar(probs)unless the input eltype is concrete, in which casemapis kept"). With d544b61, concrete containers also go through theall(isa)guard andcopyto!, and the rebuild ismapfollowed by a conditionalcopyto!, notmap!. The "before" output (3 1 4) comes from the 4-assertion version of the test; the testset now has 6 assertions. The body should be updated before merge.remake(sccprob5; u0 = Float32[1.5, 0.5])with a state check would pin it.eltype(probs)is concrete and the remake keeps the type,mapalready returns aVector{T}, and the guard allocates and copies a second one. The cost is negligible, and [v2-backport] Fix integer time-step indexing under AD (#1325) #1328 has the same redundancy. Anisconcretetype(eltype(probs))short-circuit would skip it.mapwould narrow homogeneous blocks…" explains why the assertion exists, which is acceptable.Checklist answers
mapfirst, thenif all(Base.Fix2(isa, eltype(probs)), out); out = copyto!(similar(probs), out); end. Under a narrow abstract eltype, a block whose type changes makes the guard false, so nothing is copied and there is no MethodError. Confirmed by running (probe (a)).sccprob2.probs isa Vector{Any}, because the result narrows toVector{NonlinearProblem{…}}, and atsccprob6.probs isa Vector{U}, because the result narrows toVector{NonlinearProblem{…} where F}.test/problem_building_test.jlexits 0.Unionnarrower thanAny: the eltype is kept when the blocks fit. WithFloat32u0the result falls back to narrowing, withFloat32sub-states.AbstractSciMLProblem[...]: kept on the PR, narrowed on master.Float32remake: works, and the type is identical to master's.probs::Vector, so views never reach this code. That is unchanged from master; from reading only, not run.Vector:allover no elements is true andcopyto!of an empty vector is fine. Other paths were already reported to throwBoundsErroron emptyprobsbefore this PR; from reading only.[1.5, 0.5]and container types) are the requested inputs and invariants, not values copied from code output.CI
All failures are pre-existing or infrastructure:
Base.Callableatsrc/problems/nonlinear_problems.jl:256, which is not in this diff.Base.Fix2was not flagged. Job: https://github.com/SciML/SciMLBase.jl/actions/runs/35983109070/job/107580441499type SCCNonlinearProblem has no field u0, raised fromNonlinearProblem(::SCCNonlinearProblem)atnonlinear_problems.jl:241on a Tuple-probs SCC. That path is not touched here. Job: https://github.com/SciML/SciMLBase.jl/actions/runs/35983109070/job/107580441709SystemError: … Permission deniedopening a Catalyst testProject.toml, which is an infrastructure failure. Job: https://github.com/SciML/SciMLBase.jl/actions/runs/35983108153What I ran
gh pr view/diff/checks 1615,gh run view --log-failedon the QA, SII, Catalyst and Core jobs,gh pr diff 1328 -R SciML/NonlinearSolve.jl. I also read/Users/chrisrackauckas/sandbox/fleet-master/jobs/918-1/REVIEW-1328-r2.md./Users/chrisrackauckas/sandbox/master/r1615(pr1615 = d544b61) and a master worktreer1615-master(b7076b5), each dev'd into its own env. Julia 1.12.7.jobs/918-2/probe.jl: the new testset's body, plus cases (a)Uwith aFloat32remake, (b) concrete container with aFloat32remake, (d)AbstractSciMLProblem[...], and (e) Tuple. Each testset is wrapped so that every case runs on master.probe_pr.logandprobe_master.log.test/problem_building_test.jlon the branch: exit 0, new testset 6/6 (problem_building_pr.log).What I did not verify
Vector{Any}.probsinput (reasoned from dispatch only).🤖 Risk assessment added by an AI agent — harness: Devin CLI 3000.11.3 · model: fusion-claude-opus-5-5-medium-sidekick-swe-2-medium (fleet master); reviewer: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Devin CLI fleet-master session on Chris's Mac (no session URL); review output at ~/sandbox/fleet-master/jobs/918-2/REVIEW-1615.md