Skip to content

Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint - #1275

Merged
ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:nlls-reverse-adjoint
Sep 13, 2026
Merged

ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:nlls-reverse-adjoint

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Companion PR to SciML/SciMLSensitivity.jl#1664, which adds the SciMLBase._concrete_solve_adjoint dispatch for NonlinearLeastSquaresProblem. 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 cotangent dp = −(∂G/∂p)' · (∂G/∂u)⁻ᵀ · Δu for the projected stationarity equation G(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, analytic jac/vjp callbacks, and save_idxs scatter. ∂G/∂u and ∂G/∂p are computed through DifferentiationInterface, preferring AutoForwardDiff since it composes cleanly with the nested derivative nlls_generate_gradient_function performs 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_solve now delegates to it (no behavior change).
  • solve_call and nlls_solve_adjoint_dp declared public (NonlinearSolveBase.jl, public.jl): SciMLSensitivity calls both across the package boundary and ExplicitImports' all_qualified_accesses_are_public check requires it. solve_call gains a docstring as new developer-facing API.
  • Version bump to 2.50.1: SciMLSensitivity's compat floor for the new dispatch — the release containing this PR is the first with the helpers.

The dispatch itself moved to SciMLSensitivity because all concrete-solve adjoints live there (its ConcreteNonlinearProblem methods cover NonlinearProblem/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.jl in #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 generic AdjointNotFoundError fallback 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 the implicit_sensitivity_solve refactor): 42/42 pass
  • test/Core/bounds_tests__item1.jl, bounds_tests__item2.jl: pass
  • test/Adjoint/adjoint_tests__item1.jl–item3.jl (existing NonlinearProblem adjoints — Zygote/Tracker/ReverseDiff/Enzyme/Mooncake): pass
  • QA group (test/qa/qa.jl): 14/14 pass, 9/9 extension-load assertions pass
  • runic formatting applied to all changed files; typos clean
  • Not run locally: full Core/All groups (root manifest predates Julia 1.12 and fails to instantiate), GPU/downstream groups

Merge 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)

ChrisRackauckas and others added 4 commits September 13, 2026 12:16
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)
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title Add reverse-mode adjoint for NonlinearLeastSquaresProblem Add shared NLLS sensitivity helpers for the SciMLSensitivity reverse-mode adjoint Sep 13, 2026
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
ChrisRackauckas merged commit e2a9ef0 into SciML:master Sep 13, 2026
26 of 28 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants