Repository navigation
Respect active bounds in ForwardDiff least-squares sensitivities - #1271
Merged
ChrisRackauckas merged 1 commit intoSep 13, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
Differentiate the projected stationarity equation so active and fixed variables have zero sensitivity while the coupled free variables use their constrained stationarity system. Preserve scalar states across derivative, Jacobian, and VJP callbacks, and exercise solve, cached solve, and parameter reinitialization. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.154.0 Agent-Model: gpt-6-astra Agent-Session: local transcript /home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl
ChrisRackauckas
marked this pull request as ready for review
September 13, 2026 13:34
This was referenced Sep 13, 2026
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 13, 2026
…mode adjoint (#1275) * Add reverse-mode adjoint for NonlinearLeastSquaresProblem 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 #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) * Move the NLLS _concrete_solve_adjoint dispatch to SciMLSensitivity 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) * Bump NonlinearSolveBase to 2.49.6 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) * Declare solve_call and nlls_solve_adjoint_dp public 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) --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
For
min (u-p)^2with0 ≤ u ≤ 1andp=2,BoundedTrustRegion()returnsu=1, but ForwardDiff currently reportsdu/dp=1instead of zero. Differentiate the projected stationarity equation in the shared least-squares sensitivity helper so active/fixed variables and coupled free variables satisfy the constrained system. Scalar-state sensitivities also preserve scalar shape and use a derivative instead of an array Jacobian.This covers direct
solveand cachedsolve!/reinit!, in-place and out-of-place residuals, nested AD and analytic Jacobian/VJP callbacks. The documented assumptions are parameter-independent bounds, a locally unchanged active set, and a nonsingular stationarity Jacobian on free variables; no derivative is claimed at active-set transitions.Verification
Julia 1.13.0, using
/home/crackauc/.juliaup/bin/julia +1.13.0 --compiled-modules=existing. No dependencies or package versions changed.The exact new regression file on the unfixed native solver introduction, ab11738:
The 16 assertion failures include active-bound derivatives of
1versus expected0; the 12 errors are unsupported scalarjacobian,vec, orreshapecalls. The native solver is absent from that commit's parent. Both relevant Base AD source files are identical between this introduction and current master, and the one-variable reproducer independently fails on clean current master withderivative = 1.0.The identical regression file with this fix:
Full local checks:
Runic, typos on changed files, and
git diff --checkpassed. GPU, downstream packages, LTS, and reverse-mode sensitivities were not verified.Please ignore this draft until reviewed by @ChrisRackauckas.
🤖 Generated with Codex CLI 0.154.0 (model: gpt-6-astra). Session: local transcript
/home/crackauc/.codex/sessions/2026/09/12/rollout-2026-09-12T04-30-15-01a094bd-179a-7972-97ec-36badb9448cd.jsonl.