Repository navigation
Homotopy drivers: tracking_maxiters cap, effort-band step control, maxsteps guard (#1020 Priority 1) - #1024
Conversation
…xsteps guard Implements roadmap item 1 (Priority 1 + folded-in small fix 1) of SciML#1020 across HomotopySweep, ArcLengthContinuation, and SimpleHomotopySweep. 1. `tracking_maxiters` (default 100, `nothing` disables): an iteration cap merged into the inner solver's options for interior tracking steps only. It never applies to the sweep's λspan[1] anchor solve or the final step landing on λspan[2] (in the cached HomotopySweep driver these are exempted via full-budget standalone rescues so the happy path keeps a single inner workspace; in arclength the anchor/landing already run through `_arclength_fixed_solve`, which stays uncapped), and never overrides an explicit user-passed `maxiters` in the solve or problem kwargs. Rationale: every bisection retry otherwise re-runs the inner solver against its full default budget of 1000 iterations. Measured on the failing fold sweep `u² + λ − 0.5 = 0` from u0 = 0.7 (total residual calls): polyalg inner, uncapped 93049 (issue measured 89349) polyalg inner, default cap 100 11534 polyalg inner, cap 20 3257 (issue measured 3294) NewtonRaphson, uncapped 48132 (issue measured 46173) NewtonRaphson, cap 20 1050 (issue measured 1093) SimpleHomotopySweep uncapped 48126 SimpleHomotopySweep cap 20 1094 The generous default of 100 keeps currently-converging tracking steps converging; 10-20 (OpenModelica homMaxNewtonSteps, MatCont MaxCorrIters, HC.jl's Newton cap) makes rejections cheap. 2. Iteration-count band step controller on success (AUTO-07p ADPTDS style), layered UNDER the existing gates: in the sweeps the streak + `expand_quality` gates still veto growth, and the growth factor is now scaled by the accepted step's corrector iteration count nit (from `sol.stats.nsteps`, per-solve even under the cached driver; `stats === nothing` falls back to the classic unscaled behavior): nit ≤ max(3, budget÷20) earns the full `expand_factor`, nit ≤ max(6, budget÷4) earns 1 + (expand_factor−1)/2, beyond that the step holds (streak preserved so growth resumes when evidence recovers), and nit ≥ 3·budget/4 proactively halves the step even on success -- the earliest warning that the next full-size step will be rejected. ArcLengthContinuation gains the same bands alongside its bend-angle gate, giving it a corrector-effort signal it previously lacked. No new kwargs beyond `tracking_maxiters`. 3. `maxsteps` guard for HomotopySweep and SimpleHomotopySweep (default 10000, matching ArcLengthContinuation): caps total predictor-corrector attempts (accepted + bisection retries), returning `ReturnCode.MaxIters` with the last converged iterate. Validated ≥ 1 in the constructors, as is `tracking_maxiters` (≥ 1 or `nothing`). Also fixes a pre-existing polyalg bug this feature exposed: `init(prob, polyalg; maxiters)` silently dropped `maxiters` -- the polyalg `__init` captured it without forwarding it to the subcaches, while the specialized `solve!(::NonlinearSolvePolyAlgorithmCache)` runs each subcache to ITS own termination and never consults the polyalg-level field. The one-shot `__solve` path forwards `maxiters` to every subsolver; `__init` now matches. Tests: new test/Core/homotopy_effort_tests__item{1,2}.jl cover the eval-count reduction (with generous margins over the measurements above), the anchor/landing exemptions (problems whose anchor needs ~14 Newton iterations and whose landing needs > 1 succeed under caps of 5 and 1), user-kwarg precedence (solve-level and problem-level `maxiters` both resurrect the full-budget behavior), the maxsteps guard (creeping sweep returns MaxIters with a finite last-converged iterate), constructor validation, effort-band non-regression on an easy path (growth still beats expand_factor = 1), and arclength fold-rounding under caps of 100 and 20. Ran locally on Julia 1.11.9: all 21 homotopy_sweep + 6 arclength + 2 new Core files, the PolyAlgorithms group, polyalg cache/NoInit/aliasing/issue regression files, and SimpleNonlinearSolve's sweep + AllocCheck allocation tests (the StaticArray sweep stays allocation-free): 387 assertions, all passing. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
49db565 to
8ad7c55
Compare
Per review: the generous default of 100 hedged away most of the benefit — a rejected step's warm-started retry at half the increment IS the designed recovery, so there is no reason to let a struggling interior corrector grind toward a large budget first. Default now 20 in all three drivers, matching OpenModelica (homMaxNewtonSteps), MatCont (MaxCorrIters), and HomotopyContinuation.jl's Newton cap; the failing-fold cost drops ~30x out of the box instead of ~8x. The anchor and final landing solves remain uncapped and user-passed maxiters still wins, so target accuracy and branch selection are unaffected. Also trims the three tracking_maxiters docstring bullets to the essentials (purpose, default + provenance, exemptions, user precedence); the measurement tables live in the commit history and PR. Re-verified (Julia 1.11): full battery (21 sweep + 6 arclength + polyalg + both effort files) 232/232; SimpleHomotopySweep AllocCheck 2/2; Runic clean. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
|
Per review, pushed
Re-verified on the committed code: full battery (21 sweep + 6 arclength + polyalg + both effort files) 232/232, |
…ult 10 Investigating tracking_maxiters = 10 vs 20 exposed a controller bug: the proactive-shrink band compared the accepted step's stats.nsteps against the per-solver budget, but a polyalgorithm inner reports nsteps aggregated across ALL its ladder members (e.g. Broyden 20 + Klement 20 + Newton 4 = 44 > 3/4 of 20), so on systems large enough that the quasi-Newton members burn their budget before a Newton member succeeds, EVERY accepted step read as "corrector struggling" and dλ was halved every step. Measured on an n = 50 coupled system: uncapped 297 residual calls; cap 20 collapsed to 119445 calls; cap 10 hit the maxsteps guard and failed outright. Fix: the shrink signal is trusted only when nit <= budget — an over-budget count proves ladder aggregation, not corrector struggle — and an untrustworthy count may withhold growth but never shrink. Post-fix, the same n = 50 problem runs at 484-534 calls across caps of 10/15/20. With the controller fixed, 10 vs 20 was benchmarked across failing folds (polyalg, Newton, and Simple inners), a sharp-turn trap, a steep path, easy paths, arclength S-fold rounding (secant and tangent), and the n = 50 system: 10 wins or ties everywhere (17-34% cheaper on failing/hard paths, identical elsewhere). Risk is asymmetric in its favor (a too-tight cap costs one warm-started bisected retry; a too-loose one taxes every rejection), and it matches field practice (MatCont 10, HomotopyContinuation.jl 11, AUTO ITNW 5; OpenModelica's 20 is the high outlier). Default is now 10 in all three drivers. Verified (Julia 1.11): full battery (21 sweep + 6 arclength + polyalg + both effort files) 232/232 under the new default; SimpleHomotopySweep AllocCheck 2/2; Runic clean. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
|
Investigated The bug the benchmark exposedThe proactive-shrink band compared the accepted step's Neither the original tests nor the review battery caught this — no sweep test used n ≥ 50 (suite blind spot, now covered by the fix's rationale in the code comment). Fix: the shrink signal is trusted only when 10 vs 20 on the fixed controller
10 wins or ties everywhere — 17–34% cheaper on failing/hard paths, identical on easy ones. Risk is asymmetric in its favor: a too-tight cap costs one warm-started bisected retry, a too-loose one taxes every rejection. It also matches field practice (MatCont Re-verified on the committed code: full battery 232/232, |
… 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]>
Note
This PR should be ignored until reviewed by @ChrisRackauckas.
Implements roadmap item Priority 1 of #1020 (plus its folded-in small fix) across all three homotopy drivers:
HomotopySweep,ArcLengthContinuation, andSimpleHomotopySweep.1.
tracking_maxiters(default 100;nothingdisables)An iteration cap merged into the inner solver's options for interior tracking steps only — never the sweep's
λspan[1]anchor solve, never the final step landing onλspan[2](in the cachedHomotopySweepdriver these are exempted via full-budget standalone rescues so the happy path keeps a single inner workspace; arclength's anchor/landing go through_arclength_fixed_solve, which stays uncapped), and never overriding an explicit user-passedmaxiters(solve-level or problem-level kwargs win).Motivation and measurement (failing fold sweep
u² + λ − 0.5 = 0fromu0 = 0.7, total residual calls; issue #1020 measured the same problem):The generous default of 100 keeps currently-converging tracking steps converging (~8× cheaper rejections); 10–20 (OpenModelica
homMaxNewtonSteps, MatContMaxCorrIters, HC.jl's Newton cap) makes rejections ~30–45× cheaper.2. Iteration-count band step controller (AUTO-07p
ADPTDSstyle)On success, the growth factor is scaled by the accepted step's corrector iteration count (
sol.stats.nsteps, per-solve even under the cached driver;stats === nothingfalls back to the classic behavior), layered under the existing gates (streak +expand_qualitystill veto growth): very cheap steps earn the fullexpand_factor, moderate ones earn half the growth, expensive ones hold (streak preserved so growth resumes when evidence recovers), and near-budget steps proactively halve the increment even on success — the earliest warning that the next full-size step would be rejected.ArcLengthContinuationgains the same bands alongside its bend-angle gate (it previously had no corrector-effort signal at all).3.
maxstepsguard for both sweeps (default 10000, matching arclength)Caps total predictor-corrector attempts (accepted + bisection retries), returning
ReturnCode.MaxIterswith the last converged iterate. Previously the sweep's loop was bounded only byspan/min_dλ ≈ 7×10⁷worst-case. Constructor-validated (≥ 1), as istracking_maxiters(≥ 1 ornothing).Drive-by bug fix (pre-existing, exposed by this feature)
init(prob, polyalg; maxiters)silently droppedmaxiters: the polyalg__initcaptured it without forwarding to the subcaches, and the specializedsolve!(::NonlinearSolvePolyAlgorithmCache)runs each subcache to its own termination without consulting the polyalg-level field. The one-shot__solvepath forwardsmaxitersto every subsolver;__initnow matches. (This is why the cached sweep driver could not previously enforce any per-step budget with the default inner.)Verification (run locally, Julia 1.11.9; re-verified independently after the implementing agent's run)
test/Core/homotopy_effort_tests__item{1,2}.jl: eval-count reduction with generous margins over the measurements above; anchor/landing exemptions (problems whose anchor needs ~14 Newton iterations and whose landing needs > 1 succeed under caps of 5 and 1); user-kwarg precedence (solve-level and problem-levelmaxitersrestore full-budget behavior);maxstepsguard returnsMaxIterswith finite last-converged iterate; constructor validation; effort-band non-regression on an easy path (growth still beatsexpand_factor = 1); arclength fold-rounding under caps of 100 and 20.homotopy_sweep+ 6arclength+ polyalg + both new effort files + polyalg cache/NoInit regression files + PolyAlgorithms basic — 277 assertions pass (273 in the main runner + the polyalg-aliasing file run in its proper test env, 4/4).SimpleHomotopySweepAllocCheck test: 2/2 — the StaticArray sweep stays allocation-free with the new kwargs.--checkexit 0 on all seven touched files. No Project.toml version bumps.Coordination
Sibling PRs #1021 (arclength tangent/metric) and #1022 (sweep jac passthrough) touch the same files in disjoint regions; sequential rebases may be needed depending on merge order.
🤖 Generated with Claude Code