Repository navigation
Make ADTypes the NLsolveJL autodiff interface, deprecate the Symbols - #1212
Merged
ChrisRackauckas merged 1 commit intoAug 29, 2026
Merged
Conversation
NLsolve 5.0.0 (NLSolversBase 8) accepts only ADTypes backends for `autodiff`, so `OnceDifferentiable(f!, u0, resid; autodiff = :central)` now throws a TypeError and the `Wrappers` group fails on master. `NLsolveJL` already accepted ADTypes; make that the interface. The default becomes `AutoFiniteDiff(; fdtype = Val(:central))`, which is what `:central` meant and also NLSolversBase 8's own default, and `:central`/`:forward` are normalized to ADTypes in the constructor with a `Base.depwarn`. `alg.autodiff` is therefore always an `AbstractADType`, and the extension passes it straight to NLsolve, which drives DifferentiationInterface with any backend. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.251 Agent-Model: claude-opus-5[1m] Agent-Session: https://claude.ai/code/session_01QTnjBBwmH4EMvxpEVNCqua
ChrisRackauckas-Claude
force-pushed
the
fix-nlsolve5-autodiff
branch
from
August 29, 2026 21:50
56d4612 to
f46ad94
Compare
ChrisRackauckas
marked this pull request as ready for review
August 29, 2026 22:00
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.
What / why
NLsolveJLdocumentedautodiffas ":central,:forward, or ADTypes". NLsolve 5.0.0 (NLSolversBase 8) switched its ownautodiffkeyword fromSymboltoADTypes.AbstractADType, soOnceDifferentiable(f!, u0, resid; autodiff = :central)now throws aTypeErrorand theWrappersgroup fails onmaster(https://github.com/SciML/NonlinearSolve.jl/actions/runs/33251921454).Rather than translate the Symbols at the call site, this makes ADTypes the interface, matching the rest of NonlinearSolve:
AutoFiniteDiff(; fdtype = Val(:central))— exactly what:centralmeant, and also NLSolversBase 8's own default, so numerics are unchanged.:central/:forwardare normalized toAutoFiniteDiff(; fdtype = Val(:central))/AutoForwardDiff()in the constructor, with aBase.depwarn. They keep working;alg.autodiffis now always anAbstractADType.isa Symbolbranches and passes the backend straight to NLsolve, which drives DifferentiationInterface generically.Non-breaking, so
4.28.1→4.29.0. Actually removing the Symbols is a5.0change.Why not just unify onto
construct_extension_jacThe obvious cleanup — delete the "let NLsolve do the AD" branch and always use
NonlinearSolveBase.construct_extension_jac, likeCMINPACKand friends — does not work. I tried it; it fails the existingforward_ad_tests__item1.jltwo ways:construct_extension_jacis broken for scalaru0(hands a bareRealtoDI.jacobian) and for non-vectoru0(feeds the flattenedutoprob.f, which still expects the original shape). Both are pre-existing and affect every wrapper — they are simply unreachable today because each wrapper short-circuits that path on its defaultautodiff. Filed separately with a standalone MWE: #1215. This PR routes around it;construct_extension_jacis still used when the problem suppliesjacorjac_prototype.Verification
GROUP=Wrappers julia --project -e 'using Pkg; Pkg.test()', Julia 1.12.4 linux, resolving NLsolve v5.0.1 / NLSolversBase v8.0.1.Before (unmodified
masterc498eaf):Pin evidence (
masterwith[compat] NLsolve = "4.5"restored inProject.tomlandtest/Wrappers/Project.toml, nothing else changed) — confirms NLsolve 5 is the trigger:After (this branch, NLsolve v5.0.1 / NLSolversBase v8.0.1):
Nonlinear Root Finding Problemsgoes 58 → 63:test/Wrappers/rootfind_tests__item2.jlnow runs the solve overAutoFiniteDiff(; fdtype = Val(:central)),AutoForwardDiff(),:centraland:forward, and asserts the Symbols normalize to the right backends. The discriminating tests are the pre-existing ones inforward_ad_tests__item1.jlandrootfind_tests__item2.jl; the latter never ran on CI because the group aborts after the first errored@safetestset.The deprecation path fires as intended:
Runic
--checkandtypospass on all changed files.Not verified
ltsandprechannels — CI covers these.src/extension_algs.jlandext/NonlinearSolveNLsolveExt.jl; nothing outsideNLsolveJLconstruction readsalg.autodiff.NLsolveJLdocstring changed, sodocs/make.jlis worth a look on CI.For a reviewer to push back on
autodiff = nothing(auto-select → ForwardDiff), which is faster but silently changes results for existingNLsolveJL()users. That belongs in a5.0, not here.construct_extension_jac. Previously an explicit ADType took theconstruct_extension_jacpath whenprob.f.jac === nothing. It now goes to NLsolve unlessjacorjac_prototypeis set. That is what dodges construct_extension_jac is broken for scalar and non-vector u0 with an explicit ADTypes backend #1215, and both are DI-backed, but it does mean ajac_prototype-less sparsity setup no longer gets NonlinearSolve's coloring — there was no such path exercised in the tests.4.29.0) on the grounds that Symbols still work. If the changed default representation counts as breaking for anyone pattern-matching onalg.autodiff, say so.🤖 Generated with Claude Code (model: claude-opus-5[1m])
https://claude.ai/code/session_01QTnjBBwmH4EMvxpEVNCqua