Skip to content

Add FastShortcutHomotopyPolyalg, the named autodiff-aware homotopy continuation default - #1105

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:homotopy-fastshortcut-polyalg
Jul 23, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:homotopy-fastshortcut-polyalg

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

What

Add FastShortcutHomotopyPolyalg — the named, autodiff-aware default continuation polyalgorithm for a SciMLBase.HomotopyProblem, the homotopy analogue of FastShortcutNonlinearPolyalg. It builds a FastShortcutNonlinearPolyalg from the requested autodiff and threads it in as the inner corrector of a HomotopyPolyAlgorithm (fast HomotopySweep, then robust ArcLengthContinuation on failure):

FastShortcutHomotopyPolyalg(; autodiff = AutoFiniteDiff())
# ≡ HomotopyPolyAlgorithm(; inner = FastShortcutNonlinearPolyalg(; autodiff = AutoFiniteDiff()))
  • Defined in top-level src/poly_algs.jl (next to FastShortcutNonlinearPolyalg), exported, docstring'd, and added to the rendered docs (docs/src/native/solvers.md).
  • Wired as the homotopy initialization default: initialization_alg(::HomotopyProblem, autodiff) now returns it (src/default.jl).

Why

Until now the homotopy solve/init default was the bare HomotopyPolyAlgorithm() (each stage's own default inner), with no discoverable, autodiff-aware entry point paralleling FastShortcutNonlinearPolyalg. Downstream code (OrdinaryDiffEq init) had to hand-roll HomotopyPolyAlgorithm((HomotopySweep(; inner), ArcLengthContinuation(; inner))) with inner = FastShortcutNonlinearPolyalg(; autodiff). This gives that construction a name.

It also closes a real gap in the init dispatch: initialization_alg(::AbstractNonlinearProblem, autodiff) returns a plain FastShortcutNonlinearPolyalg, and since HomotopyProblem <: AbstractNonlinearProblem, a homotopy initialization system hitting that fallback would be handed a standard nonlinear algorithm — which fixes λ at the target and solves only the actual system (solve(::HomotopyProblem, ::AbstractNonlinearSolveAlgorithm)), and can converge to the wrong branch. The new initialization_alg(::HomotopyProblem, …) method routes it to continuation instead, carrying the same autodiff. (An SCCNonlinearProblem init that contains homotopy blocks stays on the generic FastShortcutNonlinearPolyalg method — SCCNonlinearSolve #1104 continues those blocks per-block — so only the bare HomotopyProblem needed the override.)

Test

test/Core/homotopy_polyalg_tests__item4.jl:

  • Wiring: FastShortcutHomotopyPolyalg() is a HomotopyPolyAlgorithm of (HomotopySweep, ArcLengthContinuation), each stage's inner a NonlinearSolvePolyAlgorithm.
  • Branch selection proves continuation: block (1-λ)·2(m-1) + λ·(m²-1); from guess m=-3 the solve returns the physical +1 (a plain NewtonRaphson returns the target-λ -1, asserted as control). The finite-diff configuration solves the same problem end-to-end.
  • Init routing: initialization_alg(::HomotopyProblem, autodiff) returns a HomotopyPolyAlgorithm (not a FastShortcutNonlinearPolyalg) and reaches +1.

Verified locally against the fresh monorepo (LinearSolve 5, NonlinearSolveBase 2.37).

Notes


Please ignore until reviewed by @ChrisRackauckas. Opened as a draft.

🤖 Generated with Claude Code

…ntinuation default

`FastShortcutHomotopyPolyalg` is the homotopy analogue of
`FastShortcutNonlinearPolyalg`: a `HomotopyPolyAlgorithm` (fast `HomotopySweep`,
then robust `ArcLengthContinuation`) whose inner corrector is a
`FastShortcutNonlinearPolyalg` built from the requested `autodiff`. It gives the
previously hand-rolled default continuation polyalgorithm a discoverable name.

Also wire it as the homotopy initialization default:
`initialization_alg(::HomotopyProblem, autodiff)` now returns it, closing a gap
where the `AbstractNonlinearProblem` fallback would hand a homotopy init system a
plain nonlinear polyalgorithm that solves only the target-λ system (and can land
on the wrong branch).

- Defined in top-level src/poly_algs.jl, exported, docstring'd, added to docs.
- Uses `HomotopyPolyAlgorithm(; inner)` from NonlinearSolveBase 2.37 (SciML#1104);
  top-level compat bumped 2.36 -> 2.37. NonlinearSolve 4.22 -> 4.23.
- Test: test/Core/homotopy_polyalg_tests__item4.jl (wiring, branch selection,
  init routing).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Jul 23, 2026
…lg collapse target

_homotopy_init_alg hand-rolls exactly NonlinearSolve.FastShortcutHomotopyPolyalg(; autodiff)
(SciML/NonlinearSolve.jl#1105). Once that releases, this body collapses to a call to it.

Comment-only; no behavior change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 23, 2026 08:20
@ChrisRackauckas
ChrisRackauckas merged commit 79baa0b into SciML:master Jul 23, 2026
65 of 71 checks passed
ChrisRackauckas added a commit to SciML/OrdinaryDiffEq.jl that referenced this pull request Jul 23, 2026
…lve → nothing) (#3989)

* Initialize HomotopyProblem init systems by continuation, honoring autodiff

The DAE-initialization OverrideInit path picks the nonlinear algorithm for the init
problem via `default_nlsolve`. A `SciMLBase.HomotopyProblem` (built by ModelingToolkit
when the init system carries Modelica `homotopy(actual, simplified)` operators) must be
solved by continuation, not by a Newton polyalgorithm.

`default_nlsolve` now returns a `HomotopyPolyAlgorithm` (sweep, then pseudo-arclength) for a
`HomotopyProblem`, with the `autodiff` argument threaded into the continuation's *inner
corrector* (`FastShortcutNonlinearPolyalg`) — the differentiation the sweep and the
secant-predictor arclength stage actually use, and where a finite-diff initialization must
avoid dual-numbering a residual that is not ForwardDiff-safe. (A high-level `autodiff` knob
on `HomotopyPolyAlgorithm` itself cannot do this: it lives in NonlinearSolveBase, which
cannot construct the concrete inner solver, so the AD rides on the inner algorithm here.)

Handing a `HomotopyProblem` a plain Newton polyalgorithm instead — as the previous
`AbstractNonlinearProblem` default did — solves only the target-λ system directly (see the
companion `solve(::HomotopyProblem, ::AbstractNonlinearSolveAlgorithm)` in NonlinearSolve),
which on branch selection returns a `Success` retcode on the wrong root (measured `-1.0` vs
the physical `+1.0`).

An `SCCNonlinearProblem` with `HomotopyProblem` blocks is solved with `nothing` so each
block picks its own default (homotopy blocks continue, plain blocks Newton-solve). The
`autodiff` signal cannot be threaded per block from here — `SCCNonlinearSolve` applies one
algorithm to every block — so that is left to a follow-up (routing by block type in
`SCCNonlinearSolve`); the code comment records this.

Adds test/homotopy_default_nlsolve_tests.jl (including a ForwardDiff-hostile residual that
only the finite-diff inner can solve, proving the AD is genuinely threaded).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH

* Cite SciML/NonlinearSolve.jl#1104 as the per-block SCC autodiff follow-up

The SCC homotopy `default_nlsolve` methods return `nothing` (each block picks
its own default) so homotopy blocks continue on the correct branch, at the
cost of the continuation using its default inner corrector instead of the
requested AD backend. #1104 adds the SCCNonlinearSolve per-block routing that
makes returning `FastShortcutNonlinearPolyalg(; autodiff)` here honor autodiff
per block; the NOTE now points at it as the concrete follow-up.

Comment-only; no behavior change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH

* Note FastShortcutHomotopyPolyalg (#1105) as the _homotopy_init_alg collapse target

_homotopy_init_alg hand-rolls exactly NonlinearSolve.FastShortcutHomotopyPolyalg(; autodiff)
(SciML/NonlinearSolve.jl#1105). Once that releases, this body collapses to a call to it.

Comment-only; no behavior change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH

* Correct the homotopy-init follow-up notes: blocked on OrdinaryDiffEq LinearSolve-5 migration

The SCC per-block-autodiff flip and the FastShortcutHomotopyPolyalg collapse both need
NonlinearSolve 4.23 / SCCNonlinearSolve 1.14 / NonlinearSolveBase 2.37, which require
LinearSolve 5. OrdinaryDiffEq is capped at LinearSolve "3.75.0, 4" (pinned to
NonlinearSolve <= 4.21), so the follow-ups are blocked on the LinearSolve-5 migration, not
merely on those packages being released (they are). The SCC flip additionally needs a direct
SCCNonlinearSolve dependency (it is a reverse dep of NonlinearSolve). Notes updated to say so.

Comment-only; no behavior change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GSXiS4u4BaR2RvGFWGEQeH

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Jul 25, 2026
- ExplicitImports: `HomotopyPolyAlgorithm` is used in `src/poly_algs.jl` but was
  only reaching the module through a reexport; import it explicitly from
  NonlinearSolveBase (introduced by #1105).
- Aqua piracy: `initialization_alg(::SciMLBase.HomotopyProblem, autodiff)` in
  `src/default.jl` is an intentional dispatch on the continuation problem type,
  alongside the `AbstractNonlinearProblem` method that is already whitelisted;
  add `HomotopyProblem` to `treat_as_own` (also #1105).
- check_reexports: SciMLTesting 2.4.0 enabled this check by default. NonlinearSolve
  is a facade that deliberately reexports the whole solver stack, so pass a
  `reexports_allow` list built from the sublibraries' public API names and module
  names, unioned with the existing external-reexport set already computed for the
  docs check.

Verified locally: `GROUP=QA Pkg.test()` now passes 19/19 (was 16 passed,
2 failed, 1 errored).

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
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