Repository navigation
Preserve Vector container eltype in scc_solve_up - #1328
Merged
ChrisRackauckas merged 2 commits intoSep 24, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
scc_solve_up rebuilt the block vector with map, which narrows the output eltype to the common concrete block type, so _scc_solve sees a different SCCNonlinearProblem type for homogeneous vs heterogeneous block vectors. Fill a vector of the same eltype instead, unless the input eltype is concrete. Tuple storage is untouched. 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
map! into similar(probs) throws when concretization changes a block's type under a narrow abstract eltype (e.g. a literal mixing specialization levels or a Union of block types). Compute with map first and only copy into the caller's container when every rebuilt block fits its eltype. 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
This was referenced Sep 24, 2026
ChrisRackauckas
referenced
this pull request
Sep 25, 2026
Agent-Harness: Devin CLI 3000.11.3 Agent-Model: fusion-claude-opus-5-5-medium-sidekick-swe-2-medium Agent-Session: local Devin CLI fleet-master session on Chris's Mac (no URL)
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_solve_uprebuilt the block vector withmap(_concrete_scc_problem, prob.probs), which narrows the output eltype to the common concrete blocktype.
_scc_solvetherefore sees a differentSCCNonlinearProblemtype forhomogeneous block vectors (
Vector{NonlinearProblem{...}}) than forheterogeneous ones (
Vector{AbstractSciMLProblem}) — and a different typethan the problem had at construction (
Vector{Any}). Solve-time compiledcode 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 this path.
The fix uses
map!intosimilar(prob.probs)unless the input is aTupleor has a concrete eltype, in which cases
mapis kept (Tuple storage isstable by construction; a concretely typed input must keep working even if a
remake changes the element type).
Note: this touches the same file as
#1321 (
probvecfix) but adifferent hunk (this PR:
scc_solve_upline ~70; #1321:probvecline ~81).A trial
git merge-treeof that branch into this one reports zero conflictmarkers — expected clean merge in either order.
Verification
New test
test/core_tests__item7.jl(registered incore_tests.jl):homogeneous
NonlinearProblemblocks inVector{Any}, solved withSCCAlg(nlalg = NewtonRaphson()); asserts the solve succeeds, the solutionis correct, and the solution's problem (
sol.prob, i.e. exactly what_scc_solvereceived) still has aVector{Any}block container. Before(fix stashed; correctness asserts pass, only the eltype assert fails):
After: item7 passes (5/5), and the full SCCNonlinearSolve core group passes
locally (exit 0): Manual SCC 14/14, #758 3/3, Residuals Transfer 6/6,
FunctionWrappers 13/13, Homotopy 5/5, AutoDespecialize 21/21, new item 5/5.
Runic
--checkandtyposclean on all 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
SciMLBase companion (
scc_update_subproblems); the 39 vanished lines areSCC-remake-path codegen, and the user
_scc_solveinstance now matches theworkload's (
Vector{Any}container in both). Load caveat: trace batteriesran 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). Only the SCCNonlinearSolve core group was run, not the
whole NonlinearSolve suite or downstream packages.
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
Round 2 re-review of #1328 at head 4d42a74. Companion PR checked: SciML/SciMLBase.jl#1615 at d544b614.
Blocking findings
None. Round-1 blocking finding 1 is resolved:
scc_solve_upnow runsmapfirst. It copies intosimilar(prob.probs)only whenprobs isa AbstractVectorand every rebuilt blockisa eltype(prob.probs); otherwise it keeps the narrowedmapresult (src/SCCNonlinearSolve.jl:70-75). SciMLBase#1615'sscc_update_subproblemsuses the same guarded form.core_tests__item7.jl:28-37: the literal[_nfs, _nad](one AutoSpecialize block, one AutoDespecialize block) and aUnion{typeof(_nfs), typeof(_nad)}vector. Both assert a successful retcode and the correctu. Confirmed by running: with the src reverted to the unguarded ff78745, item7 errors at line 34 withMethodError: Cannot convert … DespecializedParameters …. So the new test discriminates the round-1 bug.Non-blocking findings
map!intosimilar(prob.probs)unless the input is aTupleor has a concrete eltype"). It also says "item7 passes (5/5)", but item7 now has 11 assertions. The "75 → 55 compiled methods" claim still has no command or output attached. I did not reproduce it.using SCCNonlinearSolveis gone.typeof(_sol.prob) === typeof(_shet.prob)is asserted, homogeneousAny[nl, nl]vs heterogeneousAny[nad, lin]. Confirmed by running: with master src it fails at line 47, and line 25 (isa Vector{Any}) fails too.copyto!(similar(...))makes a second allocation and copy of a vector thatmaphad already built with the same eltype. The cost is negligible per solve, butisconcretetype(eltype(prob.probs))could skip it.U[prob1, probd]+u0 = Float32[...]case to that test would pin it.Any,AbstractSciMLProblem). NarrowUnion/UnionAll containers that hold AutoDespecialize blocks still narrow, as they do on master. That is correct behavior. It just means the TTFX benefit does not apply to those containers.probs(Any[],U2[]) throwBoundsErrorboth on master and on the PR. This is pre-existing and not introduced by this PR.What I ran
(julia +1.12; SciMLBase 3.56.0, LinearSolve 5.18.1; NonlinearSolve sublibs dev'd from a scratch clone at /Users/chrisrackauckas/sandbox/master/r1328; logs are in
r1328/logs/.)gh pr view/diff/checks 1328,gh pr diff 1615 -R SciML/SciMLBase.jl.GROUP=Core Pkg.test()in lib/SCCNonlinearSolve:core_head.log);core_ff78.log);core_master.log).r1328/probe_nls.jl) against head and master src. On both, every case solves withSuccessand the correctu: literal mixed,Union{nfs,nad},Union{lin,nad}, partial UnionAllNonlinearProblem{V,true,V}, concrete[nad,nad]and[nfs,nfs],Any[…],AbstractSciMLProblem[lin,nad], Tuples(nfs,nad)and(lin,nad),view(Any[…],1:2),view(U2[…],1:2), reversedview(Any[…],2:-1:1). The eltype is kept only on head, and only for theAny/AbstractSciMLProblem/view(Any)containers. Views come back asVectorviasimilar, which is fine. Tuples take themappath unchanged.r1328/probe_scimlbase.jl):Anycontainers and forUwhen the remake fits.Uor a concrete container, withFloat32/BigFloatu0; partialNonlinearProblem{Vector{Float64}}withFloat32), it falls back to narrowing, with correct state and sub-u0types.test/problem_building_test.jlon pr1615 passes in full.What I did not verify
Vector{Any}.🤖 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-1/REVIEW-1328-r2.md