Repository navigation
Add HomotopyProblem: a homotopy/continuation problem type - #1375
Conversation
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).
… a homotopy family)
| To define a Homotopy Problem, you give the residual function ``H`` | ||
|
|
||
| ```math | ||
| 0 = H(u, p, \lambda) |
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
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.
| * `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`. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
Adds
HomotopyProblem <: AbstractNonlinearProblem, a problem type describing a one-parameter homotopy / continuation familyin which one parameter inside
pis a continuation knobλ. It is the natural-parameter-continuation analogue ofNonlinearProblem: a solver sweepsλacrossλspan(default0 → 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 Modelicahomotopy()operator in ModelingToolkit.jl).It does not describe a polynomial system — that is the existing
HomotopyNonlinearFunction/HomotopyContinuationJL, which this PR leaves untouched.API
f— the residualHas aNonlinearFunction(f(u, p)out-of-place orf(du, u, p)in-place);λlives insidep.homotopy_parameter— which parameter isλ: a symbolic parameter (resolved through SymbolicIndexingInterface) or an integer index intop.λspan— the continuation interval; the target system is atstop.It mirrors
NonlinearProblemexactly:@add_kwonlyinner constructor, raw-function wrapping withisinplaceautodetection, andConstructionBase.constructorofso@reset/remakepreserve the parametrized type. The SymbolicIndexingInterface surface is inherited fromAbstractNonlinearProblemwith no overrides.HomotopyProblemis also added to the accepted-type set ofOverrideInitData, so it can serve as an initialization problem.Tests
test/homotopy_problem_tests.jl(Core group): construction (explicitNonlinearFunctionand raw function with iip autodetection),@resettype preservation, export visibility, inheritedparameter_values/state_values, andremakefield preservation. The fullCoregroup 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:HomotopyProbleminterface type.HomotopySweep, an MTK-independent natural-parameter continuation solver dispatching onHomotopyProblem.homotopy(actual, simplified)into aHomotopyProblemand targetHomotopySweep.Each is independently reviewable; (2) and (3) depend on this one being released first.