Skip to content

Add HomotopyProblem: a homotopy/continuation problem type - #1375

Merged
ChrisRackauckas merged 10 commits into
SciML:masterfrom
BatchZero:feature/homotopy-problem
Jun 10, 2026
Merged

ChrisRackauckas merged 10 commits into
SciML:masterfrom
BatchZero:feature/homotopy-problem

Conversation

@BatchZero

Copy link
Copy Markdown
Contributor

Summary

Adds HomotopyProblem <: AbstractNonlinearProblem, a problem type describing a one-parameter homotopy / continuation family

0 = H(u, p, λ)

in which one parameter inside p is a continuation knob λ. It is the natural-parameter-continuation analogue of NonlinearProblem: a solver sweeps λ across λspan (default 0 → 1), deforming an easy-to-solve system into the target. This is the interface type targeted by a continuation solver (HomotopySweep, NonlinearSolve.jl) and by symbolic frontends (the Modelica homotopy() operator in ModelingToolkit.jl).

It does not describe a polynomial system — that is the existing HomotopyNonlinearFunction / HomotopyContinuationJL, which this PR leaves untouched.

API

HomotopyProblem(f, u0, p = NullParameters(); homotopy_parameter, λspan = (0.0, 1.0), kwargs...)
  • f — the residual H as a NonlinearFunction (f(u, p) out-of-place or f(du, u, p) in-place); λ lives inside p.
  • homotopy_parameter — which parameter is λ: a symbolic parameter (resolved through SymbolicIndexingInterface) or an integer index into p.
  • λspan — the continuation interval; the target system is at stop.

It mirrors NonlinearProblem exactly: @add_kwonly inner constructor, raw-function wrapping with isinplace autodetection, and ConstructionBase.constructorof so @reset / remake preserve the parametrized type. The SymbolicIndexingInterface surface is inherited from AbstractNonlinearProblem with no overrides.

HomotopyProblem is also added to the accepted-type set of OverrideInitData, so it can serve as an initialization problem.

Tests

test/homotopy_problem_tests.jl (Core group): construction (explicit NonlinearFunction and raw function with iip autodetection), @reset type preservation, export visibility, inherited parameter_values/state_values, and remake field preservation. The full Core group passes.

Part of a series

First of three coordinated PRs implementing Modelica's homotopy(actual, simplified) operator (spec 3.7.4) for initialization across the SciML stack:

  1. (this PR) SciMLBase — the HomotopyProblem interface type.
  2. NonlinearSolve — HomotopySweep, an MTK-independent natural-parameter continuation solver dispatching on HomotopyProblem.
  3. ModelingToolkit — lower homotopy(actual, simplified) into a HomotopyProblem and target HomotopySweep.

Each is independently reviewable; (2) and (3) depend on this one being released first.

BatchZero added 9 commits June 5, 2026 11:04
Define `HomotopyProblem{uType,isinplace,P,F,K,Λ,S} <: AbstractNonlinearProblem`
in `src/problems/nonlinear_problems.jl` with fields `f`, `u0`, `p`,
`homotopy_parameter`, `λspan`, `kwargs` and two inner constructors (typed
`AbstractNonlinearFunction{iip}` + bare-`f` fallback), mirroring the
`NonlinearProblem` pattern. Includes TDD test in `test/homotopy_problem_tests.jl`.
No outer constructors, export, ConstructionBase, or remake in this commit.
SciMLBase's generic remake, backed by ConstructionBase.constructorof
added in Task 3, already reconstructs HomotopyProblem correctly —
preserving homotopy_parameter and λspan while accepting u0/p/f overrides.
No custom remake method needed (YAGNI).
Comment thread src/problems/nonlinear_problems.jl Outdated
Comment on lines +732 to +735
To define a Homotopy Problem, you give the residual function ``H``

```math
0 = H(u, p, \lambda)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To define a Homotopy Problem, you give the residual function ``H``
```math
0 = H(u, p, \lambda)
To define a Homotopy Problem, you give the residual function ``f``
```math
0 = f(u, p, \lambda)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, but as part of the larger λ-separation rewrite rather than via the suggestion block — the whole signature section it targeted changed. The docstring now reads 0 = f(u, p, λ) throughout.

Comment thread src/problems/nonlinear_problems.jl Outdated
* `f`: The residual `H` as a `NonlinearFunction`.
* `u0`: The initial guess.
* `p`: The parameters; one entry, located by `homotopy_parameter`, is ``\lambda``.
* `homotopy_parameter`: locator (symbol or index) of ``\lambda`` within `p`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a very specific structure for p which will not always be possible. Is there a reason to no just entirely separate it out? I think it should just be lambda is a separate scalar, rather than trying to treat "p is a constant except for one index". That also would make things like automatic differentiation really wonky.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked as requested: the homotopy_parameter index field is deleted, and λ is now a separate trailing argument — f(u, p, λ) out-of-place, f(du, u, p, λ) in-place, i.e. the time-dependent argument convention with λ in place of t, with in-place autodetection via isinplace(f, 4). p passes through unchanged, so any parameter object works (NamedTuple p — impossible under the old design — is now in the tests), and ∂f/∂λ is directly available for future tangent/arclength predictors.

Review feedback (SciML#1375): locating λ inside p required p to have a very
specific (indexable) structure and entangled λ with parameter AD. The residual
now follows the time-dependent argument convention with λ in place of t:
f(u, p, λ) out-of-place, f(du, u, p, λ) in-place, detected via isinplace(f, 4).
Drops the homotopy_parameter field; p passes through to solvers untouched.
Also applies the H -> f docstring rename suggestion.
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