Repository navigation
Evaluate Jacobians into a private residual buffer - #1365
ChrisRackauckas-Claude wants to merge 5 commits into
Conversation
`construct_jacobian_cache` stored the solver's residual array as the `JacobianCache` output buffer, so every in-place AD Jacobian evaluation overwrote the solver's `fu` with the dual-number primal of f(u). That primal is not bitwise equal to a plain f call (e.g. `sin` of a Dual goes through `sincos`), so the residual used by the step and the termination check silently changed after each Jacobian evaluation. Use the cache's own `fu_cache`, which is already allocated for DI preparation. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Agent-Harness: Claude Code Agent-Model: claude-opus-5-5 Agent-Session: https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Independent review (Devin CLI 3000.11.3, model fusion-claude-opus-5-5-high-sidekick-swe-2-medium): MERGE, risk low. Full reviewVERDICT: MERGE PR: #1365 (head 7dd4590, base origin/master 8a86577). No linked issue; stacked follow-up is #1367. The change is one line: Blocking findingsNone. Non-blocking findings
What I ranAll runs used Julia 1.12.7, with two scratch envs built from
What I did not verify
🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (review), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19739-725e-7912-a1dc-67463ce639e2, reviewed head 377c92a
Review written by the reviewer named above 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: The PR retains the existing private residual workspace for repeated Jacobian evaluations, preventing AD from overwriting the solver residual. The added regression fails on the merge-base and passes at the reviewed live head; no blocking defect was found. Blast radius: Array-valued JacobianCache construction in NonlinearSolveBase, particularly in-place differentiated residuals used by FirstOrder and default polyalgorithms; analytic, scalar, out-of-place, and operator Jacobian evaluation methods retain their computation paths. Evidence: Blind assessment recorded and hashed before author context. Julia 1.13.2 regression: head 4/4 pass, exit 0; merge-base 2 pass/2 fail, exit 1, both failures at the exact residual-preservation assertion. The Jacobian oracle is analytic. CI covers Base Core, FirstOrder, polyalgorithms, AD, CUDA, and downstream integrations; the three failed jobs have matching failures on master as detailed below. G1, G2, and G3 have independent analytic, executed ForwardDiff, and repeated-buffer-preservation evidence respectively. Blocking findingsNone. Non-blocking findingsNone. What I ranRead-only inspection used Julia invocations below use
CI inspection used
What I did not verifyThe independent probe did not reach its sparse-prototype or square-system cases, and did not validate the all-zero prototype case; the added square-system regression was verified separately on both revisions. Did not reproduce the author's 98-configuration comparison or timing/allocation measurements. Did not locally run whole-package, downstream, GPU, MPI, Reactant, or non-ForwardDiff AD suites, or Julia LTS and other operating systems; relevant CI statuses are distinguished above from local executions. No performance-only classification is assumed. The PR remains a draft; merge authorization and publication are the coordinator's responsibility. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Include the upstream return-code type assertion for polyalgorithm solve!, which resolves the existing Julia 1.10 Core inference failure. Preserve the private Jacobian residual workspace change. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local fixer job SciML__NonlinearSolve.jl__1365 (no session URL)
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Muse <noreply@meta.com> Agent-Harness: Muse CLI Code Agent-Model: muse-wonder-full-1.0 Agent-Session: local fixer job SciML__NonlinearSolve.jl__1365 (no session URL)
TaylorDiff 0.3.5 fails to precompile with current Symbolics: its code generation passes a Symbolics.Num through the ChainRules tanh frule, which uses it in a boolean context. TaylorDiff 0.3.6 drops the Symbolics dependency and precompiles cleanly. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Muse <noreply@meta.com> Agent-Harness: Muse CLI Code Agent-Model: muse-wonder-full-1.0 Agent-Session: local fixer job SciML__NonlinearSolve.jl__1365 (no session URL)
Please ignore until reviewed by @ChrisRackauckas.
What changed and why
construct_jacobian_cachehanded the solver's own residual array toJacobianCacheas the output buffer, and(cache::JacobianCache)(u)passes that buffer asytoDI.jacobian!. For an in-place problem differentiated with ForwardDiff, every Jacobian evaluation therefore overwrote the solver'sfuwith the dual-number primal of f(u).That primal is not bitwise equal to a plain
f(u)call. For example,sinof aDualgoes throughsincos. On a 100-dim dense test problem (du = A*u + 150 .* sin.(u) .- p), 74 of 100 entries offuchange in the last bits afterjac_cache(u0). The Jacobian itself is bitwise identical. So after each Jacobian evaluation, the residual used by the Newton step and by the termination check silently became the AD primal.This PR passes the cache's existing private
fu_cacheinstead.fu_cacheis already allocated byconstruct_jacobian_cachefor DI preparation, so no buffer is added. The diff is one line inlib/NonlinearSolveBase/src/jacobian.jl, plus a test.This is also the prerequisite for the follow-up PR that reuses the init-time Jacobian on the first Newton step. That PR can only be bitwise identical to its base if a Jacobian evaluation no longer has this side effect.
Behavior change: in-place AD iterates change at roundoff level
In-place problems with an AD Jacobian now step from the plain residual instead of the AD primal, so their iterates change at roundoff level. I compared master and this branch on 98 solver/problem configurations:
jac, sparse 1000 with ajac_prototypeand with a sparsity detector, SVector{4}, scalar.alias_u0 = true.step!loop, andsolve!afterreinit!with a new u0/p, a new p, and the original values.87 of 98 configurations are bitwise identical in every iterate, residual, retcode and stat. That includes all OOP, SVector, scalar, sparse, user-
jacand matrix-free cases. The 11 that differ are all dense in-place ForwardDiff cases:The last row is a solve that diverges on both master and this branch: on master its iterates reach 1e259 before MaxIters. A roundoff-level change alters how it fails. No converging case changed retcode or step count.
Cost
The buffer already existed, so there is no new allocation. Pinned with
taskset, dense 100 IIP,solve(prob, alg):Verification
New test,
lib/NonlinearSolveBase/test/jacobian_private_fu.jl: afterjac_cache(u), the residual array equals a plainf!(fu, u, p)call bitwise. It also checks the Jacobian against the analytic one.Failing before the fix (origin/master
0055e314):Passing after:
Full suites on this branch (Julia 1.12):
Runic (
Runic --check) andtyposare clean on the changed files.Not verified
yor now write it into a private buffer, so they can only become more consistent.Risk assessment
JacobianCachefor in-place problems with an AD Jacobian (dense and sparse) in every solver built onconstruct_jacobian_cache. No public API change. Iterates of in-place AD solves change at roundoff level, as tabulated above.🤖 Generated with Claude Code (model: claude-opus-5-5) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Independent review: Devin Fusion (fusion-claude-opus-5-5-high-sidekick-swe-2-medium) rated it low, verdict MERGE: #1365 (comment)
Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 2b55d35)
Merged current upstream master normally, preserving the private Jacobian residual workspace change. This includes the existing upstream fix for Julia 1.10 polyalgorithm
solve!inference: the dynamically selected subcache's return code is asserted asReturnCode.T.Both reported LTS failures match the historical master failures, rather than a regression from this PR. Latest master passes both Ubuntu and macOS LTS Core jobs. The upstream fix is #1347. No new solver implementation changes or test relaxations were made.
Local verification
Julia tests used the juliaup launcher with
+lts(Julia 1.10.12), four Julia threads, one OpenBLAS thread,JULIA_PKG_PRECOMPILE_AUTO=0, andJULIA_NUM_PRECOMPILE_TASKS=1. All local monorepo dependencies were developed into the local environment. Each test command had an external 3600-second timeout.Existing inference regression on a clean export of the pre-merge PR head:
timeout 3600 julia +lts --project -e 'using Test; @testset "LTS polyalgorithm inference" begin; include("test/Core/core_tests__item3.jl"); end'Exit 1:
The same inference file, plus this PR's Jacobian regression, on the merged tree:
timeout 3600 julia +lts --project -e 'using Test; @testset "LTS polyalgorithm inference" begin; include("test/Core/core_tests__item3.jl"); end; @testset "Private Jacobian residual" begin; include("lib/NonlinearSolveBase/test/jacobian_private_fu.jl"); end'Exit 0:
Full root Core group:
GROUP=Core timeout 3600 julia +lts --project -e 'using Pkg; Pkg.test()'Exit 0, excerpts:
Full root QA group:
GROUP=QA timeout 3600 julia +lts --project -e 'using Pkg; Pkg.test()'Exit 0:
Formatting and spelling on the merge's changed files:
All exited 0 with no diagnostics; the working tree stayed clean. The original PR's Jacobian regression file was also formatted and spell-checked successfully.
Not locally verified: macOS, other Julia versions, the other root groups, complete sublibrary groups, GPU/downstream integrations, or a docs build. No documentation or public API was added by this fix. New-head CI was not awaited.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__NonlinearSolve.jl__1365 (no session URL)
Fix by Muse CLI Code muse-wonder-full-1.0 (head f33569d)
What changed:
lib/NonlinearSolveHomotopyContinuation/Project.tomlfrom0.3.1to0.3.6(commit f33569d). No solver code changed; the private Jacobian residual buffer change under review is untouched.Why: the two base-green failures routed for this PR (NonlinearSolveHomotopyContinuation Core and QA on Julia 1) both failed while precompiling TaylorDiff 0.3.5, before any test in this repository ran:
That failure is external to the Jacobian change in this PR. I reproduced it in a scratch environment containing only TaylorDiff 0.3.5 (no code from this repository), where
using TaylorDiffexits 1 with the same stacktrace, and in the same kind of scratch environment with TaylorDiff 0.3.6 it exits 0. TaylorDiff 0.3.6 drops its Symbolics dependency. The base run used for comparison passed on 2026-11-03 with the registry state of that day; the PR run on 2026-11-08 resolved the broken TaylorDiff 0.3.5 combination. Raising the floor makes the broken version unselectable, including for the downgrade lane, which also failed with the same TaylorDiff precompile error.Validation
All Julia commands ran with
JULIA_NUM_THREADS=4 JULIA_NUM_PRECOMPILE_TASKS=4and an external 3600-second timeout, on Julia 1.13.2.TaylorDiff alone, before and after (scratch environments, no repository code):
HomotopyContinuation QA after the change:
GROUP=QA julia --project=lib/NonlinearSolveHomotopyContinuation -e 'using Pkg; Pkg.test()'(The one broken entry is the pre-existing
aqua_broken = (:persistent_tasks,)allowance already present in the QA file.)HomotopyContinuation Core after the change:
GROUP=Core julia --project=lib/NonlinearSolveHomotopyContinuation -e 'using Pkg; Pkg.test()'Both groups resolved
TaylorDiff v0.3.6. Core also passed before this commit with the registry state of 2026-11-12 (which already resolves 0.3.6); the compat floor is what excludes the broken 0.3.5 combination that CI hit.NonlinearSolveBase Core after the change (covers the Jacobian regression test added by this PR):
GROUP=Core julia --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test()'Formatting and spelling:
julia --project=@runic -m Runic --checkon the three Julia files changed by this PR exits 0 (the only file changed by this fix is a Project.toml, which Runic does not format), andtypos lib/NonlinearSolveHomotopyContinuation/Project.tomlexits 0.CI on head f33569d, checked once after pushing: NonlinearSolveHomotopyContinuation Core (Julia 1 and LTS), QA, and the HomotopyContinuation downgrade job all pass. The SCCNonlinearSolve Core and CUDA jobs still fail;
rack ci compareclassed both as pre-existing before this fix, and this change does not touch those code paths. Several macOS jobs were still pending at the single check after pushing; I did not wait for the full suite.Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
🤖 Posted by an AI agent — harness: Muse CLI Code · model: muse-wonder-full-1.0
Conversation: local fixer job SciML__NonlinearSolve.jl__1365 (no session URL)