Repository navigation
Polyalgorithm solve!: assert retcode type for Julia 1.10 inference - #1347
ChrisRackauckas merged 2 commits into
Conversation
…ndex
On Julia 1.10, `cache.caches[idx]` with a runtime `idx` infers `Any`, so
`cache.caches[idx].retcode` reaches `build_solution_less_specialize` as
`Any` and `typeof(retcode)` cannot pin the new `RC` parameter that
SciMLBase 3.57 added to `NonlinearSolution`; `solve!` then infers the
partial UnionAll `NonlinearSolution{...}` and `@inferred` fails. Assert
`::ReturnCode.T`, matching the `_uType`/`_fuType`/`_traceType` asserts
already used in this generated body for the same 1.10 limitation.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3
Agent-Model: swe-2-high
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/NonlinearSolve.jl/jobs/inf310-devin/log.txt on amdci2.julia.csail.mit.edu
98fc1d1 to
7f0d1d0
Compare
…ltiplicity Picks up #1347 (PolyAlgorithm solve! retcode type assert for Julia 1.10 inference), fixing the lts Tests-Core and Downgrade-Tests-Core failures. 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 oss-fix/SciML-NonlinearSolve.jl-1375
Independent runtime isolation for the shared Core LTS failure on seven open PRs: with the unchanged The immediate master fix commit All seven inspected heads lack Links:
🤖 Posted by an AI agent — harness: Codex CLI · model: gpt-6.1-sol |
Bump versions: NonlinearSolveBase 2.55.1 Merge master to include Core inference fix Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Agent-Harness: Claude Code 2.1.302 Agent-Model: claude-sonnet-5-5 Claude-Session: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI Agent-Model: gpt-6-luna Agent-Session: local fixer job SciML__NonlinearSolve.jl__1378 (no session URL)
Please ignore until reviewed by @ChrisRackauckas.
What changed and why
SciMLBase 3.57 added an
RCtype parameter toNonlinearSolution(retcode::RC, SciML/SciMLBase.jl#1620). In the generatedsolve!(::NonlinearSolvePolyAlgorithmCache), the fall-through path readsretcode = cache.caches[idx].retcodewith a runtimeidx; Julia 1.10 infers heterogeneous-tuple indexing at a dynamic index asAny, sotypeof(retcode)cannot pinRCand the inferred return type degrades to the partial UnionAllNonlinearSolution{…}, which fails@inferred. This adds a::ReturnCode.Tassert — the declared field type of every subcache'sretcode— matching the_uType/_fuType/_traceTypeasserts the same generated body already uses for this 1.10 limitation.Verification
All on Julia 1.10.12 (
julia +lts), SciMLBase 3.57.0, in a scratch env withNonlinearSolveBasedevved at this branch.Without the fix (registry NonlinearSolveBase v2.54.1, SciMLBase 3.57.0) — reproduces the master failure in
Coreon Julia lts (ubuntu job 109631864277, macos job 109631864862):With the fix:
Same test file on Julia 1.12.7 (SciMLBase 3.57.0): 16/16 pass.
NonlinearSolveBase sublibrary,
GROUP=Coreon Julia 1.10.12 (Pkg.test()inlib/NonlinearSolveBase, SciMLBase 3.57.0): all tests passed.Runic.main(["--check", "lib/NonlinearSolveBase/src/solve.jl"]): clean.typos: clean.CI status on this PR
Three checks are red; none is caused by this change:
RCcause (isconcretetype(NonlinearSolution{…10 params…})assertion atlib/SCCNonlinearSolve/test/core_tests__item4.jl:100). Fixed by Keep spelled NonlinearSolution element type concrete across SciMLBase layouts #1332.PolyAlgorithm Type Inferencetestset (16/16 in job 110572035298); the job then fails in23 Test Problems: BroydenatWatson function | alg #2(norm(res, Inf) = 3.32 > 1e-3). On master the job aborted at the inference error before reaching this file, so the failure is newly visible, not newly caused. The changed line is only reached from the polyalgorithmsolve!; the failing case is a directBroyden(; init_jacobian = Val(:true_jacobian))solve, so this PR cannot affect it. The file passes locally on AMD hardware for both master and this PR; CI ran on Intel. It needs a separate fix.Bisect
SciMLBase v3.56.1..v3.57.0 is six commits; the first bad commit is
ee5dedb7— "Make NonlinearSolution's retcode field type a parameter" (SciML/SciMLBase.jl#1620), whose parent is the v3.56.1 tag itself. The failure is Julia-1.10-specific because 1.12 inferscaches[idx]as a preciseUnionand hence.retcodeasReturnCode.T; the CI jobs on1/preare unaffected.Risk assessment
Very low. The assert is a no-op at runtime: every subcache declares
retcode::ReturnCode.T, so the value is already that type; it only guides inference, as the neighboring::_uType/::_fuType/::_traceTypeasserts do. A non-ReturnCode.Tsub-retcode would already fail at the existingcache.retcode = cache.caches[idx].retcodestore into theReturnCode.T-typed field (polyalg.jl:366), so the assert adds no new failure mode. No dependency or public-API changes.Independent review: Claude Code (model claude-opus-5-5, adversarial round 1) rated this low risk, high confidence, verdict MERGE — review summary at
<local path>on a fleet worker host.Not verified
GROUP=Coreof the outer package on lts (only the failing test file was run); other Core testsets could contain similar runtime-index reads feedingRC.solve()(non-mutating) passes either way — it routes through__solve, not the steppingsolve!; not fully traced.Correction to a previous claim
An earlier version of this body listed
SimpleNonlinearSolve'snonlinear_solution_new_alg(lib/SimpleNonlinearSolve/src/utils.jl) as a possible follow-up, claimingsolve(prob, SimpleLimitedMemoryBroyden())inferredNonlinearSolution{…} where RCon 1.10. That was wrong: my probe passed the bare parametric typeSimpleLimitedMemoryBroyden(itself a UnionAll) as the signature, which trivially widens the result. With a concrete signature bothsolve(prob, SimpleLimitedMemoryBroyden())andnonlinear_solution_new_alginferNonlinearSolution{…, SciMLBase.ReturnCode.T}on 1.10 + SciMLBase 3.57.0, and@inferredpasses — the 10-parameter compatibility constructor picksRC = typeof(sol.retcode)correctly. There is no issue there.🤖 Generated with Devin — Devin CLI 3000.11.3, model swe-2-high; local session, transcript at on a fleet worker host
Risk assessment
solve!loop thatNonlinearSolveBasegenerates forNonlinearSolvePolyAlgorithmCache, in its fall-through branch that picks the best residual. The diff is one line inlib/NonlinearSolveBase/src/solve.jl:606, which adds::ReturnCode.Ttocache.caches[idx].retcode. It is a typeassert, not a conversion. If a sub-cache ever had aretcodethat is notReturnCode.T, this branch would throw aTypeErrorinstead of building the solution. That case already fails at theReturnCode.T-typedcache.retcodestore inpolyalg.jl, so no new failure mode in practice. Users ofFastShortcutNonlinearPolyalg/RobustMultiNewtonand the default algorithm on Julia 1.10 get a concretely inferredNonlinearSolution; behaviour on 1.11+ does not change.ReturnCodeis SciMLBase's public module,NonlinearSolveBase.jl:43already imports it, and the same file already usesReturnCode.T. No non-public internals are used, no public API changes (patch-level), and no tests are weakened, skipped or loosened. No version bump is included.98fc1d1f90sits directly on master06b122951a(0 commits behind). Six checks fail on head. All six also fail on master's push CI for06b122951a(runs 36634513687, 36634513732, 36634513103):sublibraries / lib/NonlinearSolveBase [QA]: same failing tests, 18 passed / 1 failed / 1 errored (all_explicit_imports_are_public,all_qualified_accesses_are_public,public API is rendered in docs).lib/NonlinearSolveFirstOrder [QA]: 19 passed / 1 errored, same tests.lib/NonlinearSolveFirstOrder Core: 1113 passed / 21 errored, same erroring testsets.lib/SCCNonlinearSolve Core: sameisconcretetype(NonlinearSolution{…10 params…})failure.downgrade-sublibraries / test (lib/NonlinearSolveFirstOrder): 1512 passed / 28 errored, same erroring testsets.tests / Core (julia lts, ubuntu-latest): red on master too, so not a regression at check level, but it now fails at a different point.solve!() inferenceerror (core_tests__item3.jl:27). This PR fixes that error: the macOS lts Core job on the PR passes completely.23 Test Problems: Broyden,6: Watson function | alg #2:3.32 ≤ 1e-3, 92 passed / 1 failed.Broyden(; init_jacobian = Val(:true_jacobian))solve. It never enters the polyalgorithmsolve!that was edited.c5f0d24f27, job 109033370232) passed it on a self-hosted runner. The PR job ran on a GitHub-hostedubuntu-latestrunner.test/Core/23_test_problems_tests__item7.jlalready documents that problems with Broydentrue_jacobian(alg Refactor #2) flip between converging and failing depending on the runner.ReturnCode.Tfield type, matching the neighbouring_uType/_traceTypeasserts. Every failing check also fails on master. The newly visible Watson/Broyden failure cannot reach the changed code and is runner-dependent.🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Claude Code 2.1.285 fleet-master head, model claude-opus-5-5[1m]
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (no session URL)
Adopted 2026-10-07 (ci-green head)
What changed: rebased onto master
0055e314(after #1356 and #1357); no code change. Head is now7f0d1d0f.Root cause / where the fix belongs: SciMLBase v3.57.0 (SciML/SciMLBase.jl#1620) made
retcode::RCa type parameter on purpose, for Reactant traced return codes. SciMLBase cannot restore inference here. The value ofRCcomes fromtypeof(retcode), and on Julia 1.10cache.caches[idx].retcodewith a runtimeidxinfers asAny. Only the call site knows that every subcache'sretcodeis aReturnCode.T, so the assert belongs here in NonlinearSolveBase.Verification (Julia 1.10.12, SciMLBase 3.57.0, env with root and all
lib/*devved from the worktree):test/Core/core_tests__item3.jl, master0055e314(fails before):This branch (passes after):
The full root
GROUP=Corerun on lts with this branch ran 82 testsets and exited 0:PolyAlgorithm Type Inference | 16 16,23 Test Problems: Broyden | 93 pass, 22 broken. The Watson/Broyden failure seen on CI earlier did not reproduce locally on AMD. Runic--checkandtyposon the changed file: clean.Red checks after the rebase (CI is still running):
sublibraries / lib/SCCNonlinearSolve / Julia 1 / Core: also red on master0055e314(core_tests__item4.jl:100,isconcretetype). This is the second SciMLBase 3.57 breakage, fixed by Keep spelled NonlinearSolution element type concrete across SciMLBase layouts #1332. Not caused by this PR.benchmark (lts):Unsatisfiable requirements ... SciMLJacobianOperators restricted to 0.1.20 by NonlinearSolveFirstOrder. The benchmark env resolves from the registry, and SciMLJacobianOperators 0.1.20 (Convert Krylov Vector seeds to SVector for Enzyme VJP in SciMLJacobianOperators #1356) is not registered yet. It fails the same way on every open PR (Keep spelled NonlinearSolution element type concrete across SciMLBase layouts #1332 included). This is infrastructure, not this PR. The workflow runs only onpull_request, so master has no run to compare against.Risk assessment
solve!fall-through branch (lib/NonlinearSolveBase/src/solve.jl). It does nothing at runtime forReturnCode.Tretcodes and changes no public API. A non-ReturnCode.Tsub-retcode would already fail at theReturnCode.T-typedcache.retcodestore.🤖 Generated with Claude Code (model: claude-opus-5-5[1m]) https://claude.ai/code/session_011aK5Xvp9NpdkzKuEwtiMGd