Skip to content

AutoDiff not working for SplitODEProblem #2719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cwittens opened this issue May 23, 2025 · 2 comments
Open

AutoDiff not working for SplitODEProblem #2719

cwittens opened this issue May 23, 2025 · 2 comments
Labels

Comments

@cwittens
Copy link
Contributor

cwittens commented May 23, 2025

Describe the bug 🐞

When using Rodas5() on a SplitODEProblem{isinplace} ForwardDiff is not working.
(I think because du is not a Dual Number when it should be.)

Expected behavior

ForwardDiff is working.

Minimal Reproducible Example 👇

# Here everything works as expected
function f(du, u , p, t)
    du .= -u.^2 .+ 2u
    return nothing
end

prob = ODEProblem(f, ones(2), (0.0, 1.0))
sol = solve(prob, Rodas5())

# The SplitODEProblem is not working
function f1(du, u , p, t)
    du .= -u.^2
    return nothing
end
function f2(du, u , p, t)
    du .= 2u
    return nothing
end


prob_split = SplitODEProblem(f1, f2, ones(2), (0.0, 1.0))
sol_split = solve(prob_split, Rodas5())

interestingly, doing

function f1(du, u , p, t)
    @show du, u
    du .= -u.^2
    return nothing
end

gives me

(du, u) = ([-1.0, -1.0], [1.0, 1.0])
(du, u) = ([-1.0, -1.0], [1.01, 1.01])
(du, u) = ([-1.0201, -1.0201], [1.0, 1.0])
(du, u) = ([-1.0, -1.0], ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 2}[Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}}(1.0,1.0,0.0), Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}}(1.0,0.0,1.0)])
ERROR: First call to automatic differentiation for the Jacobian
failed. This means that the user `f` function is not compatible
with automatic differentiation. Methods to fix this include:
...

So du is not a dual number, even when it should be.

Error & Stacktrace ⚠️
Looks like the normal "First call to automatic differentiation" Error message, but I think the problem is not the User in this case.

ERROR: First call to automatic differentiation for the Jacobian
failed. This means that the user `f` function is not compatible
with automatic differentiation. Methods to fix this include:

1. Turn off automatic differentiation (e.g. Rosenbrock23() becomes
   Rosenbrock23(autodiff = AutoFiniteDiff())). More details can befound at
   https://docs.sciml.ai/DiffEqDocs/stable/features/performance_overloads/
2. Improving the compatibility of `f` with ForwardDiff.jl automatic
   differentiation (using tools like PreallocationTools.jl). More details
   can be found at https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#Autodifferentiation-and-Dual-Numbers
3. Defining analytical Jacobians. More details can be
   found at https://docs.sciml.ai/DiffEqDocs/stable/types/ode_types/#SciMLBase.ODEFunction

Note: turning off automatic differentiation tends to have a very minimal
performance impact (for this use case, because it's forward mode for a
square Jacobian. This is different from optimization gradient scenarios).
However, one should be careful as some methods are more sensitive to
accurate gradients than others. Specifically, Rodas methods like `Rodas4`
and `Rodas5P` require accurate Jacobians in order to have good convergence,
while many other methods like BDF (`QNDF`, `FBDF`), SDIRK (`KenCarp4`),
and Rosenbrock-W (`Rosenbrock23`) do not. Thus if using an algorithm which
is sensitive to autodiff and solving at a low tolerance, please change the
algorithm as well.

MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 2})
The type `Float64` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat
   @ Base rounding.jl:265
  (::Type{T})(::T) where T<:Number
   @ Core boot.jl:900
  Float64(::IrrationalConstants.Sqrthalfπ)
   @ IrrationalConstants C:\Users\colli\.julia\packages\IrrationalConstants\lWTip\src\macro.jl:131
  ...

Stacktrace:
  [1] jacobian!(J::Matrix{…}, f::Function, x::Vector{…}, fx::Vector{…}, integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, jac_config::Tuple{…})
    @ OrdinaryDiffEqDifferentiation C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_wrappers.jl:223
  [2] calc_J!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:222 [inlined]
  [3] calc_W!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:627 [inlined]
  [4] calc_W!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:565 [inlined]
  [5] calc_rosenbrock_differentiation!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:702 [inlined]
  [6] perform_step!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, cache::OrdinaryDiffEqRosenbrock.RosenbrockCache{…}, repeat_step::Bool)
    @ OrdinaryDiffEqRosenbrock C:\Users\colli\.julia\packages\OrdinaryDiffEqRosenbrock\gYeUg\src\rosenbrock_perform_step.jl:1337
  [7] perform_step!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqRosenbrock\gYeUg\src\rosenbrock_perform_step.jl:1320 [inlined]
  [8] solve!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:620
  [9] __solve(::ODEProblem{…}, ::Rodas5{…}; kwargs::@Kwargs{})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:7
 [10] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [11] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [12] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [13] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [14] solve_up
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1177 [inlined]
 [15] #solve#43
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1089 [inlined]
 [16] solve(prob::ODEProblem{…}, args::Rodas5{…})
    @ DiffEqBase C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1079
 [17] top-level scope
    @ c:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\mwe.jl:27

caused by: MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 2})
The type `Float64` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat
   @ Base rounding.jl:265
  (::Type{T})(::T) where T<:Number
   @ Core boot.jl:900
  Float64(::IrrationalConstants.Sqrthalfπ)
   @ IrrationalConstants C:\Users\colli\.julia\packages\IrrationalConstants\lWTip\src\macro.jl:131
  ...

Stacktrace:
  [1] convert(::Type{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 2})
    @ Base .\number.jl:7
  [2] setindex!(A::Memory{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{…}, Float64, 2}, i1::Int64)
    @ Base .\genericmemory.jl:243
  [3] unsafe_copyto!(dest::Memory{Float64}, doffs::Int64, src::Memory{ForwardDiff.Dual{…}}, soffs::Int64, n::Int64)
    @ Base .\genericmemory.jl:153
  [4] unsafe_copyto!
    @ .\genericmemory.jl:133 [inlined]
  [5] _copyto_impl!
    @ .\array.jl:308 [inlined]
  [6] copyto!
    @ .\array.jl:294 [inlined]
  [7] copyto!
    @ .\array.jl:319 [inlined]
  [8] copyto!
    @ .\broadcast.jl:966 [inlined]
  [9] copyto!
    @ .\broadcast.jl:925 [inlined]
 [10] materialize!
    @ .\broadcast.jl:883 [inlined]
 [11] materialize!
    @ .\broadcast.jl:880 [inlined]
 [12] f1(du::Vector{Float64}, u::Vector{ForwardDiff.Dual{…}}, p::SciMLBase.NullParameters, t::Float64)
    @ Main c:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\mwe.jl:17
 [13] ODEFunction
    @ C:\Users\colli\.julia\packages\SciMLBase\iHgIu\src\scimlfunctions.jl:2573 [inlined]
 [14] (::SplitFunction{…})(du::Vector{…}, u::Vector{…}, p::SciMLBase.NullParameters, t::Float64)
    @ SciMLBase C:\Users\colli\.julia\packages\SciMLBase\iHgIu\src\scimlfunctions.jl:2590
 [15] UJacobianWrapper
    @ C:\Users\colli\.julia\packages\SciMLBase\iHgIu\src\function_wrappers.jl:32 [inlined]
 [16] vector_mode_dual_eval!
    @ C:\Users\colli\.julia\packages\ForwardDiff\UBbGT\src\apiutils.jl:31 [inlined]
 [17] vector_mode_jacobian!(result::Matrix{…}, f!::SciMLBase.UJacobianWrapper{…}, y::Vector{…}, x::Vector{…}, cfg::ForwardDiff.JacobianConfig{…})
    @ ForwardDiff C:\Users\colli\.julia\packages\ForwardDiff\UBbGT\src\jacobian.jl:157
 [18] jacobian!
    @ C:\Users\colli\.julia\packages\ForwardDiff\UBbGT\src\jacobian.jl:82 [inlined]
 [19] jacobian!(::SciMLBase.UJacobianWrapper{…}, ::Vector{…}, ::Matrix{…}, ::DifferentiationInterfaceForwardDiffExt.ForwardDiffTwoArgJacobianPrep{…}, ::ADTypes.AutoForwardDiff{…}, ::Vector{…})
    @ DifferentiationInterfaceForwardDiffExt C:\Users\colli\.julia\packages\DifferentiationInterface\zJHX8\ext\DifferentiationInterfaceForwardDiffExt\twoarg.jl:489
 [20] jacobian!(J::Matrix{…}, f::Function, x::Vector{…}, fx::Vector{…}, integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, jac_config::Tuple{…})
    @ OrdinaryDiffEqDifferentiation C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_wrappers.jl:221
 [21] calc_J!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:222 [inlined]
 [22] calc_W!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:627 [inlined]
 [23] calc_W!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:565 [inlined]
 [24] calc_rosenbrock_differentiation!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqDifferentiation\Akmzh\src\derivative_utils.jl:702 [inlined]
 [25] perform_step!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, cache::OrdinaryDiffEqRosenbrock.RosenbrockCache{…}, repeat_step::Bool)
    @ OrdinaryDiffEqRosenbrock C:\Users\colli\.julia\packages\OrdinaryDiffEqRosenbrock\gYeUg\src\rosenbrock_perform_step.jl:1337
 [26] perform_step!
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqRosenbrock\gYeUg\src\rosenbrock_perform_step.jl:1320 [inlined]
 [27] solve!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:620
 [28] __solve(::ODEProblem{…}, ::Rodas5{…}; kwargs::@Kwargs{})
    @ OrdinaryDiffEqCore C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:7
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [29] __solve
 [29] __solve
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [33] solve_up
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [33] solve_up
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1177 [inlined]
 [34] #solve#43
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [33] solve_up
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1177 [inlined]
 [34] #solve#43
 [29] __solve
    @ C:\Users\colli\.julia\packages\OrdinaryDiffEqCore\UVwdM\src\solve.jl:1 [inlined]
 [30] #solve_call#36
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:667 [inlined]
 [31] solve_call
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:624 [inlined]
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [33] solve_up
 [32] #solve_up#45
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1199 [inlined]
 [33] solve_up
 [33] solve_up
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1177 [inlined]
 [34] #solve#43
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1177 [inlined]
 [34] #solve#43
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1089 [inlined]
 [34] #solve#43
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1089 [inlined]
    @ C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1089 [inlined]
 [35] solve(prob::ODEProblem{…}, args::Rodas5{…})
    @ DiffEqBase C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1079
 [35] solve(prob::ODEProblem{…}, args::Rodas5{…})
    @ DiffEqBase C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1079
    @ DiffEqBase C:\Users\colli\.julia\packages\DiffEqBase\yhgdI\src\solve.jl:1079
 [36] top-level scope
    @ c:\Users\colli\OneDrive - JGU\12. Semester\HiWi\issue\mwe.jl:27
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
[1dea7af3] OrdinaryDiffEq v6.97.0
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
  [47edcb42] ADTypes v1.14.0
  [7d9f7c33] Accessors v0.1.42
  [79e6a3ab] Adapt v4.3.0
  [4fba245c] ArrayInterface v7.19.0
  [4c555306] ArrayLayouts v1.11.1
  [62783981] BitTwiddlingConvenienceFunctions v0.1.6
  [70df07ce] BracketingNonlinearSolve v1.2.0
  [2a0fbf3d] CPUSummary v0.2.6
  [d360d2e6] ChainRulesCore v1.25.1
  [fb6a15b2] CloseOpenIntervals v0.1.13
  [38540f10] CommonSolve v0.2.4
  [bbf7d656] CommonSubexpressions v0.3.1
  [f70d9fcc] CommonWorldInvalidations v1.0.0
  [34da2185] Compat v4.16.0
  [a33af91c] CompositionsBase v0.1.2
  [2569d6c7] ConcreteStructs v0.2.3
  [187b0558] ConstructionBase v1.5.8
  [adafc99b] CpuId v0.3.1
  [a8cc5b0e] Crayons v4.1.1
  [9a962f9c] DataAPI v1.16.0
  [864edb3b] DataStructures v0.18.22
  [e2d170a0] DataValueInterfaces v1.0.0
  [2b5f629d] DiffEqBase v6.174.0
  [163ba53b] DiffResults v1.1.0
  [b552c78f] DiffRules v1.15.1
⌅ [a0c0ee7d] DifferentiationInterface v0.6.54
  [ffbed154] DocStringExtensions v0.9.4
  [4e289a0a] EnumX v1.0.5
  [f151be2c] EnzymeCore v0.8.9
  [d4d017d3] ExponentialUtilities v1.27.0
  [e2ba6199] ExprTools v0.1.10
  [55351af7] ExproniconLite v0.10.14
  [7034ab61] FastBroadcast v0.3.5
  [9aa1b823] FastClosures v0.3.2
  [442a2c76] FastGaussQuadrature v1.0.2
  [a4df4552] FastPower v1.1.2
  [1a297f60] FillArrays v1.13.0
  [6a86dc24] FiniteDiff v2.27.0
⌅ [f6369f11] ForwardDiff v0.10.38
  [069b7b12] FunctionWrappers v1.1.3
  [77dc65aa] FunctionWrappersWrappers v0.1.3
  [46192b85] GPUArraysCore v0.2.0
  [c145ed77] GenericSchur v0.5.5
  [615f187c] IfElse v0.1.1
  [3587e190] InverseFunctions v0.1.17
  [92d709cd] IrrationalConstants v0.2.4
  [82899510] IteratorInterfaceExtensions v1.0.0
  [692b3bcd] JLLWrappers v1.7.0
  [ae98c720] Jieko v0.2.1
  [ba0b0d4f] Krylov v0.10.1
  [b964fa9f] LaTeXStrings v1.4.0
  [10f19ff3] LayoutPointers v0.1.17
  [5078a376] LazyArrays v2.6.1
  [87fe0de2] LineSearch v0.1.4
  [d3d80556] LineSearches v7.3.0
  [7ed4a6bd] LinearSolve v3.14.1
  [2ab3a3ac] LogExpFunctions v0.3.29
  [1914dd2f] MacroTools v0.5.16
  [d125e4d3] ManualMemory v0.1.8
  [bb5d69b7] MaybeInplace v0.1.4
  [2e0e35c7] Moshi v0.3.5
  [46d2c3a1] MuladdMacro v0.2.4
  [d41bc354] NLSolversBase v7.9.1
  [77ba4419] NaNMath v1.1.3
  [8913a72c] NonlinearSolve v4.9.0
  [be0214bd] NonlinearSolveBase v1.10.0
  [5959db7a] NonlinearSolveFirstOrder v1.5.0
  [9a2c21bd] NonlinearSolveQuasiNewton v1.5.0
  [26075421] NonlinearSolveSpectralMethods v1.2.0
  [bac558e1] OrderedCollections v1.8.1
  [1dea7af3] OrdinaryDiffEq v6.97.0
  [89bda076] OrdinaryDiffEqAdamsBashforthMoulton v1.2.0
  [6ad6398a] OrdinaryDiffEqBDF v1.5.0
  [bbf590c4] OrdinaryDiffEqCore v1.26.0
  [50262376] OrdinaryDiffEqDefault v1.4.0
  [4302a76b] OrdinaryDiffEqDifferentiation v1.9.0
  [9286f039] OrdinaryDiffEqExplicitRK v1.1.0
  [e0540318] OrdinaryDiffEqExponentialRK v1.4.0
  [becaefa8] OrdinaryDiffEqExtrapolation v1.5.0
  [5960d6e9] OrdinaryDiffEqFIRK v1.12.0
  [101fe9f7] OrdinaryDiffEqFeagin v1.1.0
  [d3585ca7] OrdinaryDiffEqFunctionMap v1.1.1
  [d28bc4f8] OrdinaryDiffEqHighOrderRK v1.1.0
  [9f002381] OrdinaryDiffEqIMEXMultistep v1.3.0
  [521117fe] OrdinaryDiffEqLinear v1.3.0
  [1344f307] OrdinaryDiffEqLowOrderRK v1.2.0
  [b0944070] OrdinaryDiffEqLowStorageRK v1.3.0
  [127b3ac7] OrdinaryDiffEqNonlinearSolve v1.9.0
  [c9986a66] OrdinaryDiffEqNordsieck v1.1.0
  [5dd0a6cf] OrdinaryDiffEqPDIRK v1.3.0
  [5b33eab2] OrdinaryDiffEqPRK v1.1.0
  [04162be5] OrdinaryDiffEqQPRK v1.1.0
  [af6ede74] OrdinaryDiffEqRKN v1.1.0
  [43230ef6] OrdinaryDiffEqRosenbrock v1.10.0
  [2d112036] OrdinaryDiffEqSDIRK v1.3.0
  [669c94d9] OrdinaryDiffEqSSPRK v1.3.0
  [e3e12d00] OrdinaryDiffEqStabilizedIRK v1.3.0
  [358294b1] OrdinaryDiffEqStabilizedRK v1.1.0
  [fa646aed] OrdinaryDiffEqSymplecticRK v1.3.0
  [b1df2697] OrdinaryDiffEqTsit5 v1.1.0
  [79d7bb75] OrdinaryDiffEqVerner v1.2.0
  [d96e819e] Parameters v0.12.3
  [f517fe37] Polyester v0.7.17
  [1d0040c9] PolyesterWeave v0.2.2
  [d236fae5] PreallocationTools v0.4.27
⌅ [aea7be01] PrecompileTools v1.2.1
  [21216c6a] Preferences v1.4.3
  [08abe8d2] PrettyTables v2.4.0
  [3cdcf5f2] RecipesBase v1.3.4
  [731186ca] RecursiveArrayTools v3.33.0
  [189a3867] Reexport v1.2.2
  [ae029012] Requires v1.3.1
  [7e49a35a] RuntimeGeneratedFunctions v0.5.14
  [94e857df] SIMDTypes v0.1.0
  [0bca4576] SciMLBase v2.93.0
  [19f34311] SciMLJacobianOperators v0.1.5
⌅ [c0aeaf25] SciMLOperators v0.4.0
  [53ae85a6] SciMLStructures v1.7.0
  [efcf1570] Setfield v1.1.2
  [727e6d20] SimpleNonlinearSolve v2.5.0
  [ce78b400] SimpleUnPack v1.1.0
  [0a514795] SparseMatrixColorings v0.4.19
  [276daf66] SpecialFunctions v2.5.1
  [aedffcd0] Static v1.2.0
  [0d7ed370] StaticArrayInterface v1.8.0
  [90137ffa] StaticArrays v1.9.13
  [1e83bf80] StaticArraysCore v1.4.3
  [10745b16] Statistics v1.11.1
  [7792a7ef] StrideArraysCore v0.5.7
  [892a3eda] StringManipulation v0.4.1
  [2efcf032] SymbolicIndexingInterface v0.3.40
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.12.0
  [8290d209] ThreadingUtilities v0.5.3
  [a759f4b9] TimerOutputs v0.5.29
  [781d530d] TruncatedStacktraces v1.4.0
  [3a884ed6] UnPack v1.0.2
  [1d5cc7b8] IntelOpenMP_jll v2025.0.4+0
  [856f044c] MKL_jll v2025.0.1+1
  [efe28fd5] OpenSpecFun_jll v0.5.6+0
  [1317d2d5] oneTBB_jll v2022.0.0+0
  [0dad84c5] ArgTools v1.1.2
  [56f22d72] Artifacts v1.11.0
  [2a0f44e3] Base64 v1.11.0
  [ade2ca70] Dates v1.11.0
  [8ba89e20] Distributed v1.11.0
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching v1.11.0
  [9fa8497b] Future v1.11.0
  [b77e0a4c] InteractiveUtils v1.11.0
  [4af54fe1] LazyArtifacts v1.11.0
  [b27032c2] LibCURL v0.6.4
  [76f85450] LibGit2 v1.11.0
  [8f399da3] Libdl v1.11.0
  [37e2e46d] LinearAlgebra v1.11.0
  [56ddb016] Logging v1.11.0
  [d6f4376e] Markdown v1.11.0
  [ca575930] NetworkOptions v1.2.0
  [44cfe95a] Pkg 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
  [2f01184e] SparseArrays v1.11.0
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [cf7118a7] UUIDs v1.11.0
  [4ec0a83e] Unicode v1.11.0
  [e66e0078] CompilerSupportLibraries_jll v1.1.1+0
  [deac9b47] LibCURL_jll v8.6.0+0
  [e37daf67] LibGit2_jll v1.7.2+0
  [29816b5a] LibSSH2_jll v1.11.0+1
  [c8ffd9c3] MbedTLS_jll v2.28.6+0
  [14a3606d] MozillaCACerts_jll v2023.12.12
  [4536629a] OpenBLAS_jll v0.3.27+1
  [05823500] OpenLibm_jll v0.8.5+0
  [bea87d4a] SuiteSparse_jll v7.7.0+0
  [83775a58] Zlib_jll v1.2.13+1
  [8e850b90] libblastrampoline_jll v5.11.0+0
  [8e850ede] nghttp2_jll v1.59.0+0
  [3f19e933] p7zip_jll v17.4.0+2
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
  • Output of versioninfo()
julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 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-16.0.6 (ORCJIT, tigerlake)
Threads: 8 default, 0 interactive, 4 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
Copy link
Contributor Author

I could figure out the source of the problem, but I think it is somewhere related to the initialization of the problem.
When doing

@show "hey from cache"
@show f

inside of OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl alg_cache(...)

I get

"hey from cache" = "hey from cache"
f = ODEFunction{true, SciMLBase.AutoSpecialize, FunctionWrappersWrappers.FunctionWrappersWrapper{Tuple{FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{Float64}, Vector{Float64}, SciMLBase.NullParameters, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{Float64}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}}, false}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}(FunctionWrappersWrappers.FunctionWrappersWrapper{Tuple{FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{Float64}, Vector{Float64}, SciMLBase.NullParameters, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{Float64}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}}, false}((FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{Float64}, Vector{Float64}, SciMLBase.NullParameters, Float64}}(Ptr{Nothing} @0x000001562ad34630, Ptr{Nothing} @0x000001560a0181b8, Base.RefValue{SciMLBase.Void{typeof(f)}}(SciMLBase.Void{typeof(f)}(Main.f)), SciMLBase.Void{typeof(f)}), FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, Float64}}(Ptr{Nothing} @0x000001562ad36970, Ptr{Nothing} @0x000001560a0181c0, Base.RefValue{SciMLBase.Void{typeof(f)}}(SciMLBase.Void{typeof(f)}(Main.f)), SciMLBase.Void{typeof(f)}), FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{Float64}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}(Ptr{Nothing} @0x000001562ad37c30, Ptr{Nothing} @0x000001560a0181c8, Base.RefValue{SciMLBase.Void{typeof(f)}}(SciMLBase.Void{typeof(f)}(Main.f)), SciMLBase.Void{typeof(f)}), FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, SciMLBase.NullParameters, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}(Ptr{Nothing} @0x000001562ad38fb0, Ptr{Nothing} @0x000001560a0181d0, Base.RefValue{SciMLBase.Void{typeof(f)}}(SciMLBase.Void{typeof(f)}(Main.f)), SciMLBase.Void{typeof(f)}))), LinearAlgebra.UniformScaling{Bool}(true), nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED, nothing, nothing, nothing, nothing)

for the normal problem and

"hey from cache" = "hey from cache"
f = SplitFunction{true, SciMLBase.FullSpecialize, ODEFunction{true, SciMLBase.FullSpecialize, typeof(f1), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, ODEFunction{true, SciMLBase.FullSpecialize, typeof(f2), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, LinearAlgebra.UniformScaling{Bool}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}(ODEFunction{true, SciMLBase.FullSpecialize, typeof(f1), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}(Main.f1, LinearAlgebra.UniformScaling{Bool}(true), nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED, nothing, nothing, nothing, nothing), ODEFunction{true, SciMLBase.FullSpecialize, typeof(f2), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}(Main.f2, LinearAlgebra.UniformScaling{Bool}(true), nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED, nothing, nothing, nothing, nothing), LinearAlgebra.UniformScaling{Bool}(true), [7.26089470524e-312, 8.952700242101e-311], nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED, nothing, nothing, nothing, nothing)

for the Splitproblem, whoch does not seem correct with most of the entries being nothing.

@ChrisRackauckas
Copy link
Member

I think I recently mentioned something about this in a different issue? This is a duplicate? The issue is:

function (f::SplitFunction)(du, u, p, t)
    f.f1(f._func_cache, u, p, t)
    f.f2(du, u, p, t)
    du .+= f._func_cache
end

The fallback uses a _func_cache. https://github.com/SciML/SciMLBase.jl/blob/master/src/problems/ode_problems.jl#L477 this is similar(u0). This needs to use https://github.com/SciML/PreallocationTools.jl?tab=readme-ov-file#lazybuffercache LazyBufferCache as the fix. However, PreallocationTools brings in ForwardDiff, so that wouldn't be allowed. That package should be setup to use Ext for ForwardDiff if we want to make it a SciMLBase dep (about 1 hour of work), and then the fallback dispatch should be setup to use the LBC (about 30 minutes of work). Not much work and clear what to do but I don't know if I'll get to this super soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants