Repository navigation
Sweep drivers: consume jac/jac_prototype/sparsity/colorvec from the NonlinearFunction (#1020 item 2) - #1022
Merged
ChrisRackauckas merged 2 commits intoJul 10, 2026
Conversation
…onlinearFunction
HomotopySweep and SimpleHomotopySweep previously built
NonlinearFunction{iip}(FixLambda(prob.f, λ)), dropping every derivative
field of the user's NonlinearFunction: an analytic Jacobian was silently
ignored (the default polyalgorithm's must_use_jacobian never fired) and
sparse systems were differentiated dense at every Newton iteration of
every continuation step.
The drivers now forward these fields into the inner NonlinearFunction. A
user jac following HomotopyProblem's λ-extended convention jac(u, p, λ) /
jac(J, u, p, λ) is λ-fixed into the standard 2/3-argument form: in
HomotopySweep via FixLambdaJac, which reads λ from the residual's own
mutable FixLambda (one λ state, so residual and Jacobian cannot
desynchronize); in SimpleHomotopySweep via a second immutable
SimpleFixLambda built at the same site from the same λ value each step.
jac_prototype, sparsity, and colorvec pass through unchanged (the
prototype is not eltype-promoted with λ; documented in the docstrings).
Problems without derivative fields construct the inner function exactly
as before — the branch is decided by the problem's type, so the
StaticArray/scalar SimpleHomotopySweep path stays AllocCheck-clean, and
result plus residual-call count are byte-identical to master.
ArcLengthContinuation is intentionally untouched (needs the bordered
prototype; follow-up).
Part of SciML#1020 (Priority 2).
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas
marked this pull request as ready for review
July 10, 2026 07:25
ChrisRackauckas
added a commit
to SciML/SciMLBase.jl
that referenced
this pull request
Jul 10, 2026
…yProblem (#1430) HomotopyProblem documents that all functions of the wrapped NonlinearFunction follow the λ-extended argument convention (residual f(u, p, λ) / f(du, u, p, λ), jac jac(u, p, λ) / jac(J, u, p, λ)), and NonlinearSolve.jl's continuation solvers consume the derivative fields as of SciML/NonlinearSolve.jl#1022. But the NonlinearFunction constructor validated jac/jvp/vjp against the standard nonlinear arities, so a bare λ-extended jac was rejected at construction: NonconformingFunctionsError for a 3-argument out-of-place jac and TooManyArgumentsError for a 4-argument in-place jac. Users had to define a dummy λ-free method on their jac just to get past the check. Add a `lambda_extended` keyword (default `false`, not stored as a field) to the NonlinearFunction constructor that shifts the jac/jvp/vjp conformance arities by the one trailing λ argument, and shifts the residual in-place detection in the type-parameter-free constructor the same way. The standard checks are unchanged when the keyword is not passed, and nonconforming λ-extended functions are still rejected with the same errors. Also update the HomotopyProblem docstring: the derivative fields are now consumed by NonlinearSolve.jl's continuation solvers rather than "not consumed yet". Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
This was referenced Jul 10, 2026
ChrisRackauckas
added a commit
that referenced
this pull request
Jul 10, 2026
The typos spell-checker reads the "soop" (scalar/short oop) suffix in test/Core/homotopy_jac_tests__item1.jl (merged in #1022) as a misspelling, failing Spell Check on master and therefore on every open PR. Rename to short_oop. No behavior change; the file passes 30/30 locally. Co-authored-by: Claude <[email protected]> Co-authored-by: Chris Rackauckas <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/NonlinearSolve.jl
that referenced
this pull request
Jul 10, 2026
…ciML#1020 item 2 follow-up) The user's λ-extended `jac(u, p, λ)` / `jac(J, u, p, λ)` supplies only the n×n ∂H/∂u block, but the arclength driver differentiates two larger systems: the packed path system behind the `:tangent` predictor (the n×(n+1) augmented Jacobian [∂H/∂u | ∂H/∂λ]) and the (n+1)×(n+1) bordered corrector system with the θ-weighted Keller constraint row. ∂H/∂λ-column design: the missing column is a scalar-parameter derivative, so it is taken as ONE forward-mode derivative of the residual in λ at fixed u — a DifferentiationInterface `derivative` of the λ-shifted residual with (u, p) as `Constant` contexts, prepared once at solve start and reused every call — rather than differentiating the packed system wholesale. `AugmentedPathJac` assembles [user ∂H/∂u | ∂H/∂λ] under the standard 2/3-argument Jacobian convention, so the tangent predictor consumes it through `construct_jacobian_cache`'s ordinary `has_jac` path unchanged. The corrector's `AugmentedHomotopyJac` embeds the same path Jacobian as its top block and writes the constraint row analytically — it is the θ-weighted τ, read from the same in-place-updated τ buffer the per-step residual reads, so the Jacobian and the residual cannot desynchronize (`ds`/`xcur` do not enter: the constraint is affine in x, its gradient independent of both). Bordered prototype: `jac_prototype` / matrix `sparsity` are extended to the augmented shapes — one structurally dense ∂H/∂λ column for the predictor's n×(n+1) system, plus the structurally dense constraint row for the corrector's bordered (n+1)×(n+1) system. Sparse/structured prototypes are promoted to SparseMatrixCSC via the STRUCTURAL pattern (`Utils.structural_sparse`, new in the SparseArrays extension — `sparse(x)` would drop zero-valued band entries): a bordered Tridiagonal is no longer tridiagonal, and CSC is what the coloring and sparse-LU machinery handle; without SparseArrays loaded, structured prototypes fall back to a dense bordered prototype. A sparsity detector is forwarded unchanged (it detects the augmented pattern from the augmented residual itself). The user `colorvec` is extended by one fresh color for the predictor's dense λ column; it is not forwarded to the corrector, whose dense constraint row admits no nontrivial column coloring — the bordered pattern's value there is chiefly the sparse linear solve. The λ-fixed anchor/landing solves reuse the sweep's `_sweep_nonlinear_function` forwarding from SciML#1022. When no derivative fields are present, every construction is exactly the previous one (branches decided by the problem's type), verified by unchanged residual-eval counts against the base branch. Tests: test/Core/arclength_jac_tests__item1.jl (registered in the core group) covers analytic-jac consumption through the augmented corrector and through the tangent predictor on the S-fold problem (root to 1e-4, counters > 0, jac evaluations at interior λ prove the corrector consumed it), analytic-vs-AD solution agreement, the augmented/bordered prototype structure (zero-valued band survival, dense borders, CSC promotion), an n = 50 tridiagonal fold-free system solved with `:tangent` both with jac+prototype (asserting the corrector's Jacobian buffer is the bordered (n+1)×(n+1) SparseMatrixCSC) and with prototype+colorvec without an analytic jac, no-field construction type-identity, and no-field root/residual-count determinism. SparseArrays and SparseMatrixColorings are added to the root test target for the sparse assertions. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Jul 11, 2026
…1020 item 2 follow-up, stacked on #1021) (#1025) * ArcLengthContinuation: consume jac/jac_prototype/sparsity/colorvec (#1020 item 2 follow-up) The user's λ-extended `jac(u, p, λ)` / `jac(J, u, p, λ)` supplies only the n×n ∂H/∂u block, but the arclength driver differentiates two larger systems: the packed path system behind the `:tangent` predictor (the n×(n+1) augmented Jacobian [∂H/∂u | ∂H/∂λ]) and the (n+1)×(n+1) bordered corrector system with the θ-weighted Keller constraint row. ∂H/∂λ-column design: the missing column is a scalar-parameter derivative, so it is taken as ONE forward-mode derivative of the residual in λ at fixed u — a DifferentiationInterface `derivative` of the λ-shifted residual with (u, p) as `Constant` contexts, prepared once at solve start and reused every call — rather than differentiating the packed system wholesale. `AugmentedPathJac` assembles [user ∂H/∂u | ∂H/∂λ] under the standard 2/3-argument Jacobian convention, so the tangent predictor consumes it through `construct_jacobian_cache`'s ordinary `has_jac` path unchanged. The corrector's `AugmentedHomotopyJac` embeds the same path Jacobian as its top block and writes the constraint row analytically — it is the θ-weighted τ, read from the same in-place-updated τ buffer the per-step residual reads, so the Jacobian and the residual cannot desynchronize (`ds`/`xcur` do not enter: the constraint is affine in x, its gradient independent of both). Bordered prototype: `jac_prototype` / matrix `sparsity` are extended to the augmented shapes — one structurally dense ∂H/∂λ column for the predictor's n×(n+1) system, plus the structurally dense constraint row for the corrector's bordered (n+1)×(n+1) system. Sparse/structured prototypes are promoted to SparseMatrixCSC via the STRUCTURAL pattern (`Utils.structural_sparse`, new in the SparseArrays extension — `sparse(x)` would drop zero-valued band entries): a bordered Tridiagonal is no longer tridiagonal, and CSC is what the coloring and sparse-LU machinery handle; without SparseArrays loaded, structured prototypes fall back to a dense bordered prototype. A sparsity detector is forwarded unchanged (it detects the augmented pattern from the augmented residual itself). The user `colorvec` is extended by one fresh color for the predictor's dense λ column; it is not forwarded to the corrector, whose dense constraint row admits no nontrivial column coloring — the bordered pattern's value there is chiefly the sparse linear solve. The λ-fixed anchor/landing solves reuse the sweep's `_sweep_nonlinear_function` forwarding from #1022. When no derivative fields are present, every construction is exactly the previous one (branches decided by the problem's type), verified by unchanged residual-eval counts against the base branch. Tests: test/Core/arclength_jac_tests__item1.jl (registered in the core group) covers analytic-jac consumption through the augmented corrector and through the tangent predictor on the S-fold problem (root to 1e-4, counters > 0, jac evaluations at interior λ prove the corrector consumed it), analytic-vs-AD solution agreement, the augmented/bordered prototype structure (zero-valued band survival, dense borders, CSC promotion), an n = 50 tridiagonal fold-free system solved with `:tangent` both with jac+prototype (asserting the corrector's Jacobian buffer is the bordered (n+1)×(n+1) SparseMatrixCSC) and with prototype+colorvec without an analytic jac, no-field construction type-identity, and no-field root/residual-count determinism. SparseArrays and SparseMatrixColorings are added to the root test target for the sparse assertions. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]> * structural_sparse: correct the docstring premise, add the Diagonal regression it actually guards Empirically, sparse() on band-copying structured types (Tridiagonal, SymTridiagonal, Bidiagonal) preserves zero-valued structural entries — the docstring's Tridiagonal justification was wrong. The type where the plain conversion is value-based is Diagonal: sparse(Diagonal(zeros(n))) has zero stored entries, which would silently drop the pattern sparse AD coloring needs. Test the case that actually requires the helper. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Jul 11, 2026
… NonlinearSolve 4.20.4 (#1034) Registered versions (NLSB 2.33.0 on 2026-07-06) predate the merged homotopy work: #1021, #1022, #1024, #1025, #1028, #1029 (NLSB features => minor), #1028's tracking_abstol on SimpleHomotopySweep (=> minor), and #1027's SciMLBase 3.34 compat floor (top-level => patch). Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
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.
Important
This PR should be ignored until reviewed by @ChrisRackauckas.
Implements roadmap item Priority 2 of #1020 for the sweep drivers:
HomotopySweepandSimpleHomotopySweepnow consume the derivative fields of the problem'sNonlinearFunctioninstead of silently dropping them.What changed
Both drivers previously built
SciMLBase.NonlinearFunction{iip}(FixLambda(prob.f, λ)), discardingjac,jac_prototype,sparsity, andcolorvec— so a user's analytic Jacobian was ignored (the default polyalgorithm'smust_use_jacobiannever fired) and sparse systems were differentiated dense at every Newton iteration of every step.lib/NonlinearSolveBase/src/homotopy_sweep.jl(HomotopySweep): newFixLambdaJacwrapper λ-fixes the user'sjac(u, p, λ)/jac(J, u, p, λ)into the standard 2/3-argument form. It reads λ from the residual's own mutableFixLambdarather than carrying a copy, so advancing the sweep remains a single field write and the Jacobian can never be evaluated at a different λ than the residual (no second λ state to desynchronize).jac_prototype,sparsity, andcolorvecare forwarded unchanged.lib/SimpleNonlinearSolve/src/simple_homotopy_sweep.jl(SimpleHomotopySweep): the immutableSimpleFixLambdais rebuilt per step, so the jac wrapper is a secondSimpleFixLambda(f.jac, λfix)constructed at the same site from the sameλfixvalue — rebuilt together, they cannot desynchronize.NonlinearFunction{iip}(wrapper), positional only). The branch is decided by the problem's type, so the unused arm is compiled away and the StaticArray/scalarSimpleHomotopySweeppath stays AllocCheck-clean.NonlinearFunction{iip}governs both; the varargs wrappers serve either arity).jac_prototypeis forwarded unchanged — it is not eltype-promoted with λ. Users whose λ precision differs fromu0's should supply a prototype whose eltype matches the promoted residual eltype.HomotopySweepandSimpleHomotopySweepnow state the fields are consumed, mirroring theSciMLBase.HomotopyProblemdocstring's λ-extended-convention wording (which currently ends with "continuation solvers do not consume them yet" — that phrase can be updated in SciMLBase once this merges).Verified locally (all run, outputs observed)
test/Core/homotopy_jac_tests__item1.jl(registered intest/runtests.jl's core closure), covering: counting oop/iip analytic jacs consumed viaHomotopySweep(; inner = NewtonRaphson())and via the default polyalgorithm; analytic jac reproduces the AD solution to 1e-12;SimpleHomotopySweep(; inner = SimpleNewtonRaphson())consumes oop and iip analytic jacs (verified empirically — SimpleNonlinearSolve's Newton honorsf.jacthroughSciMLBase.has_jac); a 50-dim tridiagonal system withjac_prototype = Tridiagonal(...)where the inner solver'sJis asserted to be<: Tridiagonal; prototype-only (no analytic jac) passthrough; unit check that field-free problems produce the exact pre-change inner-function type; and a residual-count determinism check for field-free problems.HomotopyPolyAlgorithmmerge): new file +homotopy_sweep_tests__item1–21.jl+arclength_tests__item1–6.jl(190/190 pass) +homotopy_polyalg_tests__item1.jl(25/25 pass), all via@safetestseton this branch.HomotopySweepu=1.2599210498948732, 86 residual calls on master and on this branch;SimpleHomotopySweepu=1.2599210498948732, 73 calls on both — byte-identical behavior.NONLINEARSOLVE_TEST_GROUP=Core Pkg.test()fromlib/SimpleNonlinearSolve: pass (totals in CI log below).lib/SimpleNonlinearSolve/test/alloc/allocation_tests__item2.jlin its own env: 2/2 pass — the field-freeSimpleHomotopySweeppath is still AllocCheck-clean.--inplacethen--check(exit 0) on all touched files.Interface note (upstream wrinkle, not addressed here)
SciMLBase's
NonlinearFunctionconstructor arity-checksjacwith the standard nonlinear convention (isinplace(jac, 3, ...)), so a bare λ-extended jac (jac(u, p, λ)= 3 args oop,jac(J, u, p, λ)= 4 args iip) is rejected at user-side construction (NonconformingFunctionsError/TooManyArgumentsError) unless the jac also carries a λ-free method — MTK-style generated functions with dual dispatches pass naturally, and the tests use loud-error λ-free dummy methods. Relaxing that check forHomotopyProblemuse is a SciMLBase follow-up.Scope / coordination
arclength.jlis deliberately untouched: derivative-field support forArcLengthContinuation(which needs the bordered prototype[J_proto col; rowᵀ 1]) is a follow-up, and a sibling PR is working in that file.🤖 Generated with Claude Code