Repository navigation
Initialize HomotopyProblem init systems by continuation (default_nlsolve → nothing) - #3989
Conversation
|
Companions: SciML/NonlinearSolve.jl#1085 and SciML/ModelingToolkit.jl#4766. All drafts; ignore until reviewed by @ChrisRackauckas. |
…odiff 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
574892c to
5cd5e7f
Compare
|
Good catch — the Whole-system On the 'high level finitediff option' question: I looked at putting an SCC caveat: I can't thread |
…w-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. SciML#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
|
On "this needs a high level finitediff option?" (the The SCC homotopy methods still return |
…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
…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
Master SciML#3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]>
Master SciML#3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]>
Master SciML#3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]>
* Route OOP initdt NaN checks through DiffEqBase.NAN_CHECK The OOP Hairer–Wanner path used nested `any(x -> any(isnan, x), f₀)`, which custom array/field types cannot overload. Replace with `DiffEqBase.NAN_CHECK` (and `isnan(d₁)` for AD partials), matching the IIP intent and fixing OrdinaryDiffEq #1404. Co-Authored-By: Chris Rackauckas <[email protected]> * Allow hom abbreviation in typos (homotopy test vars) Master #3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]>
* Fix DAE automatic initdt sign on reversed tspan `ode_determine_initdt` for AbstractDAEProblem returned a positive dt even when tdir < 0, causing "Automatic dt setting has the wrong sign" on reverse integrations. Multiply by tdir (DifferentialEquations #908). Co-Authored-By: Chris Rackauckas <[email protected]> * Fix DAE reverse initdt test: assert dt sign and tighten tols Default adaptive tols left DABDF2/DImplicitEuler endpoint error outside atol=1e-2 (~1.03–1.08 vs 1.0) while still integrating successfully. Assert integ.dt < 0 as the #908 regression check, solve with abstol/reltol=1e-8 for endpoint accuracy, and use Runic 1.0e-2 float style. Co-Authored-By: Chris Rackauckas <[email protected]> * Allow hom abbreviation in typos (homotopy test vars) Master #3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]>
…3998) * Coerce initdt equality checks to scalar Bool `f₀ == f₁` is used to detect a constant zone before callbacks, but some array wrappers (notably PyCall PyObject of arrays) return Vector{Bool} from `==` (JuliaPy/PyCall.jl#900). That is not valid in a boolean context and throws TypeError (OrdinaryDiffEq.jl#1402). Add `_bool_equal` that accepts a true Bool or `all` over array-valued equality results, and use it in both iip and oop initdt paths. Co-Authored-By: Chris Rackauckas <[email protected]> * Allow hom abbreviation in typos (homotopy test vars) Master #3989 introduced scc_hom variable names that typos flags as "hom" → "home". Allow the intentional abbreviation. Co-Authored-By: Chris Rackauckas <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]>
#3989 introduced scc_hom variable names that crate-ci/typos flags as "hom" → "home". hom is intentional (HomotopyProblem / homotopy). Co-authored-by: ChrisRackauckas-Claude <[email protected]>
#4004 added `hom` under "Technical variable names" (line 72) and #4000 added it again at the end of the file (line 149). TOML forbids duplicate keys, so typos cannot read its own config and bails out before checking anything: TOML parse error at line 149, column 1 | 149 | hom = "hom" # scc_hom homotopy abbreviation in NonlinearSolve tests (#3989) | ^^^ duplicate key Remove the later entry — the line 72 declaration already covers the `scc_hom` variables — and leave a pointer in its place, matching how the file already notes the same situation for `Numer`. Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Summary
Makes the DAE-initialization OverrideInit path initialize a
SciMLBase.HomotopyProblem(and anSCCNonlinearProblemthat contains homotopy blocks) by continuation, by havingdefault_nlsolvereturnnothingfor them.Why
default_nlsolvepicks the nonlinear algorithm the OverrideInit path solves the init problem with. AHomotopyProblem— built by ModelingToolkit when the init system carries Modelicahomotopy(actual, simplified)operators (SciML/ModelingToolkit.jl#4766) — has a λ-swept residualf(u, p, λ); the operator is the user declaring the system needs continuation. Returningnothingroutessolve(initprob, nothing)to the problem's own default (NonlinearSolveBase.HomotopyPolyAlgorithm), which sweeps λ from thesimplifiedform to the target.The alternative — the previous
AbstractNonlinearProblemdefault,FastShortcutNonlinearPolyalg— under the companion SciML/NonlinearSolve.jl#1085 solves only the target-λ system directly (solve(::HomotopyProblem, ::standard_alg)fixes λ). That is a real bug, not just slower: on branch-selection it returns aSuccessretcode on the wrong root. Measured end-to-end onhomotopy(m² − 1, 2(m−1))fromm = −3:An
SCCNonlinearProblemwith homotopy blocks is likewise solved withnothing, so each block picks its own default (homotopy blocks continue, plain blocks use the standard nonlinear default); a pure-NonlinearProblemSCC keepsFastShortcutNonlinearPolyalg.Tests
test/homotopy_default_nlsolve_tests.jl(registered inruntests.jl):default_nlsolvereturnsnothingfor aHomotopyProblemand for an SCC that has a homotopy block, and the usualFastShortcutNonlinearPolyalgotherwise. Verified locally (Julia 1.12): 8/8, plus the end-to-end wrong-root/right-root result above.Companions
solve(::HomotopyProblem, ::AbstractNonlinearSolveAlgorithm)solves the target-λ system (so a standard algorithm here does the obvious thing).HomotopyProblem/homotopy SCC blocks this PR initializes.Runic-formatted.
🤖 Generated with Claude Code