Repository navigation
Inner-algorithm retention for the homotopy continuation drivers (sticky polyalg rung + lazy reinit!) - #1036
Conversation
…cache; retain_best = true) When a polyalgorithm cache is reused across warm-started solves (init/reinit!/solve!), every reinit! restarted the ladder at start_index and eagerly reinitialized all subcaches — each of which evaluates the residual at the new u0 — so drivers like the homotopy continuation loops paid one residual call per rung per step plus a re-fail of every cheap rung below the winner. reinit!(cache; retain_best = true) (opt-in; plain reinit! is byte-for-byte the status quo) makes the next solve! start from the subalgorithm that produced the last recorded success: - Escalation is preserved: a failing sticky rung continues up the ladder. - A fully-failed pass wraps around to the skipped cheaper rungs, floored at the algorithm's own start_index (measured: wrapping to rung 1 made the failure path more expensive than the status quo on small systems whose ladder starts at Newton), so retention never attempts fewer rungs than a full ladder run and never attempts rungs start_index excludes. - Subcache reinitialization is lazy: only the starting rung is reinitialized up front; escalation freshens further rungs when it reaches them, cutting the per-reinit! residual cost from one call per rung to one per rung attempted. - Every 8th retained reinit! whose retained rung sits above start_index re-probes from start_index, so a cheap rung that failed once transiently is rediscovered instead of locked out forever. cache.best is now also recorded on the generated solve! path (previously only step! set it), which the retention start relies on. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
…ed tracking steps HomotopySweep and the ArcLengthContinuation corrector now call reinit_retaining! on their tracking reinit!s: a polyalgorithm inner (the default) resumes from the subalgorithm that won the previous solve instead of re-running the ladder from its start every step; non-polyalgorithm inners get a plain reinit! (no change). The cold anchor solve at λspan[1] (and arclength's λ-fixed anchor/landing solves) still runs the full ladder — that is where the winner is discovered. Residual calls on the post-SciML#1029 benchmark set (default inner, master → this branch, vs NewtonRaphson() inner): - P1 scalar monotone sweep: 150 → 94 (Newton 86) - P2 S-curve sweep cost-to-fail: 2506 → 2344 (Newton 746) - P2 S-curve arclength: 381 → 267 (Newton 188) - P3 n=50 coupled cubic sweep: 2295 → 1577 (Newton 1400) - P4 hard ramp sweep: 246 → 204 (Newton 123; the remaining gap is entirely the full-ladder anchor: interior overhead is zero) SimpleHomotopySweep is deliberately untouched: it reconstructs a fresh stack-allocated solve per step (no persistent inner cache) and defaults to SimpleNewtonRaphson, so there is nothing to retain. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
|
Local verification output (scratch env with all local packages New tests ( (The polyalg retention file has since grown the re-probe testset; it is included in the full run below.) Full branch check — every existing Benchmark reproduction scripts and raw numbers are in the PR body; the "master" column was measured on the same machine by disabling the drivers' retention hook (method override of |
Part of #1020; addresses the default-inner overhead found in the post-#1029 benchmarks.
Note: This PR should be ignored until reviewed by @ChrisRackauckas.
Problem
The homotopy continuation drivers (
HomotopySweep, theArcLengthContinuationcorrector) solve a sequence of warm-started problems through one persistent inner cache (init/reinit!/solve!). With the default inner (theFastShortcutNonlinearPolyalgladder), everyreinit!restarted the ladder atstart_indexand eagerly reinitialized all subcaches. That cost the drivers twice:n > 25(start_index = 1) every warm step re-failed Broyden/Klement before Newton succeeded again.reinit!cost: every subcachereinit!evaluates the residual at the newu0(Utils.reinit_common!), so each continuation step paid one residual call per ladder rung (6 for the default ladder) versus 1 for a bareNewtonRaphson()inner. For small systems the default ladder already starts at Newton (start_index = 3foru0_len ≤ 25), so this eager-reinit cost was the entire measured 2x overhead there — not ladder re-failing.Result on the post-#1029 benchmark set: the default inner cost ~1.6–2x a plain
NewtonRaphson()inner everywhere.Design
reinit!(cache; retain_best = true)on the polyalgorithm cache (opt-in)cache.best, now also set on thesolve!path). Aretain_best = truereinit!starts the nextsolve!from that index instead ofstart_index. Plainreinit!(the default) is the exact status-quo full restart, so no polyalg user outside the homotopy drivers sees any behavior change.start_index: when the retained start was paststart_indexand the top of the ladder fails too, the ladder wraps around to the skipped cheaper rungs before falling through to the lowest-residual selection — retention never tries fewer rungs than a full ladder run, and never tries rungs the algorithm's ownstart_indexexcludes.reinit!reinitializes only the starting subcache; escalation freshens each further subcache at the moment it is attempted. This reduces the per-stepreinit!cost from one residual call per rung to one per rung attempted (usually just the retained one) — this is what closes the gap on small systems.start_index, every 8th retainedreinit!starts one solve fromstart_indexagain, so a cheap rung that failed once transiently is rediscovered instead of locked out forever. Bounded cost: at most one status-quo-style ladder step per interval.Drivers arm it on tracking steps only
HomotopySweepand theArcLengthContinuationcorrector callreinit_retaining!(retaining for a polyalg cache, plainreinit!otherwise) on their warm-started trackingreinit!s. The cold anchor solve atλspan[1](and arclength's λ-fixed anchor/landing solves) still runs the full ladder — that is where the winner is discovered.SimpleHomotopySweepis untouched: it deliberately reconstructs a fresh stack-allocatedsolveper step (no persistent inner cache), and its default inner isSimpleNewtonRaphson, not a polyalgorithm, so there is nothing to retain there.Wrap-around decision (measured)
Three variants were measured on the benchmark set:
start_index = 3) suddenly attempted Broyden/Klement — rungs the status-quo ladder never runs — on every bisection retry at the fold.start_index(chosen): when the retained rung is the ladder'sstart_index(the common steady state), the failure path is exactly the status-quo ladder — the wrap only engages in the rare retained-past-start case, keeping the robustness of trying every rung of a full ladder run. Measured: P2 sweep cost-to-fail drops to 2344 (below the 2506 status quo, thanks to the lazy reinit), P2 arclength 291 → 267.Benchmarks (residual calls via
Refcounter, measured on this branch at its final state)P1 scalar monotone
(1-λ)(u-4) + λ(u²-4); P2 cubic S-curve foldu³-3u-(-3+6λ); P3 n=50 coupled cubic iip; P4 hard rampu³-1-7λfromu0=100:NewtonRaphson()(NR, TR)NewtonRaphson()inner (target was 10–20%), while staying fully adaptive; the static Newton-first ladder is matched or beaten on the success-path problems.Where a quasi-Newton rung genuinely wins (honest findings)
Two constructed n=100 problems (
start_index = 1):NewtonRaphson()u + 0.1λ sin(u) + 0.25u₊ − 1u − 1 + 0.05λ tanh(u) + 0.05λ u₊Klement()inner (1088) genuinely beatsNewtonRaphson()(1229) — quasi-Newton can win steady-state.Stage-level retention (follow-up)
Carrying the winning inner rung across the sweep → arclength handoff (stage-level retention in
HomotopyPolyAlgorithm) is deliberately not part of this PR: #1030 is churninghomotopy_polyalg.jl(warm handoff), so that follow-up should land after #1030 merges.Tests
test/Core/polyalg_retention_tests__item1.jl: sticky start picks the winning rung on the next solve (asserted via subsolvernstepsand exact residual-call counts of the lazy reinit), escalation past a failing sticky rung, wrap-around rescuing via a skipped cheaper rung, wrap-around refusing to go belowstart_index, the periodic re-probe rediscovering a cheaper rung, andretain_best = false⇒ exact status-quo behavior (eager reinit of every subcache, ladder restart atstart_index).test/Core/homotopy_retention_tests__item1.jl: residual-call reduction on the benchmark problems with generous margins (each margin trips on master's numbers), anchor still runs the full ladder (an anchor that requires escalation), and a difficulty-jump path where the retained Jacobian-based rung hard-fails mid-continuation and escalation must rescue the sweep.All existing homotopy sweep/arclength/effort/tolerance/jac tests, the homotopy polyalg tests, the core polyalg/reinit!/cache/issue tests, and NonlinearSolveBase's polyalg solution-type tests pass locally (output in the PR conversation).
🤖 Generated with Claude Code