Skip to content

Use LinearSolve for ForwardDiff implicit sensitivities - #1055

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/forwarddiff-singular-implicit-derivative
Jul 15, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/forwarddiff-singular-implicit-derivative

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

This PR should be ignored until reviewed by @ChrisRackauckas.

Summary

Fixes #1054 by routing the ForwardDiff implicit sensitivity solve through NonlinearSolveBase's construct_linear_solver path when LinearSolve is loaded, instead of using raw Jᵤ \ Jₚ. This lets the AD-over-solve path use LinearSolve's singular-LU to pivoted-QR rescue for rank-deficient implicit systems.

The scalar Jᵤ case stays on Julia's native \ path because LinearSolve's generic matrix-RHS setup does not handle scalar A with matrix B here.

Tests

  • env JULIA_NUM_THREADS=1 JULIA_PKG_PRECOMPILE_AUTO=no JULIA_PKG_SERVER_REGISTRY_PREFERENCE=eager timeout 3600 julia +1 --startup-file=no --project=. -e 'using Test; include("test/Core/forward_ad_tests__item2.jl")'
  • Scalar smoke check: ForwardDiff.gradient(g, [4.0, 0.0]) = [0.25, 0.25]
  • Original BoundaryValueDiffEq nested FIRK reproducer against this branch: sol.retcode = SciMLBase.ReturnCode.Success, SciMLBase.successful_retcode(sol.retcode) = true
  • timeout 3600 julia +1 --startup-file=no --project=.runic_env -e 'using Runic; exit(Runic.main(["--check", "."]))'

NONLINEARSOLVE_TEST_GROUP=Core Pkg.test() currently fails on clean origin/master before reaching this ForwardDiff test file in 23 Test Problems: Broyden; a separate investigation has been spawned per repo instructions.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 15, 2026 06:16
@ChrisRackauckas
ChrisRackauckas merged commit 247a8bf into SciML:master Jul 15, 2026
62 of 74 checks passed
ChrisRackauckas added a commit to SciML/BoundaryValueDiffEq.jl that referenced this pull request Aug 31, 2026
The `LinearSolve = "4.2"` compat entry in the FIRK sublibrary Project.toml
caps the test environment at LinearSolve 4.x. Since NonlinearSolveBase
2.36.0 requires LinearSolve 5, this holds the test environment at
NonlinearSolveBase 2.35.0 -- the last release before
SciML/NonlinearSolve.jl#1055 routed the ForwardDiff implicit-sensitivity
solve through LinearSolve instead of a raw `Jᵤ \ Jₚ`. The nested FIRK
underconstrained solves then throw `LinearAlgebra.SingularException` out
of that backslash, which the LinearSolve default's LU-to-QR fallback
handles.

LinearSolve is an unused test dependency; the compat entry's only effect
is on resolution.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code 2.1.251
Agent-Model: claude-opus-5[1m]
Agent-Session: https://claude.ai/code/session_01GHa2ZK4kgnGknJBGoM2sV8
Claude-Session: https://claude.ai/code/session_01GHa2ZK4kgnGknJBGoM2sV8
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.

ForwardDiff over nested NLLS solve throws SingularException in implicit derivative

2 participants