Repository navigation
ArcLengthContinuation: bordered tangent solve + θ-weighted arclength metric (#1020 item 3, Priorities 3+4) - #1021
Conversation
…metric Implements Priorities 3+4 of the homotopy roadmap (SciML#1020) as one change, since they share the same semantic break in the arclength metric. Part A: the :tangent predictor's path tangent is now computed by the bordered linear solve [J; wᵀ] t = e_{n+1} (one LU factorization, w = the θ-weighted previous tangent, i.e. J t = 0 normalized by ⟨τ_prev, t⟩_θ = 1; BifurcationKit's Bordered tangent / Govaerts bordering) instead of the dense SVD of nullspace(J). Measured 11.2x faster at n = 200 and 8.7x at n = 800 on random augmented Jacobians, and works verbatim with sparse Jacobians (nullspace throws for sparse input). The SVD null space is kept as a fallback that engages only when the bordered matrix is (near-)singular — τ_prev θ-orthogonal to the tangent (e.g. the pure-λ first-step seed meeting a fold head-on) or a genuine branch point — and never runs on the happy path. Part B: the Keller constraint row, tangent/secant normalization, orientation sign, chord length, and bend-angle test all now use the BifurcationKit DotTheta metric ⟨(u₁,λ₁),(u₂,λ₂)⟩_θ = (θ/n)⟨u₁,u₂⟩ + (1−θ)λ₁λ₂ (new `theta` kwarg, default 0.5, validated 0 < θ < 1) instead of the unweighted Euclidean dot on [u; λ], whose u-block swamps λ at large n. The 1/n normalization makes the balance size-independent. This changes what ds-valued options (initial_step_factor, min_ds, max_step_factor) and max_angle mean numerically; documented in a metric admonition in the docstring. The weighted dot is view-based, so ForwardDiff duals pass through the constraint row and Float32 stays Float32. All existing arclength (items 1-6) and homotopy-sweep (items 1-21) test files pass unmodified; new arclength_tests__item7.jl covers the bordered tangent on known Jacobians (including the vertical-in-λ fold tangent), the SVD fallback unit-level and end-to-end, theta validation and root regressions, an n = 50 system, and Float32 eltype preservation. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
Per review, the tangent path allocated per predictor step instead of reusing memory: the weighted border row (`similar`), the bordered matrix (`vcat`), the rhs (`zeros`), the LU factorization (which copies B again), the solution (`\`), and the normalized copy (`./`) — about 2(n+1)² + several (n+1) vectors per step. Now `B` and `t` are scratch buffers allocated once in solve and reused: the border row is written directly into B's last row, `lu!` factorizes in place (its internal pivot vector is the only remaining happy-path allocation), `ldiv!` solves into `t`, and normalization and orientation are in place; the result is `copyto!`d into the driver's stable τ buffer (safe: τprev is only read before the copy). The secant branch's per-step chord temporaries reuse the same scratch. J (the Jacobian cache's buffer) is never destroyed — B holds the copy — so the SVD fallback still reads it. Measured (n = 200 coupled system, whole solve): tangent 75196 -> 72316 KiB, the delta matching the eliminated per-step bordered-matrix/LU copies; S-fold roots identical for both predictors. The remaining bulk is the corrector-side per-step rebuild, which is roadmap SciML#1020 Priority 6, not this PR. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
2e4f1fb to
0e03150
Compare
|
Both review items addressed, and the branch is rebased for merge ( Allocations in the solve — confirmed and fixedThe bordered-tangent path did allocate per predictor step rather than reusing memory: the weighted border row (
Measured (n = 200 coupled system, whole solve): tangent 75196 → 72316 KiB, the delta matching exactly the eliminated per-step matrix/LU copies; S-fold roots identical for both predictors. The remaining bulk of arclength's solve allocation is the corrector-side per-step rebuild (fresh augmented problem + inner solve each step) — that predates this PR and is roadmap #1020 Priority 6, kept separate. RebaseRebased onto master with #1022 and #1024 now merged — four conflicts resolved as kwarg/registration unions (the constructor now carries both Verified on the exact pushed code (Julia 1.11): homotopy_sweep items 1–21 + arclength items 1–7 + jac + effort 1–2 + polyalg — 268 assertions in the main battery + 34 in the updated arc7 (which unit-tests the in-place bordered solve, the SVD fallback, and the θ metric) — all pass; Runic clean. |
Per review, the tangent's bordered solve now runs through
`construct_linear_solver` — the same LinearSolve.jl-backed cache the Newton
descent methods use — instead of raw lu!/ldiv!: the cache is built once per
solve and re-driven each step (`lincache(; A, b, linu)`), giving backend
selection, factorization-workspace reuse, and shared NLStats accounting
(one stats object now spans the tangent's Jacobian cache and linear cache).
ArcLengthContinuation gains the standard `linsolve` kwarg, forwarded to both
the bordered solve and construct_jacobian_cache. When the LinearSolve
extension is not loaded (NonlinearSolveBase only weak-depends on it) the
workspace falls back to the \\-backed native cache; the ext now defines
`Utils.is_extension_loaded(::Val{:LinearSolve})` so that is detectable.
Subtlety this surfaced: LinearSolve's default solver rescues a singular LU
with pivoted QR and returns a finite least-squares pseudo-solution marked
successful, which silently defeated the designed-singular -> SVD-fallback
routing (caught by the item7 fold-at-start test: the tracker got a bogus
pure-λ tangent). Acceptance is now gated on a backend-agnostic residual
check (Govaerts-style): ‖[J t; ⟨w,t⟩ − 1]‖ must be at rounding level, and it
is computed from `J` and `τprev` — not `B`, which the factorization may
destroy.
Verified (Julia 1.11): full battery (sweep 1-21, arclength 1-7 incl. the new
`linsolve = QRFactorization()` coverage and the restored SVD-fallback unit
tests, jac, effort 1-2, polyalg) 298/298; Runic clean.
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
|
Per review, pushed
Verified on the pushed code (Julia 1.11): full battery — sweep items 1–21, arclength 1–7 (incl. the restored SVD-fallback unit tests + the |
Spell Check reads `bord!` as a misspelling; rename the item7 unit-test helper to `unit_tangent!`. No behavior change; item7 passes 36/36 locally. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
…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]>
… 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]>
Important
This PR should be ignored until it has been reviewed by @ChrisRackauckas. Draft, not ready for merge.
Implements roadmap item 3 of the top-3 recommendation in #1020: Priority 3 (bordered linear solve for the arclength tangent) and Priority 4 (θ-weighted arclength metric), shipped together as one "arclength at scale" change since they share the same semantic break.
Part A — bordered tangent solve replacing
nullspace(Priority 3)_arclength_tangentcomputed the path tangent of the:tangentpredictor asLinearAlgebra.nullspace(J): a dense SVD — O(n³) with a large constant, allocating, and erroring for sparseJ. It is replaced by the standard bordered solve (BifurcationKitBorderedtangent; Govaerts 1991 block elimination):i.e.
J t = 0with the normalization⟨τ_prev, t⟩_θ = 1, via one LU factorization, then θ-normalized and oriented bysign(⟨t, τ_prev⟩_θ). The previous tangentτ_prevwas already threaded through the driver as the orientation reference (the pure-λ seed provides the first bordering row), so no new state is needed.SVD fallback kept, never on the happy path: the bordered matrix is singular exactly when
τ_previs θ-orthogonal to the true tangent (e.g. the pure-λ first-step seed meeting a fold head-on) or at a branch point wherenull(J)is 2-dimensional — the case for which BifurcationKit refuses the bordered tangent. A failed (issuccess(lu(B; check = false)) == false) or non-finite bordered solve falls back tonullspace(Matrix(J)), which stays robust there.Reproduced timing (this machine, random n×(n+1) augmented Jacobians, 5-run averages, matching the issue's benchmark protocol; issue measured 11–17×):
The bordered path also works verbatim with sparse Jacobians / any LU-capable backend, unlocking sparse
:tangentmode (nullspacethrows for sparse input).Part B — θ-weighted arclength metric (Priority 4) — semantic change
Every place the path metric appeared — the Keller constraint row in
AugmentedHomotopy, tangent/secant normalization, orientation sign, realized chord length, and the bend-anglecosang— used the unweighted Euclidean dot on[u; λ], so for largenthe state block swamps the single λ component. All of them now consistently use the BifurcationKitDotThetaconvention:with a new
thetakwarg onArcLengthContinuation(default0.5, validated0 < θ < 1). The1/nnormalization is the crucial automatic default: it makes the u-block/λ balance independent of system size.The weighted dot is written on views (no allocation, no eltype forcing), so ForwardDiff duals pass through the constraint row and Float32 problems stay Float32 (tested).
Tests
New
test/Core/arclength_tests__item7.jl(registered in the core closure after item 6):_bordered_tangenton known 1×2 Jacobians:Jτ = 0, θ-unit normalization, orientation, agreement with the analytic null direction at a regular point, and the ~vertical-in-λ tangent at the fold ofu³ − 3u = −3 + 6λ;τ_prevθ-orthogonal to the tangent), unit-level and end-to-end (fold exactly at the start point onu² = λwith:tangent);thetavalidation throws on0,1,-0.5,1.5; default andθ = 0.8land on the previous roots of the S-fold and monotone standard problems (values, not step counts);:tangent(exercises the 1/n-scaled metric + bordered solve at moderate n);:tangentpreserves eltype.All existing arclength (items 1–6) and homotopy-sweep (items 1–21) test files pass locally unmodified — no recalibration was needed: at n = 1 (most existing tests) θ = 0.5 scales the metric uniformly by √0.5, which changes effective step sizes but no test asserted absolute step geometry; all assertions are on final roots, retcodes, and qualitative path behavior (fold rounding), which are unchanged.
Fixes part of #1020.
🤖 Generated with Claude Code