Repository navigation
Preserve u0 === nothing for solvers that handle it via allows_null_u0 - #3433
Merged
ChrisRackauckas merged 2 commits intoApr 15, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
…_u0` `__init` coerces `u0 === nothing` to `Float64[]` so generic caches (`zero(u)`/`similar(u)`/broadcasts) keep working for MTK systems that simplify to only callbacks. IDSolve has a purpose-built `::Nothing` `alg_cache` dispatch that bypasses NonlinearSolve entirely — but it was unreachable because the coercion ran first, and the fallback then tried to build a 0x1 Jacobian in the NLLS branch and crashed. Gate the coercion behind a new trait `allows_null_u0(alg) = false`. IDSolve overrides it to `true`, so `nothing` reaches its cache constructor unchanged and the no-op step path is used. All other solvers keep the existing coercion behavior, so the MTK issue SciML#4078 case still works. Repro that previously errored in `NonlinearSolveBase.construct_jacobian_cache`: fn = ImplicitDiscreteFunction(; resid_prototype = [0.0]) do du, unext, u, p, t du[1] = 1 end pr = ImplicitDiscreteProblem(fn, nothing, (0, 1)) init(pr, IDSolve()) The trait branch is compile-time constant-folded per `@code_warntype`, so there is no runtime branch cost or type instability in the integrator struct. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
Previous run hit infrastructure-level failures (missing julia binary on several self-hosted runners, pkg.julialang.org HTTP/2 download errors, missing gh CLI on benchmark runner) plus a known-flaky SplitODE resize test that passes locally. Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Apr 16, 2026
Source changes since 1.10.0 registration: - allows_null_u0 trait to preserve u0 === nothing (#3433) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Apr 16, 2026
Source changes since 1.10.0 registration: - allows_null_u0 trait to preserve u0 === nothing (#3433) Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Apr 16, 2026
ImplicitDiscreteSolve v1.11.0 imports `allows_null_u0` from OrdinaryDiffEqCore, which was only introduced in v3.31.0 (PR SciML#3433). The previous lower bound of 3.4 allowed resolving versions that don't export this trait, causing an UndefVarError at load time. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 of 2 tasks
ChrisRackauckas
added a commit
that referenced
this pull request
Apr 16, 2026
) ImplicitDiscreteSolve v1.11.0 imports `allows_null_u0` from OrdinaryDiffEqCore, which was only introduced in v3.31.0 (PR #3433). The previous lower bound of 3.4 allowed resolving versions that don't export this trait, causing an UndefVarError at load time. Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/General
that referenced
this pull request
Apr 16, 2026
….11.0 ImplicitDiscreteSolve v1.11.0 imports `allows_null_u0` from OrdinaryDiffEqCore, which was only introduced in v3.31.0 (SciML/OrdinaryDiffEq.jl#3433). The previous lower bound of 3.4.0 allowed resolving versions that don't export this trait, causing UndefVarError at load time. This tightens the OrdinaryDiffEqCore compat for v1.11.0 from "3.4.0 - 3" to "3.31.0 - 3", while leaving prior versions unchanged. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
DilumAluthge
pushed a commit
to JuliaRegistries/General
that referenced
this pull request
Apr 16, 2026
…#153130) [ImplicitDiscreteSolve] Tighten OrdinaryDiffEqCore lower bound for v1.11.0 ImplicitDiscreteSolve v1.11.0 imports `allows_null_u0` from OrdinaryDiffEqCore, which was only introduced in v3.31.0 (SciML/OrdinaryDiffEq.jl#3433). The previous lower bound of 3.4.0 allowed resolving versions that don't export this trait, causing UndefVarError at load time. This tightens the OrdinaryDiffEqCore compat for v1.11.0 from "3.4.0 - 3" to "3.31.0 - 3", while leaving prior versions unchanged. Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
singhharsh1708
pushed a commit
to singhharsh1708/OrdinaryDiffEq.jl
that referenced
this pull request
Apr 16, 2026
…SciML#3433) * Preserve `u0 === nothing` for solvers that handle it via `allows_null_u0` `__init` coerces `u0 === nothing` to `Float64[]` so generic caches (`zero(u)`/`similar(u)`/broadcasts) keep working for MTK systems that simplify to only callbacks. IDSolve has a purpose-built `::Nothing` `alg_cache` dispatch that bypasses NonlinearSolve entirely — but it was unreachable because the coercion ran first, and the fallback then tried to build a 0x1 Jacobian in the NLLS branch and crashed. Gate the coercion behind a new trait `allows_null_u0(alg) = false`. IDSolve overrides it to `true`, so `nothing` reaches its cache constructor unchanged and the no-op step path is used. All other solvers keep the existing coercion behavior, so the MTK issue SciML#4078 case still works. Repro that previously errored in `NonlinearSolveBase.construct_jacobian_cache`: fn = ImplicitDiscreteFunction(; resid_prototype = [0.0]) do du, unext, u, p, t du[1] = 1 end pr = ImplicitDiscreteProblem(fn, nothing, (0, 1)) init(pr, IDSolve()) The trait branch is compile-time constant-folded per `@code_warntype`, so there is no runtime branch cost or type instability in the integrator struct. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]> * Retrigger CI Previous run hit infrastructure-level failures (missing julia binary on several self-hosted runners, pkg.julialang.org HTTP/2 download errors, missing gh CLI on benchmark runner) plus a known-flaky SplitODE resize test that passes locally. Co-Authored-By: Chris Rackauckas <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
u0 === nothing → Float64[]coercion inOrdinaryDiffEqCore/_ode_initbehind a newallows_null_u0(alg)trait (defaultfalse).IDSolveopts in so its purpose-built::Nothingalg_cachedispatch actually fires — the one that bypasses NonlinearSolve entirely for a no-state problem.Motivation
This repro previously crashed inside
NonlinearSolveBase.construct_jacobian_cachetrying to build a 0x1 Jacobian:IDSolve'scache.jlalready hasalg_cache(alg::IDSolve, ::Nothing, ...)that returnsIDSolveCache(nothing, nothing, nothing, nothing, ...)withperform_step!as a no-op success. That dispatch is the right thing for a discrete problem with no state — there is nothing to nonlinear-solve. But it was unreachable: the blanket coercion insolve.jlintroduced in d20c351 turnednothingintoFloat64[]beforealg_cacheran, routing into the generic-vector branch which built a NonlinearLeastSquaresProblem over an empty u.Rather than unwind the coercion (which would regress the MTK case — Tsit5/Rosenbrock23/FBDF caches can't directly ingest
nothing), this introduces a trait so solvers that can handle the richernothingsignal opt in.Design notes
allows_null_u0(alg) = falsedefault inOrdinaryDiffEqCore/src/alg_utils.jl.allows_null_u0(::IDSolve) = trueoverride.if u === nothing && !allows_null_u0(_alg); u = Float64[]; end.@code_warntypeconfirms the branch is compile-time constant-folded in both directions:Tsit5()+nothing→Body::Vector{Float64}(coercion branch taken as const).IDSolve()+nothing→Body::Nothing(coercion branch is dead code).alg+ non-nothingu→ the whole block is dead code.So there is no runtime branch cost and no type instability leaking into the integrator struct.
Test plan
Null u0 bypasses NonlinearSolveinlib/ImplicitDiscreteSolve/test/runtests.jlcovering the failing repro — assertsinteg.cache.u === nothing,integ.cache.nlcache === nothing, andsuccessful_retcode(sol).ODEDIFFEQ_TEST_GROUP=Core Pkg.test("ImplicitDiscreteSolve")— all functional tests pass including the new one.ODEProblem(f, nothing, tspan)+PeriodicCallbackstill succeed, callback triggers expected count (the Release DelayDiffEq 6.1.1 and OrdinaryDiffEqDefault 2.4.2 with correct OrdinaryDiffEqCore floors #4078 regression gate).Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Co-Authored-By: Chris Rackauckas [email protected]