Skip to content
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

Type instability for ODEProblem? #2024

Closed
NilsNiggemann opened this issue Sep 6, 2023 · 2 comments
Closed

Type instability for ODEProblem? #2024

NilsNiggemann opened this issue Sep 6, 2023 · 2 comments

Comments

@NilsNiggemann
Copy link

Maybe I am missing something, but @code_warntype reports a type instability when setting up an ODEProblem:

I am encountering this on Julia 1.9.3 with the newest version (OrdinaryDiffEq v6.55.0)

MWE:
from the tutorial:

using OrdinaryDiffEq
function lorenz!(du,u,p,t)
 du[1] = 10.0(u[2]-u[1])
 du[2] = u[1]*(28.0-u[3]) - u[2]
 du[3] = u[1]*u[2] - (8/3)*u[3]
end
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)

Then I run @code_warntype:

julia> @code_warntype ODEProblem(lorenz!,u0,tspan)
MethodInstance for ODEProblem(::typeof(lorenz!), ::Vector{Float64}, ::Tuple{Float64, Float64})
  from ODEProblem(f, u0, tspan) @ SciMLBase /storage/user/.julia/packages/SciMLBase/DPrcG/src/problems/ode_problems.jl:174
Arguments
  #self#::Type{ODEProblem}
  f::Core.Const(lorenz!)
  u0::Vector{Float64}
  tspan::Tuple{Float64, Float64}
Body::Any
1 ─ %1 = SciMLBase.NullParameters()::Core.Const(SciMLBase.NullParameters())
│   %2 = (#self#)(f, u0, tspan, %1)::Any
└──      return %2

It looks like it cannot figure out the return type.

@avik-pal
Copy link
Member

avik-pal commented Sep 6, 2023

ODEProblem(lorenz!,u0,tspan) needs to do a runtime check to determine if the function is in place / out of place. If you use ODEProblem{true}(lorenz!,u0,tspan) then everything is inferred properly.

@NilsNiggemann
Copy link
Author

Ah that makes sense,
Seems like I was overzealous when I was hunting type instabilities.

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

No branches or pull requests

2 participants