Skip to content

Big slowdown and type instabilities of AD through ODE solver #2837

@hersle

Description

@hersle

Example:

using OrdinaryDiffEq, ProfileCanvas, ForwardDiff
function rober!(du, u, p, t)
    y₁, y₂, y₃ = u
    k₁, k₂, k₃ = p
    du[1] = -k₁ * y₁ + k₃ * y₂ * y₃
    du[2] = k₁ * y₁ - k₂ * y₂^2 - k₃ * y₂ * y₃
    du[3] = k₂ * y₂^2
    nothing
end
prob = ODEProblem(rober!, [1.0, 0.0, 0.0], (0.0, 1.0), [0.04, 3e7, 1e4])
function y_final(y_initial)
    newprob = remake(prob, u0 = y_initial)
    sol = solve(newprob, KenCarp4(); adaptive = false, dt = 1e-4, save_everystep = false)
    return sol[end]
end
@profview ForwardDiff.jacobian(y_final, [1.0, 0.0, 0.0])

First run the example with new package versions:

(bug) pkg> add OrdinaryDiffEq@6.101.0 LinearSolve@3.28.0 ForwardDiff ProfileCanvas

(bug) pkg> status
Status `~/Downloads/bug/Project.toml`
⌅ [f6369f11] ForwardDiff v0.10.38
  [7ed4a6bd] LinearSolve v3.28.0
  [1dea7af3] OrdinaryDiffEq v6.101.0
  [efd6af41] ProfileCanvas v0.1.6
Image

Then run the same example with older package versions (at least before #2567?):

(bug) pkg> add OrdinaryDiffEq@6.93.0 LinearSolve@3.17.0 ForwardDiff ProfileCanvas

(bug) pkg> status
Status `~/Downloads/bug/Project.toml`
⌅ [f6369f11] ForwardDiff v0.10.38
⌃ [7ed4a6bd] LinearSolve v3.17.0
⌃ [1dea7af3] OrdinaryDiffEq v6.93.0
  [efd6af41] ProfileCanvas v0.1.6
Image

There are a lot of type instabilities with the latest package versions!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions