fix: DynamicQuantities compatibility in core + differentiation paths (rebased #3126)#3480
Merged
ChrisRackauckas merged 3 commits intoSciML:masterfrom Apr 21, 2026
Conversation
48b4490 to
f84ae68
Compare
Core init changes so that Tsit5 (and other adaptive methods) can
solve problems whose eltype is a DynamicQuantities `Quantity` of a
`Measurement`:
- `initdt.jl`: use a value-based `oneunit(t)` and compute `dtmin`
via `eps(DiffEqBase.value(t))`, avoiding `eps(::Quantity)` which
is undefined for runtime-unit quantity types.
- `solve.jl`:
- Default `dtmin`/`dtmax` use `zero(prob.tspan[1])` and a direct
subtraction so units are preserved without going through the
unitless `eltype(prob.tspan)(0)` path that drops DQ units.
- `tTypeNoUnits` is derived via `DiffEqBase.value(oneunit(first(tspan)))`
so units are stripped correctly for Unitful and DQ; `one(tType)`
fails for runtime-unit DQ types.
- Split the unitless/tolerance branch into a `scalar_type_tol`
predicate so non-scalar Number arrays take the broadcasting
path.
- `rate_prototype` uses `oneunit(first(tspan))` instead of
`oneunit(tType)` for the same reason as above.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Adds `test/downstream/dynamicquantities_measurements.jl` covering a Tsit5 solve of a problem whose state type combines DynamicQuantities units with Measurements uncertainty propagation. Wires it into the existing `Downstream` CI group so the extra deps (DynamicQuantities, plus the existing Measurements) stay in `test/downstream/Project.toml` and don't leak into `OrdinaryDiffEqCore`'s own test deps. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Adds a narrow "strip units only" primitive that is orthogonal to the existing
`value` (strips everything, including AD) and `unitfulvalue` (strips AD, keeps
units) helpers. Defaults to the identity; Unitful, FlexUnits, and
DynamicQuantities extensions override it to return the underlying numeric value.
Switches the `tTypeNoUnits` derivation in `OrdinaryDiffEqCore/src/solve.jl`
from `DiffEqBase.value(oneunit(first(tspan)))` to
`DiffEqBase.stripunits(oneunit(first(tspan)))` so that ForwardDiff Duals in t0
are preserved through `tTypeNoUnits`. The previous `value`-based form collapsed
Duals to Float64, which then made `NLSolver{true, tTypeNoUnits}` use Float64
fields for ηold etc., and SDIRK solvers (KenCarp4/47/5/58, TRBDF2) that run
with a Dual t0 errored with `MethodError: Float64(::Dual)`.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
4e612f1 to
6ae8e96
Compare
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.
Rebase of #3126 onto the latest master. Original author: @MilesCranmerBot.
Wave 2 (post-DynamicQuantities release) for the DynamicQuantities × SciML rollout.
Tracking issue: JuliaPhysics/DynamicQuantities.jl#200
What this changes
OrdinaryDiffEqCore
lib/OrdinaryDiffEqCore/test/dynamicquantities_measurements.jl)zero(::Type{<:Quantity})on runtime-unit quantity typesOrdinaryDiffEqDifferentiation
Rebase notes
Conflicts resolved in
lib/OrdinaryDiffEqCore/Project.toml: kept master'sDiffEqBase = "6.217"bound alongside the PR's newAllocCheck,DynamicQuantities = "1.8",Measurements,OrdinaryDiffEqTsit5, andFillArrayscompat entries.Supersedes #3126.
Related DiffEqBase PR: SciML/DiffEqBase.jl#1293
Co-Authored-By: Chris Rackauckas accounts@chrisrackauckas.com