Repository navigation
Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint - #1275
Merged
ChrisRackauckas merged 5 commits intoSep 13, 2026
Merged
Conversation
Zygote/Mooncake/Enzyme through solve(::NonlinearLeastSquaresProblem) previously hit SciMLBase's AdjointNotFoundError: the solve_up rrule routes to _concrete_solve_adjoint, and no dispatch existed for NLLS (SciMLSensitivity's ConcreteNonlinearProblem union excludes it). The adjoint differentiates the projected stationarity equation G(u,p) = u − Π(u − ∇φ) rather than the residual system — the residual is rectangular and need not vanish at active bounds. This is the reverse-mode counterpart of the ForwardDiff fix from SciML#1271 and shares its assumptions: parameter-independent bounds, locally unchanged active set, nonsingular stationarity Jacobian on the free variables. Components pinned at an active bound get zero sensitivity; free components solve J_u' λ = Δu and accumulate dp = −J_p' λ. The primal is re-solved via solve_call on the already-concrete problem so the returned NonlinearSolution's prob.f.f stays unwrapped on the Enzyme originator path, matching the rule's declared primal type (the traced forward solve skips AutoSpecializeCallable wrapping inside within_autodiff, but the wrap would otherwise re-run inside the rule). SteadyStateAdjoint is the only supported sensealg; other sensitivity algorithms throw an explanatory ArgumentError. Scalar/array states and parameters, rectangular residuals, analytic jac/vjp callbacks, and save_idxs are covered by the new Adjoint-group test, which compares ForwardDiff against Zygote, Enzyme, and Mooncake. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript; earlier Codex CLI 0.154.0 / gpt-6-astra session at /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl)
Concrete-solve adjoint dispatches live in SciMLSensitivity (its ConcreteNonlinearProblem dispatch covers NonlinearProblem et al.), so the reverse-mode hook moves to a SciMLSensitivityNonlinearSolveBaseExt extension there. NonlinearSolveBase keeps the shared machinery the dispatch calls: nlls_solve_adjoint_dp (projected-stationarity adjoint) and implicit_sensitivity_solve (shared with the ForwardDiff path). The regression test moves to SciMLSensitivity's suite alongside the other nonlinear-solve adjoint tests. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript)
SciMLSensitivity's NLLS adjoint dispatch sets its NonlinearSolveBase compat floor to 2.49.6 — the first release containing nlls_solve_adjoint_dp and implicit_sensitivity_solve. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript)
SciMLSensitivity's NLLS adjoint dispatch calls both, and ExplicitImports requires cross-package accesses to be public. solve_call gains a docstring since it is now developer-facing API. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript)
Resolve the 2.50.0 version renumbering (SciML#1276) and the initialization_alg public declaration: keep upstream's get_concrete_problem/initialization_alg line, add solve_call and nlls_solve_adjoint_dp, and bump to 2.50.1 as the release floor for the SciMLSensitivity compat bound. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript)
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 13, 2026
- Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint (#1275) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Sep 13, 2026
The compat floor resolves now that SciML/NonlinearSolve.jl#1275 merged and NonlinearSolveBase v2.51.0 landed in General (#168172). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript)
ChrisRackauckas
added a commit
to SciML/SciMLSensitivity.jl
that referenced
this pull request
Sep 13, 2026
* Add SteadyStateAdjoint dispatch for NonlinearLeastSquaresProblem Zygote/Mooncake/Enzyme through solve(::NonlinearLeastSquaresProblem) currently hit the generic _concrete_solve_adjoint fallback: SciMLSensitivity's ConcreteNonlinearProblem union covers NonlinearProblem et al. but not NLLS. The new dispatch differentiates the projected stationarity equation G(u,p) = u - Π(u - ∇φ) rather than the residual system — the residual is rectangular and need not vanish at active bounds. Pinned components get zero sensitivity; free components solve J_u' λ = Δu and accumulate dp = -J_p' λ. This is the reverse-mode counterpart of the ForwardDiff bounded-sensitivity fix in NonlinearSolve.jl#1271, and shares its assumptions: parameter-independent bounds, locally unchanged active set, nonsingular stationarity Jacobian on the free variables. The adjoint solve lives in NonlinearSolveBase.nlls_solve_adjoint_dp, which shares the nlls_generate_vjp_function machinery with the ForwardDiff path; the primal is re-solved via NonlinearSolveBase.solve_call on the already-concrete problem so the returned NonlinearSolution's prob.f.f stays unwrapped on the Enzyme originator path (the traced forward solve uses the raw callable, and re-wrapping in the inner solve would make the solution type disagree with the rule's declared primal type). SteadyStateAdjoint is the only supported sensealg; other sensitivity algorithms throw an explanatory ArgumentError, and structured parameters currently raise a clear error rather than mis-differentiating. Scalar and array states/parameters, rectangular residuals, analytic jac/vjp callbacks, and save_idxs are covered by the new Core8 test, which compares ForwardDiff against Zygote, Enzyme, and Mooncake. Requires NonlinearSolveBase >= 2.49.6 (nlls_solve_adjoint_dp, implicit_sensitivity_solve, and the public solve_call declaration land in SciML/NonlinearSolve.jl#1275, which must merge and release first). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript) * Require NonlinearSolveBase 2.50.1 Upstream renumbered the library versions (NonlinearSolve.jl#1276), so the release containing nlls_solve_adjoint_dp and the public solve_call declaration will be 2.50.1 rather than 2.49.6. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript) * Re-trigger CI: NonlinearSolveBase 2.51.0 is registered The compat floor resolves now that SciML/NonlinearSolve.jl#1275 merged and NonlinearSolveBase v2.51.0 landed in General (#168172). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.21 Agent-Model: SWE-2 Max Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript) --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 14, 2026
- Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint (#1275) - Release NonlinearSolveBase 2.51.0 (#1277) - Make SobolMultistart the default bounded solver (stall recovery, #1147) (#1278) - Bump actions/upload-artifact from 4 to 7 (#1279) - Bump julia-actions/cache from 2 to 3 (#1281) - Bump actions/checkout from 6 to 7 (#1282) - Bump julia-actions/setup-julia from 2 to 3 (#1280) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 14, 2026
- Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint (#1275) - Release NonlinearSolveBase 2.51.0 (#1277) - Make SobolMultistart the default bounded solver (stall recovery, #1147) (#1278) - Bump actions/upload-artifact from 4 to 7 (#1279) - Bump julia-actions/cache from 2 to 3 (#1281) - Bump actions/checkout from 6 to 7 (#1282) - Bump julia-actions/setup-julia from 2 to 3 (#1280) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This was referenced Sep 26, 2026
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.
Summary
Companion PR to SciML/SciMLSensitivity.jl#1664, which adds the
SciMLBase._concrete_solve_adjointdispatch forNonlinearLeastSquaresProblem. This PR provides the NonlinearSolveBase machinery that dispatch calls — the problem-side math stays next to the residual/VJP internals it composes with.Contents:
nlls_solve_adjoint_dp(new,src/autodiff.jl): parameter cotangentdp = −(∂G/∂p)' · (∂G/∂u)⁻ᵀ · Δufor the projected stationarity equationG(u,p) = u − Π(u − ∇φ)— the reverse-mode counterpart of the ForwardDiff bounded-sensitivity fix in Respect active bounds in ForwardDiff least-squares sensitivities #1271. Active-bound components get zero sensitivity; supports scalar/array states and parameters, rectangular residuals, analyticjac/vjpcallbacks, andsave_idxsscatter.∂G/∂uand∂G/∂pare computed through DifferentiationInterface, preferringAutoForwardDiffsince it composes cleanly with the nested derivativenlls_generate_gradient_functionperforms internally.implicit_sensitivity_solve(new,src/autodiff.jl): the LinearSolve-backed implicit solve, hoisted from the ForwardDiff extension so the forward and reverse paths share it._forwarddiff_implicit_solvenow delegates to it (no behavior change).solve_callandnlls_solve_adjoint_dpdeclaredpublic(NonlinearSolveBase.jl,public.jl): SciMLSensitivity calls both across the package boundary and ExplicitImports'all_qualified_accesses_are_publiccheck requires it.solve_callgains a docstring as new developer-facing API.The dispatch itself moved to SciMLSensitivity because all concrete-solve adjoints live there (its
ConcreteNonlinearProblemmethods coverNonlinearProblem/ImmutableNonlinearProblem/SteadyStateProblem), keeping the standard "load SciMLSensitivity for adjoints" contract consistent across problem types.Test plan
The end-to-end coverage lives in SciMLSensitivity's suite (
test/Core8/nlls_adjoint.jlin #1664): bounded/unbounded NLLS adjoints compared across ForwardDiff, Zygote, Enzyme, and Mooncake — 69/69 pass locally against this branch dev'd into SciMLSensitivity's env, and 44/44 reverse-mode cases error with the genericAdjointNotFoundErrorfallback when the dispatch is absent (the test discriminates).In-repo regression checks:
test/Core/bounds_sensitivity_tests.jl(ForwardDiff sensitivity suite from Respect active bounds in ForwardDiff least-squares sensitivities #1271, exercises theimplicit_sensitivity_solverefactor): 42/42 passtest/Core/bounds_tests__item1.jl,bounds_tests__item2.jl: passtest/Adjoint/adjoint_tests__item1.jl–item3.jl(existing NonlinearProblem adjoints — Zygote/Tracker/ReverseDiff/Enzyme/Mooncake): passtest/qa/qa.jl): 14/14 pass, 9/9 extension-load assertions passrunicformatting applied to all changed files;typoscleanCore/Allgroups (root manifest predates Julia 1.12 and fails to instantiate), GPU/downstream groupsMerge order: this PR must merge and NonlinearSolveBase ≥2.50.1 release before SciML/SciMLSensitivity.jl#1664's CI can pass.
🤖 Generated with Devin CLI 3000.10.21 (model: SWE-2 Max)
Session: /home/crackauc/.local/share/devin/cli/summaries/history_036c03678c564696.md (local transcript; earlier Codex CLI 0.154.0 / gpt-6-astra session at /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl)