From 598b920bd4eba1867cdc0085a7704ae4f726dd5e Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Tue, 8 Oct 2024 09:42:00 -0400 Subject: [PATCH 01/10] fix saveat includes save_start for ARKODE --- src/common_interface/solve.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common_interface/solve.jl b/src/common_interface/solve.jl index 004fbdd..a1cb3c0 100644 --- a/src/common_interface/solve.jl +++ b/src/common_interface/solve.jl @@ -483,8 +483,12 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractODEProblem{uType, tupType, i save_everystep = isempty(saveat), save_idxs = nothing, dense = save_everystep, save_on = true, - save_start = true, - save_end = true, + save_start = save_everystep || isempty(saveat) || + saveat isa Number ? true : + prob.tspan[1] in saveat, + save_end = save_everystep || isempty(saveat) || + saveat isa Number ? true : + prob.tspan[2] in saveat, save_timeseries = nothing, progress = false, progress_steps = 1000, @@ -1415,7 +1419,7 @@ function DiffEqBase.solve!(integrator::AbstractSundialsIntegrator; early_free = integrator.userfun.p = integrator.p solver_step(integrator, tstop) integrator.t = first(integrator.tout) - # NB: CVode, ARKode may warn and then recover if integrator.t == integrator.tprev so don't flag this as an error + # NB: CVode, ARKode may warn and then recover if integrator.t == integrator.tprev so don't flag this as an error integrator.flag < 0 && break handle_callbacks!(integrator) # this also updates the interpolation integrator.flag < 0 && break From bbbd7dfe309b9368067a85dd75af4f12a5bfb4f8 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Tue, 8 Oct 2024 10:08:29 -0400 Subject: [PATCH 02/10] add test --- test/common_interface/arkode.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/common_interface/arkode.jl b/test/common_interface/arkode.jl index b303bc9..45d8047 100644 --- a/test/common_interface/arkode.jl +++ b/test/common_interface/arkode.jl @@ -56,3 +56,21 @@ method = ARKODE(Sundials.Explicit(); # Solve sol = solve(prob, method) @test sol.retcode == ReturnCode.Success + + + +function lotka_volterra(du, u, p, t) + # Model parameters. + α, β, γ, δ = p + # Current state. + x, y = u + + # Evaluate differential equations. + du[1] = (α - β * y) * x # prey + du[2] = (δ * x - γ) * y # predator + + return nothing +end + +sol = solve(prob, ARKODE(), saveat = [0.1, 0.2]) +@test sol.t == [0.1, 0.2] From 7e1c02d1b95afe4da578b3162f4b1c9d3f3bf167 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Tue, 8 Oct 2024 10:09:24 -0400 Subject: [PATCH 03/10] cleanup --- test/common_interface/arkode.jl | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/test/common_interface/arkode.jl b/test/common_interface/arkode.jl index 45d8047..1b6c7b4 100644 --- a/test/common_interface/arkode.jl +++ b/test/common_interface/arkode.jl @@ -57,20 +57,6 @@ method = ARKODE(Sundials.Explicit(); sol = solve(prob, method) @test sol.retcode == ReturnCode.Success - - -function lotka_volterra(du, u, p, t) - # Model parameters. - α, β, γ, δ = p - # Current state. - x, y = u - - # Evaluate differential equations. - du[1] = (α - β * y) * x # prey - du[2] = (δ * x - γ) * y # predator - - return nothing -end - +#test that save_start and save_end are false by default when saveat is set sol = solve(prob, ARKODE(), saveat = [0.1, 0.2]) @test sol.t == [0.1, 0.2] From 38c170a1a75483d2b3e63a7af60e872f5bf7019c Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 9 Oct 2024 11:05:58 -0400 Subject: [PATCH 04/10] fix precs test --- Project.toml | 4 ++-- test/common_interface/precs.jl | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 42b9806..4e6a8a4 100644 --- a/Project.toml +++ b/Project.toml @@ -35,8 +35,8 @@ IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" ODEProblemLibrary = "fdc4e326-1af4-4b90-96e7-779fcce2daa5" SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804" -SparsityTracing = "06eadbd4-12ad-4cbc-ab6e-10f8370940a5" +SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "AlgebraicMultigrid", "DiffEqCallbacks", "ODEProblemLibrary", "DAEProblemLibrary", "ForwardDiff", "SparseDiffTools", "SparsityTracing", "IncompleteLU", "ModelingToolkit"] +test = ["Test", "AlgebraicMultigrid", "DiffEqCallbacks", "ODEProblemLibrary", "DAEProblemLibrary", "ForwardDiff", "SparseDiffTools", "SparseConnectivityTracer", "IncompleteLU", "ModelingToolkit"] diff --git a/test/common_interface/precs.jl b/test/common_interface/precs.jl index 487ef66..058c444 100644 --- a/test/common_interface/precs.jl +++ b/test/common_interface/precs.jl @@ -1,6 +1,6 @@ using Sundials, Test, LinearAlgebra, IncompleteLU import AlgebraicMultigrid -import SparsityTracing, SparseDiffTools +import SparseConnectivityTracer, SparseDiffTools const N = 32 const xyd_brusselator = range(0; stop = 1, length = N) @@ -46,15 +46,14 @@ function init_brusselator_2d(xyd) u end u0 = vec(init_brusselator_2d(xyd_brusselator)) +du = similar(u0) prob_ode_brusselator_2d = ODEProblem(brusselator_2d_vec, u0, (0.0, 11.5), p) -# find Jacobian sparsity pattern -u0_st = SparsityTracing.create_advec(u0) -du_st = similar(u0_st) -brusselator_2d_vec(du_st, u0_st, p, 0.0) -const jaccache = SparsityTracing.jacobian(du_st, length(du_st)) +detector = SparseConnectivityTracer.TracerSparsityDetector() +brus_uf = (du, u)->brusselator_2d_vec(du, u, p, 0.1) +const jaccache = similar(SparseConnectivityTracer.jacobian_sparsity(brus_uf, du, u0, detector), Float64) const W = I - 1.0 * jaccache # setup sparse AD for Jacobian From 65d4204c73f425b0f9ac6d2a696046542c6496b3 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 9 Oct 2024 14:53:39 -0400 Subject: [PATCH 05/10] cleanup test warnings --- test/common_interface/cvode.jl | 4 ++-- test/common_interface/ida.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/common_interface/cvode.jl b/test/common_interface/cvode.jl index a40996c..a7b1e72 100644 --- a/test/common_interface/cvode.jl +++ b/test/common_interface/cvode.jl @@ -46,7 +46,7 @@ sol = solve(prob, CVODE_Adams(); saveat = saveat, save_everystep = false) @test sol.t == saveat for tstops in [0.9, [0.9]] - sol = solve(prob, CVODE_Adams(); tstops) + local sol = solve(prob, CVODE_Adams(); tstops) @test 0.9 ∈ sol.t end @@ -57,7 +57,7 @@ sol_idxs = solve(prob, CVODE_Adams(); save_idxs = [1], timeseries_errors = false sol_idxs = solve(prob, CVODE_Adams(); save_idxs = [1, 2], timeseries_errors = false, calculate_error = false) -@test length(sol_idxs[1]) == 2 +@test length(sol_idxs[:, 1]) == 2 @test sol[1, :] == sol_idxs[1, :] @test sol[2, :] == sol_idxs[2, :] diff --git a/test/common_interface/ida.jl b/test/common_interface/ida.jl index 7932c28..503e3ec 100644 --- a/test/common_interface/ida.jl +++ b/test/common_interface/ida.jl @@ -60,7 +60,7 @@ sol = solve(prob, IDA(); saveat = saveat, save_everystep = true) @test intersect(sol.t, saveat) == saveat @info "IDA with tstops" for tstops in [0.9, [0.9]] - sol = solve(prob, IDA(); tstops) + local sol = solve(prob, IDA(); tstops) @test 0.9 ∈ sol.t end From 6b025916da2699b2c8a95c27b800dd63cdfeeeb3 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 9 Oct 2024 17:37:27 -0400 Subject: [PATCH 06/10] fix depwarn --- test/common_interface/jacobians.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/common_interface/jacobians.jl b/test/common_interface/jacobians.jl index 482f174..3eadaaf 100644 --- a/test/common_interface/jacobians.jl +++ b/test/common_interface/jacobians.jl @@ -35,8 +35,7 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU)) @test Array(sol9) ≈ Array(good_sol) Lotka_fj = ODEFunction(Lotka; - jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2), - SciMLBase.NullParameters())) + jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2))) prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0)) sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES), saveat = 0.1, abstol = 1e-12, From c15979ac0a8f24c98be8c9af2de1dbde86859fe6 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 10 Oct 2024 05:42:49 -0400 Subject: [PATCH 07/10] Update test/common_interface/jacobians.jl --- test/common_interface/jacobians.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/common_interface/jacobians.jl b/test/common_interface/jacobians.jl index 3eadaaf..be19119 100644 --- a/test/common_interface/jacobians.jl +++ b/test/common_interface/jacobians.jl @@ -35,7 +35,8 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU)) @test Array(sol9) ≈ Array(good_sol) Lotka_fj = ODEFunction(Lotka; - jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2))) + jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2)), + SciMLBase.NullParameters()) prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0)) sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES), saveat = 0.1, abstol = 1e-12, From 3a024253982b6c9f2d786e94c68741a10a74c03b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 10 Oct 2024 05:43:09 -0400 Subject: [PATCH 08/10] Update test/common_interface/jacobians.jl --- test/common_interface/jacobians.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common_interface/jacobians.jl b/test/common_interface/jacobians.jl index be19119..406a9bb 100644 --- a/test/common_interface/jacobians.jl +++ b/test/common_interface/jacobians.jl @@ -36,7 +36,7 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU)) Lotka_fj = ODEFunction(Lotka; jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2)), - SciMLBase.NullParameters()) + SciMLBase.NullParameters())) prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0)) sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES), saveat = 0.1, abstol = 1e-12, From 2fc40e50f535d5f5f2804a94c5bdeaf6137451b6 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 10 Oct 2024 05:43:25 -0400 Subject: [PATCH 09/10] Update test/common_interface/jacobians.jl --- test/common_interface/jacobians.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common_interface/jacobians.jl b/test/common_interface/jacobians.jl index 406a9bb..482f174 100644 --- a/test/common_interface/jacobians.jl +++ b/test/common_interface/jacobians.jl @@ -35,7 +35,7 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU)) @test Array(sol9) ≈ Array(good_sol) Lotka_fj = ODEFunction(Lotka; - jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2)), + jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2), SciMLBase.NullParameters())) prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0)) From 1b85969e630b04765290704e006d5432e40a527b Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Thu, 10 Oct 2024 22:21:11 -0400 Subject: [PATCH 10/10] fix jacvec --- test/common_interface/jacobians.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/common_interface/jacobians.jl b/test/common_interface/jacobians.jl index 482f174..29f358b 100644 --- a/test/common_interface/jacobians.jl +++ b/test/common_interface/jacobians.jl @@ -35,8 +35,7 @@ sol9 = solve(prob, CVODE_BDF(; linear_solver = :KLU)) @test Array(sol9) ≈ Array(good_sol) Lotka_fj = ODEFunction(Lotka; - jac_prototype = JacVec((du, u) -> Lotka(du, u, (), 0.0), ones(2), - SciMLBase.NullParameters())) + jac_prototype = JacVec(Lotka, ones(2), SciMLBase.NullParameters(), 0.0)) prob = ODEProblem(Lotka_fj, ones(2), (0.0, 10.0)) sol9 = solve(prob, CVODE_BDF(; linear_solver = :GMRES), saveat = 0.1, abstol = 1e-12,