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 interpolating solution from out of place prob with default solver #2530

Closed
densmojd opened this issue Nov 14, 2024 · 3 comments · Fixed by #2540
Closed

Type instability interpolating solution from out of place prob with default solver #2530

densmojd opened this issue Nov 14, 2024 · 3 comments · Fixed by #2540
Assignees
Labels

Comments

@densmojd
Copy link

Interpolating a solution from a non-mutating problem definition is type unstable, but using a mutating definition is fine.

MWE:

using OrdinaryDiffEq

function f1(du, u, p, t)
       du .= -u
end

function f2(u, p, t)
       -u
end

sol1 = solve(ODEProblem(f1, [1.0, 2.0, 3.0], (0.0, 10.0)))
sol2 = solve(ODEProblem(f2, [1.0, 2.0, 3.0], (0.0, 10.0)))

@code_warntype sol1(1.0) # type stable
@code_warntype sol2(1.0) # type unstable

I'm using Julia 1.11.1 and OrdinaryDiffEq.jl v6.90.1

@ChrisRackauckas
Copy link
Member

@oscardssmith can you look at this one?

@oscardssmith oscardssmith changed the title Type instability when interpolating solution from non-mutating problem definition Type instability interpolating solution from out of place prob with default solver Nov 20, 2024
@oscardssmith
Copy link
Contributor

looks like a bug with the default solver.

@oscardssmith
Copy link
Contributor

oscardssmith commented Nov 20, 2024

specifically, we seem to be creating the cache with an abstract type incorrectly...

prob = ODEProblem(f2, [1.0, 2.0, 3.0], (0.0, 10.0))
integ = init(prob)
julia> fieldtype(typeof(integ.cache), :cache3)
OrdinaryDiffEqRosenbrock.Rosenbrock23ConstantCache{_A, SciMLBase.TimeDerivativeWrapper{false, ODEFunction{false, SciMLBase.AutoSpecialize, typeof(f2), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, SciMLBase.NullParameters}, SciMLBase.UDerivativeWrapper{false, ODEFunction{false, SciMLBase.AutoSpecialize, typeof(f2), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing, Nothing}, Float64, SciMLBase.NullParameters}, Matrix{Float64}, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Nothing, ADTypes.AutoFiniteDiff{Val{:forward}, Val{:forward}, Val{:hcentral}}} where _A

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

Successfully merging a pull request may close this issue.

3 participants