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

Support for SparseDiffTools v2 #1917

Merged
merged 58 commits into from
May 26, 2023
Merged

Conversation

gaurav-arya
Copy link
Member

No description provided.

@gaurav-arya gaurav-arya marked this pull request as draft March 26, 2023 22:08
ChrisRackauckas referenced this pull request in SciML/StochasticDiffEq.jl Mar 27, 2023
@vpuri3
Copy link
Member

vpuri3 commented Mar 27, 2023

can you also handle

jacvec = SparseDiffTools.JacVec(UJacobianWrapper(_f, t, p), copy(u),
OrdinaryDiffEqTag(), autodiff = alg_autodiff(alg))

jacvec = SparseDiffTools.JacVec(UJacobianWrapper(_f, t, p), copy(u),
OrdinaryDiffEqTag(), autodiff = alg_autodiff(alg))

alg_autodiff would need to be updated to return an AbstractADType https://github.com/SciML/ADTypes.jl/blob/main/src/ADTypes.jl

@vpuri3
Copy link
Member

vpuri3 commented Mar 27, 2023

@ChrisRackauckas can you explain why we are using the OOP update_coefficients(L,u,p,t) here?

L = update_coefficients(A, uprev, p, t)

That is something we have not fully supported in SciMLOps.

EDIT
OOP update_coeffs is fully supported in SciMLOps 0.2.2

src/derivative_utils.jl Outdated Show resolved Hide resolved
@gaurav-arya gaurav-arya marked this pull request as ready for review May 8, 2023 18:13
@gaurav-arya
Copy link
Member Author

gaurav-arya commented May 18, 2023

@ChrisRackauckas are there any convergence tests of implicit methods with a time- or parameter-dependent f? I believe the test suite passed even though I think such a test should have failed prior to c7e778e (update_coefficients for a WOperator would not have properly updated the Jacobian operator if it depended on p or t)

If there aren't, where would you recommend adding one?

(I mean an explicit dependence on p or t, not an implicit one through u, that should indeed work even previously)

@ChrisRackauckas
Copy link
Member

There are but not with operators I think. It would be good to explicitly test that

@vpuri3
Copy link
Member

vpuri3 commented May 18, 2023

@gaurav-arya , check out test/regression/time_derivative_test. Looks like what youre looking for is being tested there?

@vpuri3
Copy link
Member

vpuri3 commented May 22, 2023

looks like the time dependence test passed @gaurav-arya .

@ChrisRackauckas is there anything left to do here?

@gaurav-arya
Copy link
Member Author

@vpuri3 do you know the cause of the speedup in the numbers you posted for Krylov solves? Was there a type instability before or has something changed algorithmically?

@@ -1,6 +1,6 @@
const ROSENBROCK_INV_CUTOFF = 7 # https://github.com/SciML/OrdinaryDiffEq.jl/pull/1539

struct StaticWOperator{isinv, T}
struct StaticWOperator{isinv, T} <: AbstractSciMLOperator{T}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the effect here? Can you time a static array ROBER and make sure that doesn't regress?

@@ -272,7 +280,8 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2,
end

sparsity, colorvec = sparsity_colorvec(f, u)
if alg_autodiff(alg)
# TODO: more generc, do we need this?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I don't understand.

Comment on lines 23 to 24
# KenCarp3, # WOperator doesn't support split problems
# CFNLIRK3, # WOperator doesn't support split problems
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a regression?

@vpuri3
Copy link
Member

vpuri3 commented May 22, 2023

@ChrisRackauckas StaticWOperator regression

using OrdinaryDiffEq, StaticArrays, BenchmarkTools

function rober(u, p, t)
    y₁, y₂, y₃ = u
    k₁, k₂, k₃ = p
    dy₁ = -k₁ * y₁ + k₃ * y₂ * y₃
    dy₂ = k₁ * y₁ - k₂ * y₂^2 - k₃ * y₂ * y₃
    dy₃ = k₂ * y₂^2
    SA[dy₁, dy₂, dy₃]
end

prob = ODEProblem{false}(rober, SA[1.0, 0.0, 0.0], (0.0, 1e5), SA[0.04, 3e7, 1e4])

for Alg in (Rodas4, Rosenbrock23)
    @info "$Alg"
    int = init(prob, Alg())
    @assert int.cache.W isa OrdinaryDiffEq.StaticWOperator

    @btime solve(prob, $Alg(), save_everystep = false)
end

on this branch

julia> include("b.jl")
[ Info: Rodas4
  59.250 μs (900 allocations: 38.14 KiB)
[ Info: Rosenbrock23
  46.375 μs (744 allocations: 30.97 KiB)

on master

julia> include("b.jl")
WARNING: using StaticArrays.push in module Main conflicts with an existing identifier.
[ Info: Rodas4
  60.042 μs (900 allocations: 38.14 KiB)
[ Info: Rosenbrock23
  48.542 μs (744 allocations: 31.08 KiB)

@vpuri3
Copy link
Member

vpuri3 commented May 23, 2023

weird the accuracy error isn't showing up on my local tests (MacOS, Linux w. JL 1.9, ). rerunning CI hoping that its just a fluke

@ChrisRackauckas
Copy link
Member

It went away?

The last thing then is to run Downstream locally and make sure it all works on master branches. If so, then this is good to merge.

@vpuri3
Copy link
Member

vpuri3 commented May 24, 2023

it did go away. The only errors now are from downstream.

I'll run the downstream tests locally with the PR branches this afternoon.

@vpuri3
Copy link
Member

vpuri3 commented May 24, 2023

@ChrisRackauckas, I ran downstream, ODEInterfaceRegression tests locally with this branch of stochasticdiffeq. Everything went smoothly except for:

  1. an accuracy error in test/downstream/delaydiffeq.jl (should be a local problem as delaydiffeq tests pass on CI)
  2. this error in test/odeinterface/init_dt_vs_dopri_tests.jl line 9, test/odeinterface/odeinterface_regression line 41.
Init dt vs dorpri tests: Error During Test at /Users/vp/.julia/packages/SafeTestsets/A8
3XK/src/SafeTestsets.jl:25                                                             
  Got exception outside of a @test                                                     
  LoadError: Cannot find method(s) for dopri5! I've tried to loadODESolvers(), but it d
idn't work. Please check ODEInterface.help_solversupport() and call loadODESolvers and 
check also this output. For further information see also ODEInterface.help_install. 

I also updated the compats in downstream/Project.toml. With that and the StochasticDiffEq PR branch, the compatibility error disappeared. Can also confirm that tests pass locally on ProbNumDiffEq PR branch with this ODE.jl branch.

@vpuri3
Copy link
Member

vpuri3 commented May 24, 2023

Can also confirm that all StochasticDiffEq tests pass locally on the PR branch with this ODE branch

@vpuri3
Copy link
Member

vpuri3 commented May 26, 2023

@ChrisRackauckas good to merge?

@ChrisRackauckas
Copy link
Member

Alright, here it goes.

@ChrisRackauckas ChrisRackauckas merged commit acd09c3 into SciML:master May 26, 2023
@ChrisRackauckas
Copy link
Member

Where is the PR to DelayDiffEq?

@vpuri3 vpuri3 deleted the ag-sparsediff branch May 27, 2023 10:42
@vpuri3
Copy link
Member

vpuri3 commented May 27, 2023

Looks like delaydiffeq doesn't need a PR. The only reference to alg_autodiff (which is the API change) is below, and works fine with this branch.

function OrdinaryDiffEq.alg_autodiff(alg::AbstractMethodOfStepsAlgorithm)
    OrdinaryDiffEq.alg_autodiff(alg.alg)
end

I also ran DelayDiffEq tests locally. Everything passed.

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

Successfully merging this pull request may close these issues.

3 participants