OrdinaryDiffEq.jl icon indicating copy to clipboard operation
OrdinaryDiffEq.jl copied to clipboard

RDPK3Sp35(), RDPK3Sp49(), and RDPK3Sp510() not working with Float32

Open cwittens opened this issue 2 months ago • 3 comments

Describe the bug 🐞 RDPK3Sp35(), RDPK3Sp49(), and RDPK3Sp510() not working with Float32 (on CPU), when tspan is given as Float64 tuple.

Expected behavior

tspan = (0.0f0, 1.0f0) and (0.0, 1.0) should work. Right now only (0.0f0, 1.0f0) works when u0 is eltype Float32.

(Interestingly when using CUDABackend() (on a bigger example than the MWE) it works as well)

Minimal Reproducible Example 👇

using Pkg
Pkg.activate(@__DIR__)
Pkg.add("OrdinaryDiffEqLowStorageRK")
using OrdinaryDiffEqLowStorageRK

function foo(du, u, p, t)
    du .= 0.9f0 .* u
end

prob = ODEProblem(foo, zeros(Float32, 10), (0.0, 1.0))
solve(prob, RDPK3Sp35()) # ERROR: No matching function wrapper was found!
solve(prob, RDPK3Sp49()) # ERROR: No matching function wrapper was found!
solve(prob, RDPK3Sp510()) # ERROR: No matching function wrapper was found!

solve(prob, RDPK3SpFSAL49()) # retcode: Success

Error & Stacktrace ⚠️

RROR: No matching function wrapper was found!
Stacktrace:
  [1] _call(::Tuple{}, arg::Tuple{…}, fww::FunctionWrappersWrappers.FunctionWrappersWrapper{…})
    @ FunctionWrappersWrappers C:\Users\colli\.julia\packages\FunctionWrappersWrappers\9XR0m\src\FunctionWrappersWrappers.jl:23
  [2] _call(fw::Tuple{…}, arg::Tuple{…}, fww::FunctionWrappersWrappers.FunctionWrappersWrapper{…})
    @ FunctionWrappersWrappers C:\Users\colli\.julia\packages\FunctionWrappersWrappers\9XR0m\src\FunctionWrappersWrappers.jl:13
  [3] (::FunctionWrappersWrappers.FunctionWrappersWrapper{…})(::Vector{…}, ::Vector{…}, ::SciMLBase.NullParameters, ::Float64)
    @ FunctionWrappersWrappers C:\Users\colli\.julia\packages\FunctionWrappersWrappers\9XR0m\src\FunctionWrappersWrappers.jl:10
  [4] (::ODEFunction{…})(du::Vector{…}, u::Vector{…}, p::SciMLBase.NullParameters, t::Float64)
    @ SciMLBase C:\Users\colli\.julia\packages\SciMLBase\b4Q81\src\scimlfunctions.jl:2597
  [5] ode_determine_initdt(u0::Vector{…}, t::Float64, tdir::Float64, dtmax::Float64, abstol::Float32, reltol::Float32, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), prob::ODEProblem{…}, integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\initdt.jl:53
  [6] auto_dt_reset!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\integrators\integrator_interface.jl:451 [inlined]
  [7] handle_dt!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\solve.jl:638
  [8] __init(prob::ODEProblem{…}, alg::RDPK3Sp35{…}, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_discretes::Bool, save_start::Bool, save_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Float64, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{…}, abstol::Nothing, reltol::Nothing, qmin::Rational{…}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{…}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(LinearAlgebra.opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), progress_id::Symbol, userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias::ODEAliasSpecifier, initializealg::DiffEqBase.DefaultInit, kwargs::@Kwargs{})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\solve.jl:600
  [9] __init (repeats 2 times)
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\solve.jl:11 [inlined]
 [10] #__solve#49
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\solve.jl:6 [inlined]
 [11] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\GMkz9\src\solve.jl:1 [inlined]
 [12] #solve_call#23
    @ C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:127 [inlined]
 [13] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:84 [inlined]
 [14] #solve_up#30
    @ C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:563 [inlined]
 [15] solve_up
    @ C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:540 [inlined]
 [16] #solve#29
    @ C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:530 [inlined]
 [17] solve(prob::ODEProblem{…}, args::RDPK3Sp35{…})
    @ DiffEqBase C:\Users\colli\.julia\packages\DiffEqBase\p82Yh\src\solve.jl:520
 [18] top-level scope
    @ c:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\MWE_F32_RDPK3Sp35\mwe.jl:11
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
using Pkg; Pkg.status()
Status `C:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\MWE_F32_RDPK3Sp35\Project.toml`
  [b0944070] OrdinaryDiffEqLowStorageRK v1.7.0
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
Status `C:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\MWE_F32_RDPK3Sp35\Manifest.toml`
  [47edcb42] ADTypes v1.18.0
  [7d9f7c33] Accessors v0.1.42
  [79e6a3ab] Adapt v4.4.0
  [4fba245c] ArrayInterface v7.21.0
  [62783981] BitTwiddlingConvenienceFunctions v0.1.6
  [2a0fbf3d] CPUSummary v0.2.7
  [fb6a15b2] CloseOpenIntervals v0.1.13
  [38540f10] CommonSolve v0.2.4
  [f70d9fcc] CommonWorldInvalidations v1.0.0
  [34da2185] Compat v4.18.1
  [a33af91c] CompositionsBase v0.1.2
  [2569d6c7] ConcreteStructs v0.2.3
  [187b0558] ConstructionBase v1.6.0
  [adafc99b] CpuId v0.3.1
  [864edb3b] DataStructures v0.19.1
  [2b5f629d] DiffEqBase v6.190.2
  [ffbed154] DocStringExtensions v0.9.5
  [4e289a0a] EnumX v1.0.5
  [f151be2c] EnzymeCore v0.8.14
  [e2ba6199] ExprTools v0.1.10
  [55351af7] ExproniconLite v0.10.14
  [7034ab61] FastBroadcast v0.3.5
  [9aa1b823] FastClosures v0.3.2
  [a4df4552] FastPower v1.1.3
  [1a297f60] FillArrays v1.14.0
  [069b7b12] FunctionWrappers v1.1.3
  [77dc65aa] FunctionWrappersWrappers v0.1.3
  [46192b85] GPUArraysCore v0.2.0
  [615f187c] IfElse v0.1.1
  [3587e190] InverseFunctions v0.1.17
  [82899510] IteratorInterfaceExtensions v1.0.0
  [ae98c720] Jieko v0.2.1
  [10f19ff3] LayoutPointers v0.1.17
  [1914dd2f] MacroTools v0.5.16
  [d125e4d3] ManualMemory v0.1.8
  [2e0e35c7] Moshi v0.3.7
  [46d2c3a1] MuladdMacro v0.2.4
  [bac558e1] OrderedCollections v1.8.1
  [bbf590c4] OrdinaryDiffEqCore v1.36.0
  [b0944070] OrdinaryDiffEqLowStorageRK v1.7.0
  [f517fe37] Polyester v0.7.18
  [1d0040c9] PolyesterWeave v0.2.2
  [d236fae5] PreallocationTools v0.4.34
  [aea7be01] PrecompileTools v1.3.3
  [21216c6a] Preferences v1.5.0
  [3cdcf5f2] RecipesBase v1.3.4
  [731186ca] RecursiveArrayTools v3.39.0
  [189a3867] Reexport v1.2.2
  [ae029012] Requires v1.3.1
  [7e49a35a] RuntimeGeneratedFunctions v0.5.15
  [94e857df] SIMDTypes v0.1.0
  [0bca4576] SciMLBase v2.121.1
  [c0aeaf25] SciMLOperators v1.9.0
  [431bcebd] SciMLPublic v1.0.0
  [53ae85a6] SciMLStructures v1.7.0
  [efcf1570] Setfield v1.1.2
  [ce78b400] SimpleUnPack v1.1.0
  [aedffcd0] Static v1.3.0
  [0d7ed370] StaticArrayInterface v1.8.0
  [90137ffa] StaticArrays v1.9.15
  [1e83bf80] StaticArraysCore v1.4.3
  [10745b16] Statistics v1.11.1
  [7792a7ef] StrideArraysCore v0.5.8
  [2efcf032] SymbolicIndexingInterface v0.3.46
  [8290d209] ThreadingUtilities v0.5.5
  [781d530d] TruncatedStacktraces v1.4.0
  [56f22d72] Artifacts v1.11.0
  [2a0f44e3] Base64 v1.11.0
  [ade2ca70] Dates v1.11.0
  [8ba89e20] Distributed v1.11.0
  [9fa8497b] Future v1.11.0
  [b77e0a4c] InteractiveUtils v1.11.0
  [ac6e5ff7] JuliaSyntaxHighlighting v1.12.0
  [8f399da3] Libdl v1.11.0
  [37e2e46d] LinearAlgebra v1.12.0
  [56ddb016] Logging v1.11.0
  [d6f4376e] Markdown v1.11.0
  [de0858da] Printf v1.11.0
  [9a3f8284] Random v1.11.0
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization v1.11.0
  [6462fe0b] Sockets v1.11.0
  [f489334b] StyledStrings v1.11.0
  [fa267f1f] TOML v1.0.3
  [cf7118a7] UUIDs v1.11.0
  [4ec0a83e] Unicode v1.11.0
  [e66e0078] CompilerSupportLibraries_jll v1.3.0+1
  [4536629a] OpenBLAS_jll v0.3.29+0
  [8e850b90] libblastrampoline_jll v5.15.0+0
  • Output of versioninfo()
Julia Version 1.12.1
Commit ba1e628ee4 (2025-10-17 13:02 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, tigerlake)
  GC: Built with stock GC
Threads: 8 default, 1 interactive, 8 GC (on 8 virtual cores)
Environment:
  JULIA_NUM_THREADS = 8
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1

Additional context

Add any other context about the problem here.

cwittens avatar Oct 22 '25 03:10 cwittens

The difference comes from

https://github.com/SciML/OrdinaryDiffEq.jl/blob/3c55c01f57d6cc32fba2b3c1130a779bf692a529/lib/OrdinaryDiffEqCore/src/initdt.jl#L39-L54

The working methods, such as RDPK3SpFSAL49, choose the first branch. The others end up in the second branch.

ranocha avatar Oct 22 '25 07:10 ranocha

eltype(first(u0) / oneunit_tType) the unit support seems to be making it promote the type. With v7 I hope we cut out Unitful.jl support and tell people to use DynamicQuantities.jl because this kind of stuff would just go away.

ChrisRackauckas avatar Oct 22 '25 09:10 ChrisRackauckas

In any case, I would recommend using Float32 for the time span as well. Otherwise, the intermediate results may be computed using Float64:

julia> ode = ODEProblem(MtlArray(ones(Float32, 4)), (0.0, 1.0)) do du, u, p, t
           @. du = u
       end
ODEProblem with uType MtlVector{Float32, Metal.PrivateStorage} and tType Float64. In-place: true
Non-trivial mass matrix: false
timespan: (0.0, 1.0)
u0: 4-element MtlVector{Float32, Metal.PrivateStorage}:
 1.0
 1.0
 1.0
 1.0

julia> solve(ode, RDPK3SpFSAL35())
ERROR: InvalidIRError: compiling MethodInstance for (::Metal.var"#broadcast_linear#230")(::MtlDeviceVector{…}, ::Base.Broadcast.Broadcasted{…}) resulted in invalid LLVM IR
Reason: unsupported use of double value

ranocha avatar Oct 22 '25 10:10 ranocha