Repository navigation
Support nlstep_data on the DAE and multistep stage paths - #4264
Merged
ChrisRackauckas merged 1 commit intoAug 16, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
SciML#4279 made `NonlinearSolveAlg` solve `DAEProblem`s, but left the `nlstep_data` branch untouched. Three defects remain on that branch. **`nlstep_data` is read as a field off any `AbstractSciMLFunction`.** Only `ODEFunction`, `SplitFunction` and (since SciMLBase 3.44) `DAEFunction` have it, so a `DynamicalODEFunction` threw before the first step: FieldError: type DynamicalODEFunction has no field `nlstep_data` build_nlsolver(...) @ utils.jl:839 Look it up the way `get_mass_matrix` already does for `DiscreteFunction`; the check constant-folds on a concrete `f`, so the branch selecting `prob` stays resolved at compile time. **A `DAEFunction` carrying `nlstep_data` had no stage assignment.** Both arms state the stage system in mass-matrix ODE conventions, so a fully implicit problem took the `DIRK` arm and solved the wrong system, returning `Success` at the initial condition. `_compute_rhs!` states the fully implicit stage as `F(du, u, p, t)` at `du = (tmp + α z) * invγdt` and `u = get_dae_uprev(integrator, uprev) + z`, so the coefficient belongs on the derivative argument and the state argument carries the predictor base -- `cache.u₀` for a multistep method, not `uprev`. There is no `M z` term, so `γ₃` stays 1. The predictor base is worth a second look on review: using `uprev` still converges, so it does not fail, it just solves a slightly wrong stage system. DAEProblem(robsys, du0, (0, 1e2); nlstep = true), DFBDF(nlsolve = NonlinearSolveAlg()), abstol = reltol = 1e-10 no DAE arm at all: Success [0.0, 1.0] (the initial condition) with uprev: Success [6.153424605628343e-6, 0.6172329005992305] with the predictor: Success [6.153591276834092e-6, 0.6172348824868119] plain DFBDF: Success [6.153591274602223e-6, 0.6172348823018348] **The multistep stage residual is inflated by `α * invγdt`.** `tmp + f(z) - (α * invγdt) * M * z` is `O(z / dt)`, but this branch feeds the raw residual to `calculate_residuals!` as its convergence measure. At small `dt` it reads as divergence, the step is rejected, `dt` shrinks, the residual grows, and the solver walks to `dtmin`. Scale the stage system so the `M z` coefficient is 1, matching the `DIRK` arm -- which only escaped this because its assignment omits the `invγdt` factor. The root is unchanged. ODEProblem(sys; nlstep = true), FBDF(nlsolve = NonlinearSolveAlg()) on D(y) ~ -y^3 - y from y = 1.0, tspan (0, 1), abstol = reltol = 1e-10 before: Unstable 0.9999999999500001 (the initial condition) after: Success 0.26940468363541614 plain FBDF: 0.2694046833972673 `NonlinearSolveAlg` without `nlstep_data` is untouched: verified byte-identical to plain `FBDF` on the case above. Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas-Claude
force-pushed
the
fix-nlstep-data-dae-4127
branch
from
August 15, 2026 23:36
45a5334 to
5b0ec88
Compare
ChrisRackauckas
marked this pull request as ready for review
August 16, 2026 03:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ignore this PR until it has been reviewed by @ChrisRackauckas. It is a draft and should not be merged before then.
Rebased onto
3d2933057(#4279). That PR madeNonlinearSolveAlgsolveDAEProblems and independently fixed four defects this branch previously carried — thedaenlf/oopdaenlfargument mismatches, the unallocateddz, and theinitialize!parameter tuple. Those are dropped here. #4127 is fixed by #4279, not by this PR; an earlier revision of this description claimed the issue stayed open, which is no longer true.What remains is the part #4279 did not touch:
nlstep_dataon the DAE and multistep stage paths. It adds zero lines mentioningnlstep_data, and master's branch still has only the multistep andDIRKarms.The three defects
1.
nlstep_datais read as a field off anyAbstractSciMLFunction. OnlyODEFunction,SplitFunctionand (since SciMLBase 3.44)DAEFunctionhave it, so aDynamicalODEFunctionthrew before the first step:Looked up the way
get_mass_matrixalready does forDiscreteFunction. The check constant-folds on a concretef, so the branch selectingprobstays resolved at compile time.2. A
DAEFunctioncarryingnlstep_datahad no stage assignment. Both arms state the stage system in mass-matrix ODE conventions, so a fully implicit problem took theDIRKarm and solved the wrong system._compute_rhs!states the fully implicit stage asF(du, u, p, t)atdu = (tmp + α z) * invγdtandu = get_dae_uprev(integrator, uprev) + z, so the coefficient belongs on the derivative argument and the state argument carries the predictor base. There is noM zterm, soγ₃stays 1.3. The multistep stage residual is inflated by
α * invγdt.tmp + f(z) - (α * invγdt) * M * zisO(z / dt), but this branch feeds the raw residual tocalculate_residuals!as its convergence measure. At smalldtit reads as divergence, the step is rejected,dtshrinks, the residual grows, and the solver walks todtmin. Scaled so theM zcoefficient is 1, matching theDIRKarm — which only escaped this because its assignment omits theinvγdtfactor. The root is unchanged.The bit to review hardest
Defect 2's predictor base does not announce itself.
get_dae_uprev(integrator, uprev)returnscache.u₀when the cache defines one — as BDF's does, since a multistep predictor is notuprev. Usinguprevstill converges: it does not error, it solves a slightly wrong stage system and reportsSuccess.Robertson index-1,
tspan = (0, 1e2),abstol = reltol = 1e-10:Four orders of accuracy between the middle two, with the same retcode either way.
Verification
Julia 1.12.4, SciMLBase 3.47.0, on
3d2933057.Multistep,
D(y) ~ -y^3 - yfromy = 1.0,tspan = (0, 1):End to end, all four
NonlinearSolveAlgDAE/ODE configurations on this branch:Tests — new
lib/OrdinaryDiffEqNonlinearSolve/test/nsa_nlstep_data_field_tests.jl, registered in that sublibrary'sruntests.jl. The stage systems are hand-rolled so this does not add a ModelingToolkit dependency. Run asjulia --project=env <file> > log 2>&1; echo "EXIT=$?"— exit0, 10 tests, no failures:Each assertion has a demonstrated failing-before state. The DAE and multistep testsets both assert
≉ u0, because "sitting at the initial condition" was the signature of both bugs and a tolerance check alone can miss it; the DAE case is checked against the closed formu₁ = 1/2 + exp(-2t)/2rather than a reference solve.This changes ODE behaviour, deliberately
Fixing defect 3 is the point, and it turns an
Unstableresult into a correct one.NonlinearSolveAlgwithoutnlstep_datais unaffected — verified byte-identical to plainFBDFabove.Not verified
OrdinaryDiffEqNonlinearSolvesuite was not run to completion locally; only theNonlinearSolveAlgpaths above.DFBDF,FBDFandImplicitEulerwere exercised. Other algorithms reach the same branch but are untested here.🤖 Generated with Claude Code