Skip to content

HomotopyPolyAlgorithm: warm sweep→arclength handoff (#1020 P7) - #1030

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:warm-handoff-polyalg
Jul 11, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:warm-handoff-polyalg

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Part of #1020 (P7).

Note: This PR should be ignored until reviewed by @ChrisRackauckas.

What

HomotopyPolyAlgorithm tried HomotopySweep first and, on failure, restarted the ArcLengthContinuation fallback cold at λspan[1] — redoing the stretch the sweep had already conquered. Now, when the sweep fails partway, the next stage is first attempted on the remaining stretch: the problem is rebuilt with u0 = the sweep's last accepted iterate and λspan = (λ_h, λspan[2]). Controlled by a new warm_handoff::Bool = true keyword on HomotopyPolyAlgorithm (false recovers the old always-cold behavior).

Design (each choice measured, not guessed)

  • The handoff λ is backed off 5% of the span behind the sweep's last accepted λ. The sweep dies at a fold, where the path turns vertical in λ; arclength seeded exactly at the fold starts with its pure-λ initial tangent nearly orthogonal to the path and pays in rejected steps. Measured on the cubic S-curve (u³ − 3u = −3 + 6λ, fold at λ = 5/6): arclength warm-started at the fold costs 226 residual calls vs 166 for a full cold run; backed off 5–10% it costs 127–146. The handed-over u0 is the last accepted iterate (off-path at λ_h by the backoff distance); the stage's own λ-fixed anchor solve pulls it back onto the path in a few warm Newton iterations, so no extra machinery (and no accepted-point history) is needed in the sweep.
  • Span-relative step-size caps are rescaled to survive the span shrink. max_step_factor (and a sweep stage's fixed-size nsteps) are fractions of the span width, so the shrunken span would silently shrink the absolute cap — measured 2.4× worse than cold on the S-curve with max_step_factor = 0.05. The caps are rescaled by full_width/remaining_width, capped at fraction 1 (an absolute step of the remaining width), because unbounded rescaling also measured worse near the fold (166 vs 146 stage calls). The initial step factor stays span-relative: starting small right behind the fold measured cheaper, and adaptivity regrows it within a few steps.
  • Anchor edge case: a sweep that failed at the λspan[1] anchor itself (no accepted point), or within the backoff width of it, hands off nothing — fallback stages run cold exactly as before (asserted by equal residual-call counts with warm_handoff on/off).
  • Double fallback: if the warm-started attempt fails anyway, the stage is retried cold on the original full-range problem before the polyalgorithm moves on — enabling the handoff never costs robustness relative to warm_handoff = false (tested with a stage that fails on any shrunken span but succeeds full-range).
  • Original-problem semantics: a warm-handoff success is rebuilt against the original prob (original λspan semantics, original u type); the shrunken-problem solution stays reachable through original. Stats/retcode forwarding is unchanged from the current single-stage return behavior.
  • arclength.jl is untouched (churning in ArcLengthContinuation: consume jac/jac_prototype/sparsity/colorvec (#1020 item 2 follow-up, stacked on #1021) #1025); the sweep only had its CommonSolve.solve split into an internal driver that additionally returns the last accepted λ on partway failure (public behavior unchanged).

Benchmarks (residual calls via Ref counter, warm vs cold, totals include the failed sweep stage)

Problem warm cold saved
cubic S-curve fold (u³−3u = −3+6λ, fold at λ=5/6) 344 364 5.5%
8-dim coupled fold (cubic drives a linear chain) 436 506 13.8%
S-curve, arclength max_step_factor = 0.05 594 704 15.6%

Stage-only (excluding the identical failed-sweep cost): 146 vs 166, 238 vs 308, 396 vs 506 — 12%, 23%, 22%.

Savings are structurally bounded on these S-curves because the post-fold back-swing (λ 5/6 → 1/6 → 1) dominates the arc; the skipped prefix grows (and with it the savings) the later the fold sits and the tighter the user's step caps are.

Tests

New test/Core/homotopy_polyalg_tests__item2.jl (30 assertions): warm handoff succeeds on the S-curve fold with the correct root and strictly fewer residual calls than cold restart; the returned solution's prob is the original with the shrunken-span stage solution as original and u type preserved; anchor-failure and below-backoff-progress edge cases do identical work with warm_handoff on/off; the double-fallback path (warm fails → cold full-range retry, verified via the spans the stage observed); Float32 handoff preserves eltype. All 33 existing homotopy/arclength/polyalg test files pass locally (Julia 1.12), e.g.:

Test Summary:                      | Pass  Total   Time
HomotopyPolyAlgorithm warm handoff |   30     30  23.2s

🤖 Generated with Claude Code

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 11, 2026 04:03
When a HomotopySweep stage fails partway along the span, hand the next
stage the remaining stretch instead of restarting it cold at λspan[1]:
the problem is rebuilt with u0 = the sweep's last accepted iterate and
λspan = (λ_h, λspan[2]), where λ_h is backed off 5% of the span width
behind the last accepted λ. The backoff matters: the sweep dies at a
fold, and arclength seeded exactly at the fold starts with its pure-λ
initial tangent nearly orthogonal to the path — measured costlier than
a full cold run — while a seed 5% behind is 12–23% cheaper (stage-only)
on the benchmarked fold problems. The stage's own λ-fixed anchor solve
pulls the off-path u0 back onto the path at λ_h.

Span-relative step-size caps (max_step_factor, fixed-size nsteps) are
rescaled by full/remaining width (capped at fraction 1) so a
user-tightened absolute cap survives the span shrink; the initial step
factor stays span-relative (starting small behind the fold measured
cheaper). If the warm attempt fails, the stage is retried cold on the
original full-range problem before moving on, so the handoff never
costs robustness. A sweep that failed at the anchor, or within the
backoff width of it, hands off nothing (cold behavior unchanged). Warm
successes are rebuilt against the original problem (original λspan
semantics and u type), with the shrunken-problem solution attached as
`original`. `warm_handoff = false` recovers the plain staged behavior.

The sweep's CommonSolve.solve is split into an internal driver that
additionally returns the last accepted λ on partway failure; its
public solve behavior is unchanged.

Benchmarks (residual calls, warm vs cold total including the failed
sweep): cubic S-curve fold 344 vs 364 (5.5%); 8-dim coupled fold 436
vs 506 (13.8%); S-curve with max_step_factor = 0.05 arclength 594 vs
704 (15.6%).

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas
ChrisRackauckas merged commit e48e5ce into SciML:master Jul 11, 2026
90 of 93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants