Repository navigation
Improve HomotopySweep adaptive step control: success expansion, quality-gated growth, trust-monitored secant predictor - #967
Conversation
|
Two follow-up commits since the initial push:
For context when reading this PR's CI: master is currently red for unrelated, pre-existing reasons — Runic format-check failures on six sublibrary |
|
Pushed Root cause: the root test env's Verification: ran the full root Status of the remaining red checks on the previous run, none PR-caused:
|
Final CI status — all PR-relevant jobs greenGreen (caused by / exercising this PR's code):
Red, none caused by this PR:
Net: every job that compiles or tests this PR's changes is green. Remaining reds are pre-existing (#968 fixed in-PR, #969/#970/#971 filed) or self-hosted-runner infra. |
The root test env's [sources] table is ignored on Julia < 1.11, so the base-env Core group tested the registered NonlinearSolveBase (2.31.0) instead of this branch's 2.32.0, failing on lts with `UndefVarError: ArcLengthContinuation not defined`. Develop the in-repo paths first, as the sublibrary and dep-adding group paths already do. (Same fix as SciML#967; expect a trivial merge with whichever lands first.) Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
…ng loop Rebase and consolidation of the SciML#967 improvements onto current master (which gained the λspan[1] anchor in SciML#972 and the SciMLTesting test dispatch), plus the inner-solver cache reuse now possible after SciML#1008. Adaptive step control (the classic predictor-corrector success/failure heuristic, e.g. Timme 2021): - `expand_threshold` consecutive accepted steps grow dλ by `expand_factor`, capped at `max_step_factor` of the span; a rejected step still halves it. - Expansion is gated on a Deuflhard-style local error estimate (`expand_quality`): the secant prediction's error must be small relative to the recent solution movement, OR the corrector must have converged within 2 iterations (covers exponentially flattening paths where the relative measure stalls). This keeps the increment from ballooning right before a sharp turn, where an oversized step is rejected only after the inner solver exhausts its iterations. - `predictor = :secant` (default) warm-starts the corrector by linear extrapolation through the last two accepted points, trust-monitored with hysteresis: measured prediction error no better than half the trivial constant prediction — or any rejected step — falls back to the constant warm start until two consecutive accepted steps measure good quality again. `:constant` restores the previous warm-start behavior. Cache-reusing, non-allocating driver: - `FixLambda` is mutable: the wrapped inner function is built once and advancing λ is a field write. - The inner solver is `init`ed once and re-driven per step with `reinit!`/`solve!` (requires the SciML#1008 LinearSolveParameters fix), reusing its workspace instead of reconstructing the solver each step; the anchor solve is the cache's first `solve!`. - The sweep's own state (`u`, `u_prev`, warm-start and quality-gate scratch) lives in preallocated buffers: in-place extrapolation, `Utils.norm_op` norms without temporaries, and buffer-swap acceptance. Immutable / StaticArray / scalar `u` takes a compile-time non-mutating branch. The λspan[1] anchor, its retcode semantics, and the zero-width-span behavior from SciML#972 are preserved verbatim. `expand_factor = 1, predictor = :constant` reproduces the previous fixed-increment behavior. Verified locally (Julia 1.11): all 21 homotopy_sweep test items pass (94 assertions) — master's 1-17 (incl. the SciML#972 anchor tests and the aliasing test) plus new items 18-21 covering kwarg validation, growth + caps, secant corrector-work reduction, and regrowth after bisecting a hard region. Stats are per-solve under the reused cache (verified), so the corrector-cheap gate is unaffected. Whole-solve allocations: scalar default 68176 -> 51840 B; the few-step scalar SimpleNewtonRaphson case pays for the one-time cache init (23888 -> 29328 B), which amortizes over longer continuations — the loop is the regime this solver targets. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
42cd2ed to
a6478cf
Compare
|
Rebased onto current master as a single consolidated commit ( What the PR now contains:
Verification (local, Julia 1.11): all 21 homotopy_sweep items pass (94 assertions), including the aliasing test (item 7) against the cached path. Allocation honesty: whole-solve scalar default 68176 → 51840 B; the few-step scalar |
Note
This PR should be ignored until reviewed by @ChrisRackauckas.
Follow-up to #962 (cf. this comment): improves the adaptive algorithm in
HomotopySweep.What was there before
The adaptive logic was failure-only: a rejected step halved
dλand the increment never grew back, so one hard region permanently degraded the resolution of the rest of the sweep. Warm starts were zeroth-order (reuse previousu).What this adds
Three mechanisms from the predictor-corrector path-tracking literature, sized for a natural-parameter sweep whose corrector is a generic NonlinearSolve algorithm (no polynomial structure, no tangent/Jacobian access from the sweep itself):
Success expansion (the classic success/failure heuristic, e.g. Timme, Mixed precision path tracking for polynomial homotopy continuation, Adv. Comput. Math. 47 (2021)): after
expand_thresholdconsecutive accepted steps,dλgrows byexpand_factor(default ×2), capped atmax_step_factorof the span width.Quality-gated growth (a Deuflhard-style local error estimate): the known failure mode of the pure success/failure heuristic is expensive trial-and-error in hard regions (cf. Hao & Zheng 2020) — the step balloons on the easy stretch before a sharp turn, and each oversized rejection costs a full inner-solver iteration budget (measured: one rejection through the default polyalgorithm ≈ 600 residual evaluations). Expansion therefore additionally requires evidence of corrector headroom: either the secant prediction error is small relative to the recent solution movement (
expand_quality), or the corrector converged within 2 iterations (which covers exponentially flattening path tails, where the relative error measure stays at a constant mediocre value while the absolute corrections become negligible).Trust-monitored secant predictor: warm starts extrapolate linearly through the last two accepted points, so the corrector starts on the path tangent. Right after a sharp turn a stale tangent predicts far off the path, so the secant's measured prediction error is compared against the trivial constant prediction each accepted step, with hysteresis: two consecutive good measurements to (re-)engage, any bad measurement or rejected step to disengage and fall back to the constant warm start.
predictor = :constantrestores the old warm-start behavior.All defaults preserve the old semantics where it matters:
expand_factor = 1disables growth entirely,expand_quality = Infdisables the gate,adaptive = falsefixed-step mode is untouched.Measured behavior (local runs, Julia 1.11)
Sharp-turn path
u*(λ) = 2tanh(20(λ-1/2))with corrector residualx + 2sin(x)(spurious merit-stationary traps for warm-start error > ~2.09), default polyalgorithm,maxiters = 100:Smooth cubic path
u*(λ) = 1 + λ: secant predictor 36 evals vs 64 constant; easy sweeps finish in 5 steps instead of 11 (growth doubling to the cap).Tests
Four new test items (registered in
test/runtests.jl):max_step_factorcap binds, including over annsteps-derived initial step:constanton a linear pathexpand_factor = 1Local test results: all 18 homotopy sweep items pass (86 assertions), NonlinearSolveBase QA (Aqua + ExplicitImports) passes 14/14, Runic check clean. One pre-existing test (item7, aliasing) caught a real bug in an intermediate version of this PR — the θ measurement must not reuse the guess buffer the inner solver may have mutated in place — which is fixed and the test passes.
NonlinearSolveBasebumped 2.31.0 → 2.32.0.Possible follow-ups (out of scope here)
🤖 Generated with Claude Code