From 89c044243ec696b838078b479fa0d05efc22da1e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 25 Sep 2024 06:45:36 -0400 Subject: [PATCH 001/203] Fix imported threads This is used in a lot of benchmarks so it's a bit of help getting everything updated. --- src/OrdinaryDiffEq.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 503484ac33..f6578c3bde 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -58,7 +58,8 @@ import OrdinaryDiffEqCore: trivial_limiter!, CompositeAlgorithm, alg_order, _change_t_via_interpolation!, ODEIntegrator, _ode_interpolant!, current_interpolant, resize_nlsolver!, _ode_interpolant, handle_tstop!, _postamble!, update_uprev!, resize_J_W!, - DAEAlgorithm, get_fsalfirstlast, strip_cache + DAEAlgorithm, get_fsalfirstlast, strip_cache, + Sequential, BaseThreads, PolyesterThreads export CompositeAlgorithm, ShampineCollocationInit, BrownFullBasicInit, NoInit AutoSwitch From 44dce665292ce31d1cbc1d5fd9f77e4395fb5985 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Thu, 7 Nov 2024 17:16:01 +0100 Subject: [PATCH 002/203] Move informative error message up the call stack so it is hit --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index e88deeef1a..0d237e1f02 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -47,6 +47,10 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) + if !hasmethod(_initialize_dae!, (Any, typeof(integrator.sol.prob), + BrownFullBasicInit, Val)) + error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") + end _initialize_dae!(integrator, integrator.sol.prob, initializealg, Val(DiffEqBase.isinplace(integrator.sol.prob))) From 6a8547e77c74fc5b69c5e3e08528a747edeb0a75 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Fri, 8 Nov 2024 14:19:11 +0100 Subject: [PATCH 003/203] Make hasmethod check if BrownFullBasicInit is defined --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 0d237e1f02..46dfa94729 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -47,9 +47,10 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) - if !hasmethod(_initialize_dae!, (Any, typeof(integrator.sol.prob), - BrownFullBasicInit, Val)) - error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") + if !hasmethod(_initialize_dae!, (typeof(integrator), + typeof(integrator.sol.prob), BrownFullBasicInit, + Val{DiffEqBase.isinplace(integrator.sol.prob)})) + error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") end _initialize_dae!(integrator, integrator.sol.prob, initializealg, From 1a070a9e55c0a2935c809c8b039060d631a67a3f Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Wed, 13 Nov 2024 15:20:47 +0100 Subject: [PATCH 004/203] Add CheckInit error message --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 46dfa94729..9c905923b4 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -203,7 +203,17 @@ end function Base.showerror(io::IO, e::CheckInitFailureError) print(io, - "CheckInit specified but initialization not satisifed. normresid = $(e.normresid) > abstol = $(e.abstol)") + "DAE initialization failed: your u0 did not satisfy the initialization requirements, + normresid = $(e.normresid) > abstol = $(e.abstol). If you wish for the system to + automatically change the algebraic variables to satisfy the algebraic constraints, + please pass `initializealg = BrownBasicInit()` to solve (this option will require + `using OrdinaryDiffEqNonlinearSolve`). If you wish to perform an initialization on the + complete u0, please pass initializealg = ShampineCollocationInit() to solve. Note that + initialization can be a very difficult process for DAEs and in many cases can be + numerically intractable without symbolic manipulation of the system. For an automated + system that will generate numerically stable initializations, see ModelingToolkit.jl + structural simplification for more details." + ) end function _initialize_dae!(integrator, prob::ODEProblem, alg::CheckInit, From 17b35afd5fb479feb6ca5d3f791efd97ddef6965 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Wed, 13 Nov 2024 15:21:57 +0100 Subject: [PATCH 005/203] Swap BrownFullBasicInit for CheckInit --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 9c905923b4..ccb2db0a7f 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -66,7 +66,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, OverrideInit(integrator.opts.abstol), x) else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) end end @@ -77,7 +77,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, OverrideInit(integrator.opts.abstol), x) else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) end end @@ -91,7 +91,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, ShampineCollocationInit(), x) else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) end end @@ -105,7 +105,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, ShampineCollocationInit(), x) else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) end end From afd385b2f24c5761a4f5201a1b173f467cd9bab7 Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Mon, 2 Dec 2024 16:24:39 -0500 Subject: [PATCH 006/203] changes --- lib/OrdinaryDiffEqFIRK/src/controllers.jl | 11 ++++-- lib/OrdinaryDiffEqFIRK/src/firk_caches.jl | 38 +++++++++++++++++-- .../src/firk_perform_step.jl | 8 ++-- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/src/controllers.jl b/lib/OrdinaryDiffEqFIRK/src/controllers.jl index 3849d8114c..cf38a16c48 100644 --- a/lib/OrdinaryDiffEqFIRK/src/controllers.jl +++ b/lib/OrdinaryDiffEqFIRK/src/controllers.jl @@ -1,7 +1,7 @@ function step_accept_controller!(integrator, controller::PredictiveController, alg::AdaptiveRadau, q) @unpack qmin, qmax, gamma, qsteady_min, qsteady_max = integrator.opts @unpack cache = integrator - @unpack num_stages, step, iter, hist_iter = cache + @unpack num_stages, step, iter, hist_iter, index = cache EEst = DiffEqBase.value(integrator.EEst) @@ -25,12 +25,14 @@ function step_accept_controller!(integrator, controller::PredictiveController, a max_stages = (alg.max_order - 1) ÷ 4 * 2 + 1 min_stages = (alg.min_order - 1) ÷ 4 * 2 + 1 if (step > 10) - if (hist_iter < 2.6 && num_stages <= max_stages) + if (hist_iter < 2.6 && num_stages < max_stages) cache.num_stages += 2 + cache.index += 1 cache.step = 1 cache.hist_iter = iter - elseif ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages >= min_stages) + elseif ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages > min_stages) cache.num_stages -= 2 + cache.index -= 1 cache.step = 1 cache.hist_iter = iter end @@ -48,8 +50,9 @@ function step_reject_controller!(integrator, controller::PredictiveController, a cache.hist_iter = hist_iter min_stages = (alg.min_order - 1) ÷ 4 * 2 + 1 if (step > 10) - if ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages >= min_stages) + if ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages > min_stages) cache.num_stages -= 2 + cache.index -= 1 cache.step = 1 cache.hist_iter = iter end diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl index fb773cf4b0..d214c9f63f 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl @@ -497,6 +497,7 @@ mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} <: num_stages::Int step::Int hist_iter::Float64 + index::Int end function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -518,7 +519,11 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} num_stages = min tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - i = 9 + if (min == 3 || min == 5 || min == 7) + i = 9 + else + i = min + end while i <= max push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) i += 2 @@ -528,10 +533,20 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} cont[i] = zero(u) end + if (min == 3) + index = 1 + elseif (min == 5) + index = 2 + elseif (min == 7) + index = 3 + else + index = 4 + end + κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) J = false .* _vec(rate_prototype) .* _vec(rate_prototype)' AdaptiveRadauConstantCache(uf, tabs, κ, one(uToltype), 10000, cont, dt, dt, - Convergence, J, num_stages, 1, 0.0) + Convergence, J, num_stages, 1, 0.0, index) end mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type, @@ -578,6 +593,7 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, num_stages::Int step::Int hist_iter::Float64 + index::Int end function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -599,12 +615,26 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} num_stages = min tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - i = 9 + if (min == 3 || min == 5 || min == 7) + i = 9 + else + i = min + end while i <= max push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) i += 2 end + if (min == 3) + index = 1 + elseif (min == 5) + index = 2 + elseif (min == 7) + index = 3 + else + index = 4 + end + κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) z = Vector{typeof(u)}(undef, max) @@ -677,6 +707,6 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} uf, tabs, κ, one(uToltype), 10000, tmp, atmp, jac_config, linsolve1, linsolve2, rtol, atol, dt, dt, - Convergence, alg.step_limiter!, num_stages, 1, 0.0) + Convergence, alg.step_limiter!, num_stages, 1, 0.0, index) end diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl index 2058c4fb15..a85b63fb00 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl @@ -1354,8 +1354,8 @@ end @muladd function perform_step!(integrator, cache::AdaptiveRadauConstantCache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tabs, num_stages = cache - tab = tabs[(num_stages - 1) ÷ 2] + @unpack tabs, num_stages, index = cache + tab = tabs[index] @unpack T, TI, γ, α, β, c, e = tab @unpack κ, cont = cache @unpack internalnorm, abstol, reltol, adaptive = integrator.opts @@ -1595,8 +1595,8 @@ end @muladd function perform_step!(integrator, cache::AdaptiveRadauCache, repeat_step = false) @unpack t, dt, uprev, u, f, p, fsallast, fsalfirst = integrator - @unpack num_stages, tabs = cache - tab = tabs[(num_stages - 1) ÷ 2] + @unpack num_stages, tabs, index = cache + tab = tabs[index] @unpack T, TI, γ, α, β, c, e = tab @unpack κ, cont, derivatives, z, w, c_prime, αdt, βdt= cache @unpack dw1, ubuff, dw2, cubuff, dw = cache From c0698983d943b4f97073ee1928f2c428f82da8ad Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Tue, 3 Dec 2024 07:52:52 -0500 Subject: [PATCH 007/203] renaming --- lib/OrdinaryDiffEqFIRK/src/firk_caches.jl | 90 +++++++------------ .../test/ode_high_order_firk_tests.jl | 2 +- 2 files changed, 34 insertions(+), 58 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl index d214c9f63f..39c647f508 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl @@ -509,39 +509,27 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} max_order = alg.max_order min_order = alg.min_order - max = (max_order - 1) ÷ 4 * 2 + 1 - min = (min_order - 1) ÷ 4 * 2 + 1 + max_stages = (max_order - 1) ÷ 4 * 2 + 1 + min_stages = (min_order - 1) ÷ 4 * 2 + 1 if (alg.min_order < 5) error("min_order choice $min_order below 5 is not compatible with the algorithm") - elseif (max < min) + elseif (max_stages < min_stages) error("max_order $max_order is below min_order $min_order") end - num_stages = min + num_stages = min_stages tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - if (min == 3 || min == 5 || min == 7) - i = 9 - else - i = min - end - while i <= max + i = max(min_stages, 9) + while i <= max_stages push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) i += 2 end - cont = Vector{typeof(u)}(undef, max) - for i in 1:max + cont = Vector{typeof(u)}(undef, max_stages) + for i in 1:max_stages cont[i] = zero(u) end - if (min == 3) - index = 1 - elseif (min == 5) - index = 2 - elseif (min == 7) - index = 3 - else - index = 4 - end + index = min((min_stages - 1) ÷ 2, 4) κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) J = false .* _vec(rate_prototype) .* _vec(rate_prototype)' @@ -605,70 +593,58 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} max_order = alg.max_order min_order = alg.min_order - max = (max_order - 1) ÷ 4 * 2 + 1 - min = (min_order - 1) ÷ 4 * 2 + 1 + max_stages = (max_order - 1) ÷ 4 * 2 + 1 + min_stages = (min_order - 1) ÷ 4 * 2 + 1 if (alg.min_order < 5) error("min_order choice $min_order below 5 is not compatible with the algorithm") - elseif (max < min) + elseif (max_stages < min_stages) error("max_order $max_order is below min_order $min_order") end - num_stages = min + num_stages = min_stages tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - if (min == 3 || min == 5 || min == 7) - i = 9 - else - i = min - end - while i <= max + i = max(min_stages, 9) + while i <= max_stages push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) i += 2 end - if (min == 3) - index = 1 - elseif (min == 5) - index = 2 - elseif (min == 7) - index = 3 - else - index = 4 - end + index = min((min_stages - 1) ÷ 2, 4) κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) - z = Vector{typeof(u)}(undef, max) - w = Vector{typeof(u)}(undef, max) - for i in 1 : max + z = Vector{typeof(u)}(undef, max_stages) + w = Vector{typeof(u)}(undef, max_stages) + for i in 1 : max_stages z[i] = zero(u) w[i] = zero(u) end - αdt = [zero(t) for i in 1:max] - βdt = [zero(t) for i in 1:max] - c_prime = Vector{typeof(t)}(undef, max) #time stepping - for i in 1 : max + αdt = [zero(t) for i in 1:max_stages] + βdt = [zero(t) for i in 1:max_stages] + c_prime = Vector{typeof(t)}(undef, max_stages) #time stepping + for i in 1 : max_stages c_prime[i] = zero(t) end dw1 = zero(u) ubuff = zero(u) - dw2 = [similar(u, Complex{eltype(u)}) for _ in 1 : (max - 1) ÷ 2] + dw2 = [similar(u, Complex{eltype(u)}) for _ in 1 : (max_stages - 1) ÷ 2] recursivefill!.(dw2, false) - cubuff = [similar(u, Complex{eltype(u)}) for _ in 1 : (max - 1) ÷ 2] + cubuff = [similar(u, Complex{eltype(u)}) for _ in 1 : (max_stages - 1) ÷ 2] recursivefill!.(cubuff, false) - dw = [zero(u) for i in 1 : max] + dw = [zero(u) for i in 1:max_stages] - cont = [zero(u) for i in 1:max] + cont = [zero(u) for i in 1:max_stages] - derivatives = Matrix{typeof(u)}(undef, max, max) - for i in 1 : max, j in 1 : max + derivatives = Matrix{typeof(u)}(undef, max_stages, max_stages) + for i in 1 : max_stages, j in 1 : max_stages derivatives[i, j] = zero(u) end fsalfirst = zero(rate_prototype) - fw = [zero(rate_prototype) for i in 1 : max] - ks = [zero(rate_prototype) for i in 1 : max] + fw = [zero(rate_prototype) for i in 1 : max_stages] + ks = [zero(rate_prototype) for i in 1 : max_stages] k = ks[1] @@ -677,7 +653,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} error("Non-concrete Jacobian not yet supported by AdaptiveRadau.") end - W2 = [similar(J, Complex{eltype(W1)}) for _ in 1 : (max - 1) ÷ 2] + W2 = [similar(J, Complex{eltype(W1)}) for _ in 1 : (max_stages - 1) ÷ 2] recursivefill!.(W2, false) du1 = zero(rate_prototype) @@ -695,7 +671,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} linsolve2 = [ init(LinearProblem(W2[i], _vec(cubuff[i]); u0 = _vec(dw2[i])), alg.linsolve, alias_A = true, alias_b = true, - assumptions = LinearSolve.OperatorAssumptions(true)) for i in 1 : (max - 1) ÷ 2] + assumptions = LinearSolve.OperatorAssumptions(true)) for i in 1 : (max_stages - 1) ÷ 2] rtol = reltol isa Number ? reltol : zero(reltol) atol = reltol isa Number ? reltol : zero(reltol) diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl index b78c50f7f1..5f0efa71f8 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl @@ -7,7 +7,7 @@ testTol = 0.5 prob_ode_linear_big = remake(prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), tspan = big.(prob_ode_2Dlinear.tspan)) -for i in [17, 21], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] +for i in [17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] dts = 1 ./ 2 .^ (4.25:-1:0.25) sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i)) @test sim21.𝒪est[:final]≈ i atol=testTol From e9eedf826ae0ac0bc35c733f1f28202fa2b4d9e6 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Tue, 3 Dec 2024 14:23:02 +0100 Subject: [PATCH 008/203] Unify methods so that CheckInit is default for all cases --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 50 ++------------------ 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 4e156175c0..d949377159 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -37,11 +37,6 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) - if !hasmethod(_initialize_dae!, (typeof(integrator), - typeof(integrator.sol.prob), BrownFullBasicInit, - Val{DiffEqBase.isinplace(integrator.sol.prob)})) - error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") - end _initialize_dae!(integrator, integrator.sol.prob, initializealg, Val(DiffEqBase.isinplace(integrator.sol.prob))) @@ -49,50 +44,13 @@ end ## Default algorithms -function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Val{true}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - else - _initialize_dae!(integrator, prob, - CheckInit(), x) - end -end - -function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Val{false}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - else - _initialize_dae!(integrator, prob, - CheckInit(), x) - end -end - -function _initialize_dae!(integrator, prob::DAEProblem, - alg::DefaultInit, x::Val{false}) +function _initialize_dae!(integrator, + prob::Union{ODEProblem, DAEProblem}, + alg::DefaultInit, + x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif prob.differential_vars === nothing - _initialize_dae!(integrator, prob, - ShampineCollocationInit(), x) - else - _initialize_dae!(integrator, prob, - CheckInit(), x) - end -end - -function _initialize_dae!(integrator, prob::DAEProblem, - alg::DefaultInit, x::Val{true}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - elseif prob.differential_vars === nothing - _initialize_dae!(integrator, prob, - ShampineCollocationInit(), x) else _initialize_dae!(integrator, prob, CheckInit(), x) From 555369b308de78a58256f4fcba1409cc92224f5c Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Tue, 3 Dec 2024 14:23:21 +0100 Subject: [PATCH 009/203] Export BrownFullBasicInit and ShampineCollocationInit --- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 593f27ee77..659278af97 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -64,4 +64,6 @@ include("functional.jl") include("newton.jl") include("initialize_dae.jl") +export BrownFullBasicInit, ShampineCollocationInit + end From 51cf004e884124985b30ea2b323ec2f08fdf4a42 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Tue, 3 Dec 2024 19:00:51 -0500 Subject: [PATCH 010/203] don't use Rosenbrock23 with mass matrix --- lib/OrdinaryDiffEqDefault/src/default_alg.jl | 2 +- lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDefault/src/default_alg.jl b/lib/OrdinaryDiffEqDefault/src/default_alg.jl index 9347a6192c..9f0fb62e69 100644 --- a/lib/OrdinaryDiffEqDefault/src/default_alg.jl +++ b/lib/OrdinaryDiffEqDefault/src/default_alg.jl @@ -81,7 +81,7 @@ function stiffchoice(reltol, len, mass_matrix) elseif len > SMALLSIZE DefaultSolverChoice.FBDF else - if reltol < LOW_TOL || !isdiag(mass_matrix) + if reltol < LOW_TOL || mass_matrix != I DefaultSolverChoice.Rodas5P else DefaultSolverChoice.Rosenbrock23 diff --git a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl index c434bc80ab..c62ff80880 100644 --- a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl +++ b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl @@ -108,7 +108,7 @@ end f = ODEFunction(rober_mm, mass_matrix = [1 0 0; 0 1 0; 0 0 0]) prob_rober_mm = ODEProblem(f, [1.0, 0.0, 1.0], (0.0, 1e5), (0.04, 3e7, 1e4)) sol = solve(prob_rober_mm) -@test all(isequal(3), sol.alg_choice) +@test all(isequal(4), sol.alg_choice) @test sol(0.5) isa Vector{Float64} # test dense output # test callback on ConstantCache (https://github.com/SciML/OrdinaryDiffEq.jl/issues/2287) From f0690e65ea947c2f8e72e6c75db61700810ad6ff Mon Sep 17 00:00:00 2001 From: Gerd Steinebach <64948537+gstein3m@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:50:28 +0100 Subject: [PATCH 011/203] Update generic_rosenbrock.jl references References corrected --- .../src/generic_rosenbrock.jl | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl index 74a0ad57c6..1b9ff7a936 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/generic_rosenbrock.jl @@ -950,8 +950,9 @@ An Order 2/3 L-Stable Rosenbrock-W method for stiff ODEs and DAEs in mass matrix """, "Rodas23W", references = """ -- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate for dense output and Julia implementation, - In progress. +- Steinebach G., Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications - + Preprint 2024 + https://github.com/hbrs-cse/RosenbrockMethods/blob/main/paper/JuliaPaper.pdf """, with_step_limiter = true) Rodas23W @@ -1035,9 +1036,8 @@ references = """ """, "Rodas3", references = """ -- Steinebach G. Construction of Rosenbrock–Wanner method Rodas5P and numerical benchmarks - within the Julia Differential Equations package. - In: BIT Numerical Mathematics, 63(2), 2023 +- Sandu, Verwer, Van Loon, Carmichael, Potra, Dabdub, Seinfeld, Benchmarking stiff ode solvers for atmospheric chemistry problems-I. + implicit vs explicit, Atmospheric Environment, 31(19), 3151-3166, 1997. """, with_step_limiter=true) Rodas3 @@ -1048,9 +1048,9 @@ and additional error test for interpolation. Keeps accuracy on discretizations o """, "Rodas3P", references = """ -- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate - for dense output and Julia implementation, - In progress. +- Steinebach G., Rosenbrock methods within OrdinaryDiffEq.jl - Overview, recent developments and applications - + Preprint 2024 + https://github.com/hbrs-cse/RosenbrockMethods/blob/main/paper/JuliaPaper.pdf """, with_step_limiter=true) Rodas3P @@ -1096,9 +1096,10 @@ lower if not corrected). """, "Rodas4P", references = """ -- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate - for dense output and Julia implementation, - In progress. +- Steinebach, G., Rentrop, P., An adaptive method of lines approach for modelling flow and transport in rivers. + Adaptive method of lines , Wouver, A. Vande, Sauces, Ph., Schiesser, W.E. (ed.),S. 181-205,Chapman & Hall/CRC, 2001, +- Steinebach, G., Oder-reduction of ROW-methods for DAEs and method of lines applications. + Preprint-Nr. 1741, FB Mathematik, TH Darmstadt, 1995. """, with_step_limiter=true) Rodas4P @@ -1110,9 +1111,8 @@ of Roadas4P and in case of inexact Jacobians a second order W method. """, "Rodas4P2", references = """ -- Steinebach G., Rodas23W / Rodas32P - a Rosenbrock-type method for DAEs with additional error estimate - for dense output and Julia implementation, - In progress. +- Steinebach G., Improvement of Rosenbrock-Wanner Method RODASP, In: Reis T., Grundel S., Schöps S. (eds) + Progress in Differential-Algebraic Equations II. Differential-Algebraic Equations Forum. Springer, Cham., 165-184, 2020. """, with_step_limiter=true) Rodas4P2 @@ -1143,8 +1143,7 @@ with_step_limiter=true) Rodas5P @doc rosenbrock_wolfbrandt_docstring( """ -A 5th order A-stable stiffly stable Rosenbrock method with a stiff-aware 4th order interpolant. -Has improved stability in the adaptive time stepping embedding. +Variant of Ropdas5P with additional residual control. """, "Rodas5Pr", references = """ @@ -1156,8 +1155,7 @@ with_step_limiter=true) Rodas5Pr @doc rosenbrock_wolfbrandt_docstring( """ -A 5th order A-stable stiffly stable Rosenbrock method with a stiff-aware 4th order interpolant. -Has improved stability in the adaptive time stepping embedding. +Variant of Ropdas5P with modified embedded scheme. """, "Rodas5Pe", references = """ From 2d0664ea6b8f58d6ce5fcb1e14a50587de224003 Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Wed, 4 Dec 2024 19:45:36 -0500 Subject: [PATCH 012/203] cache tableaus --- lib/OrdinaryDiffEqFIRK/src/firk_caches.jl | 18 +- lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl | 261 ++------------------ 2 files changed, 20 insertions(+), 259 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl index 39c647f508..f9da99a448 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl @@ -518,18 +518,13 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} end num_stages = min_stages - tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - i = max(min_stages, 9) - while i <= max_stages - push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) - i += 2 - end + tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) for i in min_stages:2:max_stages] cont = Vector{typeof(u)}(undef, max_stages) for i in 1:max_stages cont[i] = zero(u) end - index = min((min_stages - 1) ÷ 2, 4) + index = 1 κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) J = false .* _vec(rate_prototype) .* _vec(rate_prototype)' @@ -602,14 +597,9 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} end num_stages = min_stages - tabs = [RadauIIATableau5(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau9(uToltype, constvalue(tTypeNoUnits)), RadauIIATableau13(uToltype, constvalue(tTypeNoUnits))] - i = max(min_stages, 9) - while i <= max_stages - push!(tabs, RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i)) - i += 2 - end + tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) for i in min_stages:2:max_stages] - index = min((min_stages - 1) ÷ 2, 4) + index = 1 κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100) diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl b/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl index 7191eabdb2..398d8445e9 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl @@ -269,256 +269,23 @@ struct RadauIIATableau{T1, T2} e::Vector{T1} end -function RadauIIATableau5(T1, T2) - γ = convert(T1, big"3.63783425274449573220841851357777579794593608687391153215117488565841871456727143375130115708511223004183651123208497057248238260532214672028700625775335843") - α = T1[big"2.68108287362775213389579074321111210102703195656304423392441255717079064271636428312434942145744388497908174438395751471375880869733892663985649687112332242"] - β = T2[big"3.05043019924741056942637762478756790444070419917947659226291744751211727051786694870515117615266028855554735929171362769761399150862332538376382934625577549"] - - c = T2[big"0.155051025721682190180271592529410860803405251934332987156730743274903962254268497346014056689535976518140539877338581087514113454016224265837421604876272084", - big"0.644948974278317809819728407470589139196594748065667012843269256725096037745731502653985943310464023481859460122661418912485886545983775734162578395123729143", - 1] - - e = T1[big"-10.0488093998274155624603295076470799145872107881988969663429493235855742140670683952596720105774938812433874028620997746246706860729547671304601625528869782", - big"1.38214273316074889579366284098041324792054412153223029967628265691890754740040172859300534391082721457672073619543310795800401940628810046379349588622031217", - -1//3] - - TI = Matrix{T1}(undef, 3, 3) - TI[1, 1] = big"4.32557989006315535102435095295614882731995158490590784287320458848019483341979047442263696495019938973156007686663488090615420049217658854859024016717169837" - TI[1, 2] = big"0.339199251815809869542824974053410987511771566126056902312311333553438988409693737874718833892037643701271502187763370262948704203562215007824701228014200056" - TI[1, 3] = big"0.541770539935874871186523033492089631898841317849243944095021379289933921771713116368931784890546144473788347538203807242114936998948954098533375649163016612" - TI[2, 1] = big"-4.17871859155190472734646265851205623000038388214686525896709481539843195209360778128456932548583273459040707932166364293012713818843609182148794380267482041" - TI[2, 2] = big"-0.327682820761062387082533272429616234245791838308340887801415258608836530255609335712523838667242449344879454518796849992049787172023800373390124427898159896" - TI[2, 3] = big"0.476623554500550451960069084091012497939942928625055897109833707684876604712862299049343675491204859381277636585708398915065951363736337328178192801074535132" - TI[3, 1] = big"-0.502872634945786875951247343139544292859248429570937886791036339034110181540695221500843782634464164585836226038438397328726973424362168221527501738985822875" - TI[3, 2] = big"2.57192694985560542918678535360167505469448742842178326395573566888176471664393761903447163100353067504020263109067033226021288356347565113471227052083596358" - TI[3, 3] = big"-0.596039204828224924968821911099302403289857517521591823052174732952989090998130905722763344484798508456930766594977798579939415052669401095404149917833710127" - - T = Matrix{T1}(undef, 3, 3) - T[1, 1] = big"0.091232394870892942791548135249436196118684699372210280712184363514099824021240149574725365814781580305065489937969163922775110463056339192206701819661425186" - T[1, 2] = big"-0.141255295020954208427990383807797309409263248498594798844289981408804297900674604638610419147468875667691398225003133444988034605081071965848437945842767211" - T[1 ,3] = big"-0.0300291941051474244918611170890538666683842974606300802563717702200388818691214144173874588956764952224874407424115249418136547481236684478531215095064078994" - T[2, 1] = big"0.241717932707107018957474779310148232884879540532595279746187345714229132659465207414913313803429072060469564350914390845001169448350326344874859416624577348" - T[2, 2] = big"0.204129352293799931995990810298338174086540402523315938937516234649384944528706774788799548853122282827246947911905379230680096946800308693162079538975632443" - T[2, 3] = big"0.382942112757261937795438233599873210357792575012007744255205163027042915338009760005422153613194350161760232119048691964499888989151661861236831969497483828" - T[3, 1] = big"0.966048182615092936190567080794590794996748754810883844283183333914131408744555961195911605614405476210484499875001737558078500322423463946527349731087504518" - T[3, 2] = 1 - T[3, 3] = 0 - RadauIIATableau{T1, T2}(T, TI, - c, γ, α, β, e) -end - -function RadauIIATableau9(T1, T2) - γ = convert(T1, big"6.28670475172927664517315334186940904959068186655567041187229167532923622489525703260842273089261139845280626287956099768662193453067483410165932355981736786") - - α = T1[big"3.65569432546357225824320796009543385435699888857815445045567025741630720509235614026228963385258117304229337679733945535812317372403535763551850772878775217", - big"5.70095329867178941917021536896986162084766017814401034360818390491907468246001534343349900070111312773130349176288004579856585901062722531365183049130382405"] - β = T1[big"6.5437368993600772940210715093936863183637851728134458820202187133882261290012752452972782843700946890488789462524897903624959996932392239962196563965573345", - big"3.21026560030854988842501065297211721232153653493981008029923647488964744732168461657389754087826565709085773529539707072244537983491480773006949966789260925"] - - c = T2[big"0.0571041961145176821931211925541156212350779455987501643278082929309346782020731645861138168198427368635148018903413155731609901559772929443100370500757072557", - big"0.276843013638123827680045997685625141110889169695030468349442048831121339683708036772541528564051130879197377136636984534220758899839905855114024309075271826", - big"0.583590432368916820056697668662917248693432639896771640176293841831747501961831012005632277467456299345321045569611992496682381919275766424103024358378365496", - big"0.8602401356562194478479129188751197667383780225872255049242335941839742579301655644134901549264276106897445531811874851737136468026848125542506920602484255", - 1.0] - - e = T1[big"-27.7809339440646373047872078172168798923674228687740760060378492475924178050505976287227228556471699142365371740120443650701118024100678675823465762727483305", - big"3.64147849804921315271165508774289722904088750334220956841022786858917594981395319605788667956024462601802006251583142928630101075351336314632135787805261686", - big"-1.25254772116911872049065249430114914889315244289570569309128740586057170336299694248256681515155624683225624015343224399700466177251702555220815764199263189", - big"0.592003167184542872566205223775131812219687808327572130718908784863813558599641375147402991238481535050773351649645179780815453429071529988233376036688329872", - -1//5] - - TI = Matrix{T1}(undef, 5, 5) - TI[1, 1] = big"30.0415677215444016277146611632467970747634862837368422955138470463852339244593400023985957753164599415374157317627305099177616927640413043608408838747985125" - TI[1, 2] = big"13.8651078562714131651762946846279728486098595017962436746405940971751244384714668104145151259298432908422191238542910724677205181071665482818120092330632702" - TI[1 ,3] = big"3.48000277479518556182840016971955819123081637245954095062693470191383865922357339844125383481645392882289968250993872221445874555610460465838129969397069557" - TI[1, 4] = big"-1.03200879782526342277108071214631493513824682491749273908106331923801396656058254294323988505859654767877050109789490714699847664805679842903430004696170252" - TI[1, 5] = big"0.804303045073989917475330383606196086089578671788707543063308602519859970319818304759856653218877415405946945572102875643297890954688508528143272905631829894" - TI[2, 1] = big"5.34418643783491159889531030409736033885455686563071401172022718575590068536629704134603404624953791012861634674294690788961703408019660066685859393456498931" - TI[2, 2] = big"4.59361556775916100445407449817656238428260055301676371438973411021009514435572975394999086474831271997070798032181411537895658457000537727156665947774751386" - TI[2, 3] = big"-3.03636032345942429864615756872018980250277648141683630832856906288036929718223473102394179699607901856890769270810252103326382063852039607285826867723587514" - TI[2, 4] = big"1.05066019023145886385983615715299311307615150447133905233370933194949591737765763708886464382722316727972166443876395823044171403663404254906698768838255919" - TI[2, 5] = big"-0.272778611864296270538614649997366804891835224042737605275699398413256470423268908248569612750117948720141667949532252500428432062582365619208502333677907158" - TI[3, 1] = big"3.74805980743980486005103450189256983678052751095791526209741655305580351377124372457009580386663275146166007984852101733055495783906881063060757645038080343" - TI[3, 2] = big"-3.98496573634388466725226385805351110838575115293851360514636734529255361185420464416807882769853298186283398369873418552760618971047757002216338511286260041" - TI[3, 3] = big"-1.04441564160801879294224732309562532189841624726401645191058551173485917137499204844819781779667611903670073971659834929382224472890100209497741235960707456" - TI[3, 4] = big"1.18409856813794848723102038838340482030291345603197522521517834943166421242518751666675199211369552058487095283489346390066317584532997854692445653563909898" - TI[3, 5] = big"-0.449917770156780368898811918314095435942113881883174152777026977062686286863549565130412864190301081537983106397709991028107600781961279985605930655683680139" - TI[4, 1] = big"-33.0418802135190000080614469426109507742858088371383868670878639187564531424382858814386742148456699143328462132296293097447566408853495288807407929988004676" - TI[4, 2] = big"-17.3769534790635670194549806058987105852733409102703844354448800193942184746909147697382687117638715195698950138089979798321855885541817752366521518811413713" - TI[4, 3] = big"-0.172129063254005561151528806427751383749451500597823574207174433146207178559871803504021077429693091164540897873472803934375603405253541639437370184767553293" - TI[4, 4] = big"-0.0991697779825426425881662214017368584726354746776989845479783944003623924121748016326495070834800297497011104846871751430208559227945252758721362340763610828" - TI[4, 5] = big"0.531228115838306667184911422606024795426589562580669892779793097035561488973256023529352389498509937781553683467106048413485632583844632286562240161995145055" - TI[5, 1] = big"-8.61144397987529197770008251257034851950485933115010902789613925540488896812417081206983938638600226846804467531843522104806738090683710882069500386691775154" - TI[5, 2] = big"9.69999140952880823133589405342003266497120753048627084327055311528684684237122654108691149692242002085965723391934376924400492239317026460192827344970015484" - TI[5, 3] = big"1.91472863969687428485137560339172471528025297511003983469957355306260543484472462223194401768126877615795915146192537091374017807611943419264038682143890747" - TI[5, 4] = big"2.41869200608494002642656343408298350771199306961305597858229870375990977712805399625496435641846363295393762353024017195444763964531237381728801981679934304" - TI[5, 5] = big"-1.0474634879353374186944329992117360176590042540536055452919974336199826846201614544718272622833822842591012529895091659029452542118642301415759073410771819" - - T = Matrix{T1}(undef, 5, 5) - T[1, 1] = big"0.0125175862205010458901356760368001462557655123420858705973577952199246108029451084239310924615007306721702298573083400752464277227557045438770401832498107968" - T[1, 2] = big"-0.0102420478179088270700863300668590125015813934827825923708366359399562125950804289592272678367034071306578383319296130180550178248531589487456925441921649293" - T[1 ,3] = big"0.0476738772902957238631839478592069782970238490568258436986723993118380988311441474394156362952631834786373081794857384127209450988829840886524135970873769918" - T[1, 4] = big"-0.0114785152552295147079415554121555049385506204591245712490409384029671974157542450636658532835395855844059342442518520033304129991000509527123870917346017759" - T[1, 5] = big"-0.0140198588928754102810778942934959307831026572823203692568448424056201483917805257790275956734469193171917730378117501915144713896813544630288006687542182225" - T[2, 1] = big"0.00149167015189538242900444775236282223594625052328927847572623038484966999313257893341818287477809424303168766872838075463220122499449382436194198620498144296" - T[2, 2] = big"0.050172864517371058162991380262646513853120568882725793734131676894272706020317186004736779675826101816279321643304301437029912742375638648226701787880031719" - T[2, 3] = big"-0.0943318191816114369806569003363724471884924328367212069321438749304281980331334016578193750445513659941246363262225907407726099492713722343006925656625258579" - T[2, 4] = big"-0.00766883074918016288515687679203608074116106558796378201472238095295554979920808799930579174190884587422912077296093093698836937450535804218413704866981728518" - T[2, 5] = big"0.024708578426518526812525205377780382655366504554979744093019395818934704623702078004474076773426928900579988063099593288435684744957695210778788200213260272" - T[3, 1] = big"0.072981876388087148622657299703669587832652508881663282287850495621401398441897288250625556038835308015912409648841893161563884759791665776933761278383553608" - T[3, 2] = big"-0.230539534043417946721421862180000422679228296568599014834226319726930529322581417981617275287468418138394077987361681288909676234537699721082090802790143303" - T[3, 3] = big"0.102703045380125899792210456947141185148813233939327773583525878521508211077874610560448598369259541346968946573971195783374996178436435357335759255990489434" - T[3, 4] = big"0.0193984639988289509112232896408330872285824216708905773930244363652651247181543158008567311548336143384128605013911312875018664026371225431993252265128272262" - T[3, 5] = big"0.0818003537037511708363908122287572533071340646031113975848869261019231448226334426630664318901554550460201409321555775999869184033436795623062614812355590017" - T[4, 1] = big"0.380091440003568104126439184355215575526619121262253024859378518379910007234696730891540745160675744992320824590679292148769326540463161583672773762554445506" - T[4, 2] = big"0.377893902248861249543862293745933995234687511602719536459666284734445918178134851270924212812363352965391508894581698067329905034837778770261095647458874628" - T[4, 3] = big"0.466744130332494359289559582964906703283968612669234331018678042733321473730897217606173184300477207393539851157929838664168404778962779344509707214938022808" - T[4, 4] = big"0.40760117128019906662166237021895987274626181127101561893104166874567447589187790736078997321464949349935802836110699884016973990503134772720646054039223561" - T[4, 5] = big"0.199682427886802525936540566022390695167018315867216115995143539347975271751460199398235415129329119718414206048034051939441434136353381864781262773401023899" - T[5, 1] = big"0.921978973681210488488254647415676321266345412943047462855852351388222898143904205962703147998267738964059170225806964893009202287585991334322032058414768529" - T[5, 2] = 1 - T[5, 3] = 0 - T[5, 4] = 1 - T[5, 5] = 0 +import LinearAlgebra: eigen +import FastGaussQuadrature: gaussradau - RadauIIATableau{T1, T2}(T, TI, - c, γ, α, β, e) +function RadauIIATableau{T1, T2}(tab::RadauIIATableau{T1, T2}) where {T1, T2} + RadauIIATableau{T1, T2}(tab.T, tab.TI, tab.c, tab.γ,tab.α, tab.β, tab.e) end -function RadauIIATableau13(T1, T2) - γ = convert(T1, big"8.93683278840521633730209691330107970355008194433956657198414191417624969654351559268800871286734194720118970058657997472527299153742511021973612156231867783") - α = T1[big"4.37869356150680600252334919268856129165763746518197948235657247177701087073069907016715245914093899486193202405685779803686971216417800783050995450529391908", - big"7.14105521918764010577498142571556804318193862372238812855726792587872300446315860222917039505087745633962330233504078264632719519730762016919715839787116038", - big"8.51183482510294572305062092494533081338538293892584910309408864525614127653438453125967278937451257519784982331481143195416659686980181689042482631568989031"] - β = T1[big"10.1696932837950116273183544188477298930096536824510223588525334625762336174947183926243705927725260475934351162622185429326813205432867247703480391692806137", - big"6.62304592263927597062055811591186110468148199066707542227575094761515104946479159063603447729283770429494038962408904312215452856333028405675512985803584472", - big"3.2810136243250588300359425270393915846791621918405321383787427650552081712406957205287551182809705166989352673500472974040971593568323836675590314648604458"] - - c = T2[big"0.0293164271597848919720502769131649103737303925637149277869106839449360382416657787486309483651843695097273923248526200112627747993405898353736305552306269904", - big"0.148078599668484291849976852495979212230248774808594461412594641801598386090878321806369397661747576057906341132861865305306667654594593138746653233717241913", - big"0.336984690281154299097052972080775705197568750028473347122562968073691350512784060852409141173654482529393236826516171319486086447256539582972346127980810124", - big"0.558671518771550132081393341805521940074368288965407825555747226117350122897421078323820052012282581935200398463518265914564420109615277886000739200777932339", - big"0.769233862030054500916883360115645451837142143322295416166948169636548130573953285685200211542774367652885154701431860087378103033801830280742146083476036669", - big"0.926945671319741114851873965819682011056172419542283252724467079656645202452528243814339480013587391545656707320049986592771178724621938506933715568048004783", - 1] - - e = T1[big"-54.374436894128614514583710369683221528326818668136315170227649609831132483812209590903458627819914413600703287942266678601263304348350182019714004102122958", - big"7.00002400425918651204068363735192307633403862621907697222411411256593188888314837387690262103761082115674234000933589934965063951414231971808906314491204573", - big"-2.35566109198755719225604586775720723211163199654640573606711168106849118084357027539414093812951288166804790294091903523762277368547775099880612390898224076", - big"1.13228906610613438638449290827978318662460499026070073842612187085281352278780837966549916347601259689966925986653914736463076068138934273474363230390185871", - big"-0.646891326767358711867345222439989069591870662562921671446738173180691199552327090727940249497816198076028398716990245669520129053944261569921119452534594627", - big"0.387533385375352377424782057105854424214534853623007724234120623518712309680007346340280888076477218145510846867158055651267664035097674992751409157682864641", - -1//7] - - TI = Matrix{T1}(undef, 7, 7) - TI[1, 1] = big"258.131926319982229276108947425184471333411128774462923076434633414645220927977539758484670571338176678808837829326061674950321562391576244286310404028770676" - TI[1, 2] = big"189.073763081398508951976143411165126555759459745371576264125287430947886413126866952443113984840310549596923934762141954737541643761162558070450614795561734" - TI[1, 3] = big"49.0873148179301311944474703372633419330229683717897887664283914712555334645741343066714059043135343948204451450061803442374878045458955826422757210762412997" - TI[1, 4] = big"4.11064746966142841811238518636124668078589358089581133578005291508858571621836624121708112101643343488669794287298806656198949715476379639435093560435010553" - TI[1, 5] = big"4.05344788931556330417512803837862541661144275947069236866476426664242632965376171604053865483440478823853326237912519148507906655855071507442222711969825069" - TI[1, 6] = big"-3.11275536660734607655357698925636361735741304308245452106573904595716690770542970584435712650159533448326091358879097717388530116398450168049097806992817596" - TI[1, 7] = big"1.64677491355844465016894934800942442334612077828885771793164268655566366462165061862443368822544695623147966149765223644798045399342853834086413561960176148" - TI[2, 1] = big"-3.00739016945129213173149353792169083141834116044470099212013728771587881480191343754504173052952073006187734389002396348355357273701343509199048972794392147" - TI[2, 2] = big"-11.0158660787657713291120393664792067595453921824881213620299497076376976067619617086470844707815815293102862568459526162951253770377715406520772358338647188" - TI[2, 3] = big"1.48779945613165628148618248664965038886474377325027865838645297753993182317594482435706956176392903188004580583104018591540474622009639200188521283880201225" - TI[2, 4] = big"2.13038815955928245943197208332824475219642634294808813866153957342980992047877237670079423767538654092424134276380826377135080667266661637001176204430488753" - TI[2, 5] = big"-1.81614108681756562482220455159496741723359999245934818387747079566312917815672128128449281415737713177900591942282975861961228230314168417307836619006791605" - TI[2, 6] = big"1.13432558789516110008277908420532415765361628740656810686297793967986689714948610119162966211301325316623863222505219543867472186257492829970663316956377323" - TI[2, 7] = big"-0.414699045943303531993049422295928526684402022493736427543557958358387925728160703636844863663828153394608981043415378230601486738224597324364079320598162815" - TI[3, 1] = big"-8.44196318832108468175691559413731210343158392484322786670758421404507417209484447031645790366021837365786640573614305718894911853549168061902141351516580451" - TI[3, 2] = big"-0.650525274057515002816904045893485631294530894981669254094573985727348985809697093879080285963063573837365484483755274668080611163704039179328960851461387071" - TI[3, 3] = big"6.94067073036987647880408175445008301222030789462375109942012235845495260572570799226646472429196555932436186979400567616504159564738984233922289782922787445" - TI[3, 4] = big"-3.20504752559789843156502799159713971965747774043426947358779973217345866996463287674334224123932879873323284636947452187683408110992957222808611161423213549" - TI[3, 5] = big"1.07128094354647858978279562700457911254627057919002861801894953308482120936700881726232902304000322718645130593907512149815870969208873216470962770569998532" - TI[3, 6] = big"-0.354850749121622187972972761073874956531274189535504546398851680169235702590362534883357256681588685608802983372517893712333972644320006895019178184808028042" - TI[3, 7] = big"0.0919854913278655415440864884207305663999562250023079120516746551750254082665966708567906888946992351083964961208132558221142585217674963218388224937302473142" - TI[4, 1] = big"74.6783322350226997715286176267232500441551583987525066913719852490109364599462546293112601362342028584101507709386240000804692470037564789980905370400509214" - TI[4, 2] = big"87.4085889799008164020396362924136436577534600993283836959398121813667403209890699914314446222016952621954817633686823685774595935180374571416781238038364186" - TI[4, 3] = big"4.02415873737999787701407840793921059156554118449220356776918749072220128918152906578385457943212213189933447495921754693186811343717296680238755923076427455" - TI[4, 4] = big"-3.7148063151583641866387382381081795406061842159003055897302686185198568522128509989890869602984467843559169959313018612449354703104270603001605170037725663" - TI[4, 5] = big"-3.43009398598231735074090769130593476067104938465255451803266927011738721835297930406017172365070584279715308905584391225176154776278518922912169890517961929" - TI[4, 6] = big"2.69660480976531237885262500230842013033719691844775548640355919138284680959979836353143310081338215041119022648809147361433752919265159399610746756470853959" - TI[4, 7] = big"-0.938692743607546193356785681771531136814109179879957291315724533839534255667763099330792864148293396694586387338161584706252944483821135344465739888811338788" - TI[5, 1] = big"58.3565288519065772423731088606544342599129168115273649928818622008651860145833895668543250775742899696760389837877193028417145182338484929599333810581515993" - TI[5, 2] = big"-10.0687739578001809632495544545749228539542767485211306078205622876595603032162891608453826862136355989387474454697691529766293644115682409173741730758425432" - TI[5, 3] = big"-30.3663888425666712081087189214021522992426235463582449811325590575576319489955157279473313224901192335775884848736150180108985558310423628914140477437063457" - TI[5, 4] = big"-1.02002086518486598502718784312141857841892430616701325398305811243769008274372077411348691412296276168896198187688441456921700292037247387330560786140723416" - TI[5, 5] = big"-0.112417500378424962126670249921897816128157398591725875330925039631874967429838848482089690872916638698820411392685501889126627650123714184027159547685248056" - TI[5, 6] = big"1.89064083100037762279966919417932484200269828564004442737723486475878958135985745266991261770924069476112679285337233931312540904735632744873728510014970829" - TI[5, 7] = big"-0.971648639383148228217233127548943147296423534674266405843322723719694664032217172325052282800290275002731997713145411340983758516166807609661717915219518127" - TI[6, 1] = big"-299.18624802825209667863642523944728107942141534516550178278869311293354511449399684666660494133688445719285752471650937062695632169114367079856135650539072" - TI[6, 2] = big"-243.040745368744791181900565230083092669143049316165122405971394775932180012728275256467636352341415340547177922968547123544546515287229215470481168446631934" - TI[6, 3] = big"-48.7771040780378692121909344887388032694629956594617430615510915251995189158287187599892740037773277403958100797917560590738598108409472582147091119440886778" - TI[6, 4] = big"-2.03867190574193440528015205293433905622043272233073734690244789947707827347049413187234402189062846366658963666461334786306660732097114011309282331323116958" - TI[6, 5] = big"1.67356023986108494426829042309213202110891938292923077616474877079402040904687073610625868939896244842053999572446723558562427506280564629528151134946587118" - TI[6, 6] = big"-1.0873740320571061644555969255032311107358443063278089996181949045168433801494845898897631535619158410753032807069032950523487601457868753453652745002841107" - TI[6, 7] = big"0.901938249296099373842715514839004052963355800714627971724094542443991299921284427589690820402982448873149676210397055957126153220340909284180014056386791594" - TI[7, 1] = big"-93.076502897435305911571945263737383854569504715670989865831914555937966339933932282945955570244055882294556430466422133231853008314991630740535709028417842" - TI[7, 2] = big"23.8816310562811442770319002318043863376962876994405756649585750650966186536576789769674007990310112890015051984278059899811178135726914390958188405071290871" - TI[7, 3] = big"39.2788807308138438271015646136760366834412493325456249795727722130258444051594274416196392795817449902122139076648927894476044063388859377757097127385794539" - TI[7, 4] = big"14.3889156854910800698761307424979534708984169042483973564042387223013868069040933228077604321320066763752720714195604903398768371784013771964086553618150626" - TI[7, 5] = big"-3.51043839939936122108708432480845734972162782563284715495715984978907792386567906732993553255070093796782368160341757151292477304975079070782335737053297468" - TI[7, 6] = big"4.86328488556618070121491058699734313503568312572977577331134555924656926935558698308076704662503608259898740028814153544991114426972747448736702277116049277" - TI[7, 7] = big"-2.24648272959123991640046924839711232278867381637608763335081676684616443569602032178385937243819174902544136208243971053224668691848283004752869023074006745" - - T = Matrix{T1}(undef, 7, 7) - T[1, 1] = big"0.00215375462731052642282751906550204337272018200721827917615061640312650856312529840445028048591986867096756005142895325420603307041594804305862850861253757163" - T[1, 2] = big"0.021567551351320773386914226953811992365459277376204369162736830595700124529879508417849062386878143122032508776691627063229415272329484156789207145821702462" - T[1, 3] = big"0.00878356792514414440732555660043326940873333657406338685620618347939710728032290406426688328221296324998146697730909767495361893387567339044816921837538988154" - T[1, 4] = big"-0.00405516145233102389819844704090310382485225922827010954643577855973533421255114497764957587851178840064428149215351434824919490696577563849929483184955933965" - T[1, 5] = big"0.00442723275326828547967807873499027629097834766201549949492135358632150336069311115075327876323707841703727317338755331613570950287342825020738596326021052902" - T[1, 6] = big"-0.00123864618795287405637686870391105285581324510790128485733529975336279476721707053186563729417080236061385260749762448518679294700311105630290083016823761156" - T[1, 7] = big"-0.00276061748054385249954800379096675592021481213358861974911688001011761550911589157738523818859000828996335817774948428177282421412491830529445501318154035024" - T[2, 1] = big"-0.00160002507788042852683067347985080829550105638728462477214069614397009338180775134535418790113854904464693278677067195562013777079470430165035085043732753352" - T[2, 2] = big"-0.0381316481344115466944201512445271892551007922443248010648630183723114657457789198582213862424187595732944781586531399310738197517976083499508550510483478779" - T[2, 3] = big"-0.0215255605940068755238494349163503963236812065771639056145559371805737876208350036328339608215271680572576146954552666030277743869132676140541472724370558091" - T[2, 4] = big"0.00841556827655958923717700333156546206587781542530241328710392714333753219743181540077241302321588065650704924760060316717877095134935044662592211744890794666" - T[2, 5] = big"-0.00403194957022454949230429372587008587329606687054571010486662485715979240183165499902791387008699068626978608835015342675934092134962673636484308565473356683" - T[2, 6] = big"-6.6666353393963381817604789740257628821376819567901071737415235834331307484818353061850936507762955342131861918219584166678095273744210157164382779907235669e-05" - T[2, 7] = big"0.00318547482516620984874835878222687621122035448401205459368674257818574765593899794870819769668503869906022860261901897250913569265553156976061140932045107432" - T[3, 1] = big"0.00405910730194768309165024146216588597640781263680870767202041411242133338742562561902630276038676420444232405079851555753917806998064489819308813790494788924" - T[3, 2] = big"0.0573965089393817153975680203880753938458832782600090443030839643350468249623833638779578474891654213594195393636829414422184571666256857425091138479371917574" - T[3, 3] = big"0.0588505292084267910561208969865829735901655409220388105109199298038946675765714122525765330769443473927581930134049676200572930797370286476504623214740871248" - T[3, 4] = big"-0.00856043106160343206017727185390754992573940897343949944649743606465705403614377469754987858631901604547097801042861815249197647886051332362774581709381720893" - T[3, 5] = big"-0.00692321266502390892414068519049460069371592099748070119636478595631451405094203293036429762819458535062492059219566837532157551782305886338773933077463475632" - T[3, 6] = big"-0.00235218098294333834053519532555529491776729377182703234025085030409255592197086839142988525473684138901264206886166295186155491132922909402254443843846019141" - T[3, 7] = big"0.00041690777252975626914088803059940941342549922756308931704215701350026719541939053570614368159222367707113801117750298289694571643601584878405615892432648487" - T[4, 1] = big"0.0157504880793768442034586734054915501004520506405808322686493022779655453114657621318660532381583918124125360276320121127974912393389579826125529804830864399" - T[4, 2] = big"-0.0382146935969683504846411337659300127514788882892071252172987515109399372135899067290947441850340146027892665775682097051548343529370733593281856326317259999" - T[4, 3] = big"-0.165736811272943851241241116255535218556011122333381899790277357803281567727036568454939356458468926429537927937619042817050400333625919290585510785057955509" - T[4, 4] = big"-0.0373712423023844574190702119163246888117181457309185176497005310822879226235861373253125139016964433591381638592353617347369492240160809914228784174846477722" - T[4, 5] = big"0.00823900729850771940449868235563938395546999707236910359131464615707125576979409087864780171789078059526539789661318173387826643385244974406562622466790754233" - T[4, 6] = big"0.00311507115234617525272547086289315208054441921705361129575617631104650731644437585122142710666234276633544335552925569262424677362146587776195531866754755781" - T[4, 7] = big"0.025116604913438821928363823471446698278976101918753236732238210724710282378748917637317846485853317873304329580245705683618093593158791190832004186288367408" - T[5, 1] = big"0.112977661024220807608615842313106352633973778091080400075534257952348289641328709240673869677499013004285003126194992176632265223545565047727637631580337111" - T[5, 2] = big"-0.249174212465263686330825594009221950347570740813751325091913985975498424569678307894304962660904874986611526140914403971840496728150916599999921976188547708" - T[5, 3] = big"0.273563305798662321213236935135336593478278696397012151365678540099566245199777083242808233574654642014215983653810819494932091426330017240672955510133726276" - T[5, 4] = big"0.00536676137918177009427930181087914853701809128264121101773394730339300080525157052081366996826642003169044168721911822166683675089051631342776752635189343996" - T[5, 5] = big"0.193211116101262014431211225620266980060733605289133050251158448403922545905872373640500736693735926480983370235582910255756813799388364741420161359961401418" - T[5, 6] = big"0.101717732481715146808078931323995112561027763392448195424858681165964478003318758266672250034474900552688318026734856778296896546916272032434282368222825518" - T[5, 7] = big"0.0950450203560462282103892144485647895183175432965514336285840628832838918715022627077373617151475963061484489345238022187829573892306346658797861719620799413" - T[6, 1] = big"0.458381043183931501028085939964292092908293295595258886425372669820276128937720150467378912424378376379185138190017965370589550781979145790869568608776861466" - T[6, 2] = big"0.5315846490836284292050500994300107341125728347976407285397462896004659632807779347307732180848765709277026749725126234633983063167374333425454720010026876" - T[6, 3] = big"0.486322836617572894056685295353340203321316764127126557475136642083389075853199222650975554544550110757249234979120491845825690852575400863926535437662617201" - T[6, 4] = big"0.526574226458449262914091192639271913456008564881594253716678163127743947224108435833618497118891017505982561930788522171455486058320589875335702474378251931" - T[6, 5] = big"0.275534394989625814192875938762525038291639319966986287664787801569471609648366101593885546008609962622035890891754680149203464179471952105174480329668882489" - T[6, 6] = big"0.521751945274765285294609453181807034209434470364856664246194441011327338299794536726049398636575212016960129143954076748520870645966241492966592488607495009" - T[6, 7] = big"0.128071944635543894414114939510913357662538610722706228789484435811417614332529416514635125851744500940930818246509599119254761178392202724896572159336577251" - T[7, 1] = big"0.881391578353818376313498879127399181693003124999819194603124949551827789004545406999549226388170693806014968936224161749923163222614460424501073405017519348" - T[7, 2] = 1 - T[7, 3] = 0 - T[7, 4] = 1 - T[7, 5] = 0 - T[7, 6] = 1 - T[7, 7] = 0 - - RadauIIATableau{T1, T2}(T, TI, c, γ, α, β, e) +function RadauIIATableau(T1, T2, num_stages::Int) + tab = get(RadauIIATableauCache, (T1, T2, num_stages)) do + tab = generateRadauTableau(T1, T2, num_stages) + RadauIIATableauCache[T1, T2, num_stages] = tab + tab + end + return RadauIIATableau{T1, T2}(tab) end -import LinearAlgebra: eigen -import FastGaussQuadrature: gaussradau - -function RadauIIATableau(T1, T2, num_stages::Int) +function generateRadauTableau(T1, T2, num_stages::Int) c = reverse!(1 .- gaussradau(num_stages, T1)[1])./2 if T1 == T2 c2 = c @@ -568,3 +335,7 @@ function RadauIIATableau(T1, T2, num_stages::Int) tab = RadauIIATableau{T1, T2}(T, TI, c2, γ, α, β, e) end +const RadauIIATableauCache = Dict{Tuple{Type,Type,Int}, RadauIIATableau{T1, T2} where {T1, T2}}( + (Float64, Float64, 3)=>generateRadauTableau(Float64, Float64, 3), + (Float64, Float64, 5)=>generateRadauTableau(Float64, Float64, 5), + (Float64, Float64, 7)=>generateRadauTableau(Float64, Float64, 7),) From 81f6fc3a7daf2cb9c809062fc6d725c825c4894a Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Thu, 5 Dec 2024 07:59:10 -0500 Subject: [PATCH 013/203] fix tests --- lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl | 4 +++- .../test/ode_high_order_firk_tests.jl | 14 -------------- lib/OrdinaryDiffEqFIRK/test/runtests.jl | 3 +-- 3 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl index 15d7111499..c8effacce4 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl @@ -14,10 +14,12 @@ sim21 = test_convergence(1 ./ 2 .^ (2.5:-1:0.5), prob_ode_linear, RadauIIA9()) sim21 = test_convergence(1 ./ 2 .^ (2.5:-1:0.5), prob_ode_2Dlinear, RadauIIA9()) @test sim21.𝒪est[:final]≈8 atol=testTol +using GenericSchur + prob_ode_linear_big = remake(prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), tspan = big.(prob_ode_2Dlinear.tspan)) -for i in [5, 9, 13], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] +for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] dts = 1 ./ 2 .^ (4.25:-1:0.25) local sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i)) @test sim21.𝒪est[:final]≈ i atol=testTol diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl deleted file mode 100644 index 5f0efa71f8..0000000000 --- a/lib/OrdinaryDiffEqFIRK/test/ode_high_order_firk_tests.jl +++ /dev/null @@ -1,14 +0,0 @@ -using OrdinaryDiffEqFIRK, DiffEqDevTools, Test, LinearAlgebra -import ODEProblemLibrary: prob_ode_linear, prob_ode_2Dlinear - -using GenericSchur -testTol = 0.5 - -prob_ode_linear_big = remake(prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) -prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), tspan = big.(prob_ode_2Dlinear.tspan)) - -for i in [17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] - dts = 1 ./ 2 .^ (4.25:-1:0.25) - sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i)) - @test sim21.𝒪est[:final]≈ i atol=testTol -end diff --git a/lib/OrdinaryDiffEqFIRK/test/runtests.jl b/lib/OrdinaryDiffEqFIRK/test/runtests.jl index ec335b116b..b252cdf8f2 100644 --- a/lib/OrdinaryDiffEqFIRK/test/runtests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/runtests.jl @@ -1,4 +1,3 @@ using SafeTestsets -@time @safetestset "FIRK Tests" include("ode_firk_tests.jl") -@time @safetestset "High Order FIRK Tests" include("ode_high_order_firk_tests.jl") +@time @safetestset "FIRK Tests" include("ode_firk_tests.jl") \ No newline at end of file From 226b1ca19104c116133bfe39f5f04f4cf513f648 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 9 Dec 2024 10:21:48 +0100 Subject: [PATCH 014/203] Remove export so it can live in non-breaking pull request --- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 659278af97..593f27ee77 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -64,6 +64,4 @@ include("functional.jl") include("newton.jl") include("initialize_dae.jl") -export BrownFullBasicInit, ShampineCollocationInit - end From 1749807f6c5c7a9f838ec19f559e7e2c144308d7 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 9 Dec 2024 11:28:19 +0100 Subject: [PATCH 015/203] Export BrownFullBasic and ShampineCollocation --- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 593f27ee77..659278af97 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -64,4 +64,6 @@ include("functional.jl") include("newton.jl") include("initialize_dae.jl") +export BrownFullBasicInit, ShampineCollocationInit + end From 5fa30322043964d62a862c09c6f069dc320da9d4 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 9 Dec 2024 11:29:21 +0100 Subject: [PATCH 016/203] Combine duplicate methods; add error checking if ODENLSolve is loaded --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 32 ++++---------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 0034e55d9a..67107ac335 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -44,36 +44,14 @@ end ## Default algorithms -function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Val{true}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - else - _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) - end -end function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Val{false}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - else - _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) - end -end - -function _initialize_dae!(integrator, prob::DAEProblem, - alg::DefaultInit, x::Val{false}) + alg::DefaultInit, x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif prob.differential_vars === nothing - _initialize_dae!(integrator, prob, - ShampineCollocationInit(), x) + elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) + throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") else _initialize_dae!(integrator, prob, BrownFullBasicInit(integrator.opts.abstol), x) @@ -81,10 +59,12 @@ function _initialize_dae!(integrator, prob::DAEProblem, end function _initialize_dae!(integrator, prob::DAEProblem, - alg::DefaultInit, x::Val{true}) + alg::DefaultInit, x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) + elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) + throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") elseif prob.differential_vars === nothing _initialize_dae!(integrator, prob, ShampineCollocationInit(), x) From cf9403de8b4324800865bd26eb2fdbf93f2c8194 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 9 Dec 2024 11:54:42 +0100 Subject: [PATCH 017/203] replace throw with error --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 67107ac335..1c887bc719 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -51,7 +51,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) - throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") + error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") else _initialize_dae!(integrator, prob, BrownFullBasicInit(integrator.opts.abstol), x) @@ -64,7 +64,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) - throw("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") + error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") elseif prob.differential_vars === nothing _initialize_dae!(integrator, prob, ShampineCollocationInit(), x) From ae9a96a934a8f2400655c19a63ee142a03453836 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 12:24:24 -0500 Subject: [PATCH 018/203] match NonlinearSolve for Downstream DI develop --- .github/workflows/Downstream.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index dd57d15a64..89eebf5e98 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -49,10 +49,12 @@ jobs: # the libs haven't been registered yet. - name: "Develop the libraries since they haven't been registered yet" run: | - julia --project=. -e ' - using Pkg; - Pkg.develop(map(path ->Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); - ' + import Pkg + Pkg.Registry.update() + # Install packages present in subdirectories + dev_pks = Pkg.PackageSpec[] + Pkg.develop(map(path -> Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); + Pkg.instantiate() - name: Clone Downstream uses: actions/checkout@v4 with: @@ -80,4 +82,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: lcov.info - fail_ci_if_error: true + fail_ci_if_error: false From 63a9e018d75143435369cf1f4fd9e4a82649a5d4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 13:19:01 -0500 Subject: [PATCH 019/203] forgot the shell --- .github/workflows/Downstream.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 89eebf5e98..639a6e0623 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -55,6 +55,7 @@ jobs: dev_pks = Pkg.PackageSpec[] Pkg.develop(map(path -> Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); Pkg.instantiate() + shell: julia --color=yes --code-coverage=user --depwarn=yes --project=. {0} - name: Clone Downstream uses: actions/checkout@v4 with: From ef10777e1edcd53e920eec300f90a958232564d3 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 13:59:08 -0500 Subject: [PATCH 020/203] fix CI? --- .github/workflows/Downstream.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 639a6e0623..309b86159b 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -48,14 +48,14 @@ jobs: # This is necessary since the tests are likely to fail otherwise, given that all # the libs haven't been registered yet. - name: "Develop the libraries since they haven't been registered yet" + shell: julia --project=. {0} run: | import Pkg Pkg.Registry.update() # Install packages present in subdirectories dev_pks = Pkg.PackageSpec[] - Pkg.develop(map(path -> Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); + Pkg.develop(map(path -> Pkg.PackageSpec.(;path="/lib/$(path)"), readdir("./lib"))); Pkg.instantiate() - shell: julia --color=yes --code-coverage=user --depwarn=yes --project=. {0} - name: Clone Downstream uses: actions/checkout@v4 with: From b75a786963faab7984b5c7c4c1f7459184b026b4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 14:42:11 -0500 Subject: [PATCH 021/203] no slash? --- .github/workflows/Downstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 309b86159b..dd9322c39d 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -54,7 +54,7 @@ jobs: Pkg.Registry.update() # Install packages present in subdirectories dev_pks = Pkg.PackageSpec[] - Pkg.develop(map(path -> Pkg.PackageSpec.(;path="/lib/$(path)"), readdir("./lib"))); + Pkg.develop(map(path -> Pkg.PackageSpec.(;path="lib/$(path)"), readdir("./lib"))); Pkg.instantiate() - name: Clone Downstream uses: actions/checkout@v4 From cb3c1e3e9e3da1fd631d6dfae4a3355687145a11 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 16:10:19 -0500 Subject: [PATCH 022/203] try this --- .github/workflows/Downstream.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index dd9322c39d..83669c4bd2 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -47,15 +47,6 @@ jobs: # Explicitly develop the libraries first before running the tests for now. # This is necessary since the tests are likely to fail otherwise, given that all # the libs haven't been registered yet. - - name: "Develop the libraries since they haven't been registered yet" - shell: julia --project=. {0} - run: | - import Pkg - Pkg.Registry.update() - # Install packages present in subdirectories - dev_pks = Pkg.PackageSpec[] - Pkg.develop(map(path -> Pkg.PackageSpec.(;path="lib/$(path)"), readdir("./lib"))); - Pkg.instantiate() - name: Clone Downstream uses: actions/checkout@v4 with: @@ -67,6 +58,7 @@ jobs: using Pkg try # force it to use this PR's version of the package + Pkg.develop(map(path ->Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps Pkg.update() Pkg.test(coverage=true) # resolver may fail with test time deps From 41c5c16a0209f29f63d5c2b2c2f6cee7a7a354b4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 10 Dec 2024 16:44:35 -0500 Subject: [PATCH 023/203] lib --- .github/workflows/Downstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 83669c4bd2..9ebbc15439 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -58,7 +58,7 @@ jobs: using Pkg try # force it to use this PR's version of the package - Pkg.develop(map(path ->Pkg.PackageSpec.(;path="$(@__DIR__)/lib/$(path)"), readdir("./lib"))); + Pkg.develop(map(path ->Pkg.PackageSpec.(;path="lib/$(path)"), readdir("./lib"))); Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps Pkg.update() Pkg.test(coverage=true) # resolver may fail with test time deps From dc00dc26da8efd4ee0a8c9733fc4ccd1ed76ef48 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 14:54:55 -0400 Subject: [PATCH 024/203] Use ADTypes for AD choice --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 123 +++++-- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 11 + .../src/algorithms.jl | 34 +- .../src/algorithms.jl | 41 ++- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 44 ++- .../src/algorithms.jl | 22 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 11 +- .../src/algorithms.jl | 44 ++- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 320 ++++++++++++++---- .../src/algorithms.jl | 11 +- 10 files changed, 542 insertions(+), 119 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 494bbcfa8a..9beebd2c70 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -5,7 +5,7 @@ function BDF_docstring(description::String, extra_keyword_default::String = "") keyword_default = """ chunk_size = Val{0}(), - autodiff = true, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -113,14 +113,21 @@ struct ABDF2{CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function ABDF2(; chunk_size = Val{0}(), autodiff = true, standardtag = Val{true}(), +function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, κ = nothing, tol = nothing, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + ABDF2{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}(linsolve, nlsolve, precs, κ, tol, smooth_est, extrapolant, controller, step_limiter!) @@ -169,12 +176,19 @@ struct SBDF{CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: ark::Bool end -function SBDF(order; chunk_size = Val{0}(), autodiff = Val{true}(), +function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, ark = false) - SBDF{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -187,13 +201,20 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = Val{true}(), end # All keyword form needed for remake -function SBDF(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, order, ark = false) - SBDF{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -289,13 +310,20 @@ struct QNDF1{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: step_limiter!::StepLimiter end -function QNDF1(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -37 // 200, controller = :Standard, step_limiter! = trivial_limiter!) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + QNDF1{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -344,13 +372,20 @@ struct QNDF2{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: step_limiter!::StepLimiter end -function QNDF2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -1 // 9, controller = :Standard, step_limiter! = trivial_limiter!) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + QNDF2{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -408,14 +443,21 @@ struct QNDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T, κType, StepLimiter} <: end function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), - autodiff = Val{true}(), standardtag = Val{true}(), concrete_jac = nothing, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, kappa = ( -37 // 200, -1 // 9, -823 // 10000, -83 // 2000, 0 // 1), controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - QNDF{MO, _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + QNDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(kappa), typeof(step_limiter!)}( @@ -453,11 +495,18 @@ struct MEBDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol end -function MEBDF2(; chunk_size = Val{0}(), autodiff = true, standardtag = Val{true}(), +function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant) - MEBDF2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + MEBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -507,12 +556,19 @@ struct FBDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: end function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), - autodiff = Val{true}(), standardtag = Val{true}(), concrete_jac = nothing, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - FBDF{MO, _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + FBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}( @@ -622,12 +678,19 @@ struct DImplicitEuler{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT controller::Symbol end function DImplicitEuler(; - chunk_size = Val{0}(), autodiff = true, standardtag = Val{true}(), + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) - DImplicitEuler{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + DImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -660,12 +723,19 @@ struct DABDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT, ST, CJ extrapolant::Symbol controller::Symbol end -function DABDF2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) - DABDF2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + DABDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -720,12 +790,19 @@ struct DFBDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: DAEAlgorithm{CS, AD, FD controller::Symbol end function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), - autodiff = Val{true}(), standardtag = Val{true}(), concrete_jac = nothing, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard) where {MO} - DFBDF{MO, _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + DFBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(max_order, linsolve, nlsolve, precs, κ, tol, extrapolant, diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index c6f67947eb..e3f21c8c88 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -130,3 +130,14 @@ function get_differential_vars(f, u) end isnewton(::Any) = false + + +function bool_to_ADType(AD::Val{true}, chunk_size, diff_type) + Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) + AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize)) +end + +function bool_to_ADType(AD::Val{false}, chunk_size, diff_type) + Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) + AutoFiniteDiff(fdtype = diff_type) +end \ No newline at end of file diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index 6f83541846..c92170a35e 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -34,11 +34,18 @@ for (Alg, Description, Ref) in [ iop::Int end end - @eval function $Alg(; krylov = false, m = 30, iop = 0, autodiff = true, + @eval function $Alg(; krylov = false, m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(krylov, m, iop) @@ -74,10 +81,17 @@ for (Alg, Description, Ref) in [ iop::Int end end - @eval function $Alg(; m = 30, iop = 0, autodiff = true, standardtag = Val{true}(), + @eval function $Alg(; m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(m, iop) @@ -123,6 +137,7 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) m = 30, iop = 0, """) + struct $Alg{CS, AD, FDT, ST, CJ} <: OrdinaryDiffEqExponentialAlgorithm{CS, AD, FDT, ST, CJ} adaptive_krylov::Bool @@ -130,10 +145,17 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) iop::Int end end - @eval function $Alg(; adaptive_krylov = true, m = 30, iop = 0, autodiff = true, + @eval function $Alg(; adaptive_krylov = true, m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), diff_type, + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(adaptive_krylov, m, iop) diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index 205e8e1f3d..8214f7739c 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -66,12 +66,19 @@ struct ImplicitEulerExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: sequence::Symbol # Name of the subdividing sequence end -function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = true, +function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, max_order = 12, min_order = 3, init_order = 5, threading = false, sequence = :harmonic) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + linsolve = (linsolve === nothing && (threading == true || threading isa PolyesterThreads)) ? RFLUFactorization(; thread = Val(false)) : linsolve @@ -99,7 +106,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") :$(sequence) --> :harmonic" sequence = :harmonic end - ImplicitEulerExtrapolation{_unwrap_val(chunk_size), _unwrap_val(autodiff), + ImplicitEulerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, max_order, min_order, @@ -205,12 +212,19 @@ struct ImplicitDeuflhardExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: sequence::Symbol # Name of the subdividing sequence threading::TO end -function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, diff_type = Val{:forward}, min_order = 1, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + # Enforce 1 <= min_order <= init_order <= max_order: min_order = max(1, min_order) init_order = max(min_order, init_order) @@ -242,7 +256,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") end # Initialize algorithm - ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), _unwrap_val(autodiff), + ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -353,13 +367,14 @@ struct ImplicitHairerWannerExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: threading::TO end -function ImplicitHairerWannerExtrapolation(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ImplicitHairerWannerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, diff_type = Val{:forward}, min_order = 2, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) + # Enforce 2 <= min_order # and min_order + 1 <= init_order <= max_order - 1: min_order = max(2, min_order) @@ -390,8 +405,13 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end # Initialize algorithm - ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), _unwrap_val(autodiff), + ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -433,7 +453,7 @@ struct ImplicitEulerBarycentricExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: end function ImplicitEulerBarycentricExtrapolation(; chunk_size = Val{0}(), - autodiff = Val{true}(), + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, @@ -471,8 +491,13 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end # Initialize algorithm - ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), _unwrap_val(autodiff), + ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index e98389ec7c..051a770797 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -39,7 +39,7 @@ struct RadauIIA3{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: step_limiter!::StepLimiter end -function RadauIIA3(; chunk_size = Val{0}(), autodiff = Val{true}(), +function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, @@ -47,7 +47,14 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = Val{true}(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, step_limiter! = trivial_limiter!) - RadauIIA3{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + RadauIIA3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -83,7 +90,7 @@ struct RadauIIA5{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: step_limiter!::StepLimiter end -function RadauIIA5(; chunk_size = Val{0}(), autodiff = Val{true}(), +function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, @@ -91,7 +98,14 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = Val{true}(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - RadauIIA5{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + RadauIIA5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -128,7 +142,7 @@ struct RadauIIA9{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: step_limiter!::StepLimiter end -function RadauIIA9(; chunk_size = Val{0}(), autodiff = Val{true}(), +function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, @@ -136,7 +150,14 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = Val{true}(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - RadauIIA9{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + RadauIIA9{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -167,7 +188,7 @@ struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: max_order::Int end -function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = Val{true}(), +function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, min_order = 5, max_order = 13, linsolve = nothing, precs = DEFAULT_PRECS, @@ -175,7 +196,14 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = Val{true}(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - AdaptiveRadau{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index 69e0d7ab57..f5768b1313 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -28,12 +28,19 @@ struct CNAB2{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol end -function CNAB2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + CNAB2{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -67,12 +74,19 @@ struct CNLF2{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol end -function CNLF2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + CNLF2{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index 0e93763cfd..d895ca53f4 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -29,11 +29,18 @@ struct PDIRK44{CS, AD, F, F2, P, FDT, ST, CJ, TO} <: extrapolant::Symbol threading::TO end -function PDIRK44(; chunk_size = Val{0}(), autodiff = true, standardtag = Val{true}(), +function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, threading = true) - PDIRK44{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + PDIRK44{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, nlsolve, precs, extrapolant, threading) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index 2ad10b28c8..c41b5913e2 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -111,12 +111,19 @@ for Alg in [ step_limiter!::StepLimiter stage_limiter!::StageLimiter end - function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), + function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, stage_limiter! = trivial_limiter!) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!), typeof(stage_limiter!)}(linsolve, precs, step_limiter!, @@ -130,11 +137,18 @@ struct GeneralRosenbrock{CS, AD, F, ST, CJ, TabType} <: factorization::F end -function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = true, +function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + GeneralRosenbrock{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(factorization), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(factorization), _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, factorization) end @@ -152,13 +166,20 @@ struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <: linsolve::F precs::P end -function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = true, +function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:central}, linsolve = nothing, precs = DEFAULT_PRECS) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + RosenbrockW6S4OS{_unwrap_val(chunk_size), - _unwrap_val(autodiff), typeof(linsolve), typeof(precs), diff_type, + typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) end @@ -190,10 +211,17 @@ for Alg in [ linsolve::F precs::P end - function $Alg(; chunk_size = Val{0}(), autodiff = Val{true}(), + function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) - $Alg{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 226f92e57f..285fbe7857 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -108,13 +108,20 @@ struct ImplicitEuler{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: step_limiter!::StepLimiter end -function ImplicitEuler(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :PI, step_limiter! = trivial_limiter!) - ImplicitEuler{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, controller, step_limiter!) @@ -146,12 +153,19 @@ struct ImplicitMidpoint{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: step_limiter!::StepLimiter end -function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, step_limiter! = trivial_limiter!) - ImplicitMidpoint{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ImplicitMidpoint{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -188,13 +202,20 @@ struct Trapezoid{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: step_limiter!::StepLimiter end -function Trapezoid(; chunk_size = Val{0}(), autodiff = Val{true}(), +function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - Trapezoid{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -240,12 +261,19 @@ struct TRBDF2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: step_limiter!::StepLimiter end -function TRBDF2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - TRBDF2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + TRBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -287,12 +315,19 @@ struct SDIRK2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: step_limiter!::StepLimiter end -function SDIRK2(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - SDIRK2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}( linsolve, nlsolve, precs, smooth_est, extrapolant, @@ -329,12 +364,19 @@ struct SDIRK22{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function SDIRK22(; - chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - Trapezoid{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -380,13 +422,20 @@ struct SSPSDIRK2{CS, AD, F, F2, P, FDT, ST, CJ} <: controller::Symbol end -function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :constant, controller = :PI) - SSPSDIRK2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SSPSDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -425,13 +474,20 @@ struct Kvaerno3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function Kvaerno3(; chunk_size = Val{0}(), autodiff = Val{true}(), +function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - Kvaerno3{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Kvaerno3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -467,13 +523,20 @@ struct KenCarp3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function KenCarp3(; chunk_size = Val{0}(), autodiff = Val{true}(), +function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - KenCarp3{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + KenCarp3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -503,12 +566,19 @@ struct CFNLIRK3{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol end -function CFNLIRK3(; chunk_size = Val{0}(), autodiff = Val{true}(), +function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - CFNLIRK3{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + CFNLIRK3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -549,13 +619,21 @@ struct Cash4{CS, AD, F, F2, P, FDT, ST, CJ} <: embedding::Int controller::Symbol end -function Cash4(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, embedding = 3) + + if autodiff isa AbstractADType + AD_choice = autodiff + else + # deprecation path + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + Cash4{ - _unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -590,12 +668,19 @@ struct SFSDIRK4{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol end -function SFSDIRK4(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - SFSDIRK4{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SFSDIRK4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -628,12 +713,19 @@ struct SFSDIRK5{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol end -function SFSDIRK5(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - SFSDIRK5{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SFSDIRK5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -666,12 +758,19 @@ struct SFSDIRK6{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol end -function SFSDIRK6(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - SFSDIRK6{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SFSDIRK6{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -704,12 +803,19 @@ struct SFSDIRK7{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol end -function SFSDIRK7(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - SFSDIRK7{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SFSDIRK7{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -742,12 +848,19 @@ struct SFSDIRK8{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol end -function SFSDIRK8(; chunk_size = Val{0}(), autodiff = Val{true}(), +function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - SFSDIRK8{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + SFSDIRK8{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -780,12 +893,19 @@ struct Hairer4{CS, AD, F, F2, P, FDT, ST, CJ} <: controller::Symbol end function Hairer4(; - chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - Hairer4{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Hairer4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -815,13 +935,20 @@ struct Hairer42{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function Hairer42(; chunk_size = Val{0}(), autodiff = Val{true}(), +function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - Hairer42{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Hairer42{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -860,13 +987,20 @@ struct Kvaerno4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function Kvaerno4(; chunk_size = Val{0}(), autodiff = Val{true}(), +function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - Kvaerno4{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Kvaerno4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -905,13 +1039,20 @@ struct Kvaerno5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function Kvaerno5(; chunk_size = Val{0}(), autodiff = Val{true}(), +function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - Kvaerno5{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + Kvaerno5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -947,13 +1088,20 @@ struct KenCarp4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function KenCarp4(; chunk_size = Val{0}(), autodiff = Val{true}(), +function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - KenCarp4{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + KenCarp4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -991,13 +1139,20 @@ struct KenCarp47{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function KenCarp47(; chunk_size = Val{0}(), autodiff = Val{true}(), +function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - KenCarp47{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + KenCarp47{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1033,13 +1188,20 @@ struct KenCarp5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: controller::Symbol step_limiter!::StepLimiter end -function KenCarp5(; chunk_size = Val{0}(), autodiff = Val{true}(), +function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - KenCarp5{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + KenCarp5{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1075,13 +1237,20 @@ struct KenCarp58{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function KenCarp58(; chunk_size = Val{0}(), autodiff = Val{true}(), +function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - KenCarp58{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + KenCarp58{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1117,12 +1286,19 @@ struct ESDIRK54I8L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - ESDIRK54I8L2SA{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ESDIRK54I8L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1157,12 +1333,19 @@ struct ESDIRK436L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - ESDIRK436L2SA2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ESDIRK436L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1197,12 +1380,19 @@ struct ESDIRK437L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - ESDIRK437L2SA{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ESDIRK437L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1237,12 +1427,19 @@ struct ESDIRK547L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - ESDIRK547L2SA2{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ESDIRK547L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1279,12 +1476,19 @@ struct ESDIRK659L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol controller::Symbol end -function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = Val{true}(), +function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - ESDIRK659L2SA{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + ESDIRK659L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index 78cb42bc88..1e4e3eb5cc 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -19,12 +19,19 @@ struct IRKC{CS, AD, F, F2, P, FDT, ST, CJ, K, T, E} <: eigen_est::E end -function IRKC(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), +function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, eigen_est = nothing) - IRKC{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(nlsolve), + + if autodiff isa AbstractADType + AD_choice = autodiff + else + AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + end + + IRKC{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(eigen_est)}(linsolve, nlsolve, precs, κ, tol, extrapolant, controller, eigen_est) From 32c24c7366ec990cb7f28bf304e70e3d24ca24d4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 15:01:12 -0400 Subject: [PATCH 025/203] change some docstrings --- lib/OrdinaryDiffEqCore/src/doc_utils.jl | 2 +- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/doc_utils.jl b/lib/OrdinaryDiffEqCore/src/doc_utils.jl index 75eb00dc7d..0fddff67a5 100644 --- a/lib/OrdinaryDiffEqCore/src/doc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/doc_utils.jl @@ -82,7 +82,7 @@ function differentiation_rk_docstring(description::String, extra_keyword_default::String = "") keyword_default = """ chunk_size = Val{0}(), - autodiff = true, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 285fbe7857..8bdaab0bee 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -5,7 +5,7 @@ function SDIRK_docstring(description::String, extra_keyword_default::String = "") keyword_default = """ chunk_size = Val{0}(), - autodiff = true, + autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, From 26de240ac9ec798eeccaf953aa4b226a59679942 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 15:11:12 -0400 Subject: [PATCH 026/203] change another docstring --- lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index d5aa1d363f..2562da74d6 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -48,7 +48,7 @@ function rosenbrock_wolfbrandt_docstring(description::String, keyword_default = """ chunk_size = Val{0}(), standardtag = Val{true}(), - autodiff = Val{true}(), + autodiff = AutoForwardDiff(), concrete_jac = nothing, diff_type = Val{:central}, linsolve = nothing, From 8341a6063f3eaccbdcf8452f9ebac00dcc0f282d Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 16:11:43 -0400 Subject: [PATCH 027/203] add ADTypes to libs that need it --- lib/OrdinaryDiffEqBDF/Project.toml | 1 + lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl | 1 + lib/OrdinaryDiffEqExponentialRK/Project.toml | 1 + .../src/OrdinaryDiffEqExponentialRK.jl | 1 + lib/OrdinaryDiffEqExtrapolation/Project.toml | 1 + .../src/OrdinaryDiffEqExtrapolation.jl | 1 + lib/OrdinaryDiffEqFIRK/Project.toml | 1 + lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl | 1 + .../src/OrdinaryDiffEqIMEXMultistep.jl | 1 + lib/OrdinaryDiffEqPDIRK/Project.toml | 1 + lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl | 2 ++ lib/OrdinaryDiffEqSDIRK/Project.toml | 1 + lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl | 1 + .../src/OrdinaryDiffEqStabilizedIRK.jl | 1 + 14 files changed, 15 insertions(+) diff --git a/lib/OrdinaryDiffEqBDF/Project.toml b/lib/OrdinaryDiffEqBDF/Project.toml index b5f182aff6..d0752ea049 100644 --- a/lib/OrdinaryDiffEqBDF/Project.toml +++ b/lib/OrdinaryDiffEqBDF/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.2" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index 5a2981219b..f5a56e2a13 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -32,6 +32,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper using OrdinaryDiffEqNonlinearSolve: NLNewton, du_alias_or_new, build_nlsolver, nlsolve!, nlsolvefail, isnewton, markfirststage!, set_new_W!, DIRK, compute_step!, COEFFICIENT_MULTISTEP +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqExponentialRK/Project.toml b/lib/OrdinaryDiffEqExponentialRK/Project.toml index 3dce2d7dd4..99079c409b 100644 --- a/lib/OrdinaryDiffEqExponentialRK/Project.toml +++ b/lib/OrdinaryDiffEqExponentialRK/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" diff --git a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl index 98fde5722c..7e78d7aabc 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl @@ -20,6 +20,7 @@ using ExponentialUtilities import RecursiveArrayTools: recursivecopy! using OrdinaryDiffEqDifferentiation: build_jac_config, UJacobianWrapper, UDerivativeWrapper, calc_J, calc_J! +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqExtrapolation/Project.toml b/lib/OrdinaryDiffEqExtrapolation/Project.toml index 684fb1bb4e..917b72b001 100644 --- a/lib/OrdinaryDiffEqExtrapolation/Project.toml +++ b/lib/OrdinaryDiffEqExtrapolation/Project.toml @@ -4,6 +4,7 @@ authors = ["Chris Rackauckas ", "Yingbo Ma "] version = "1.5.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838" diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 5817abd9b7..0798bb2959 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -31,6 +31,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper, build_J_W, build_jac_conf using OrdinaryDiffEqNonlinearSolve: du_alias_or_new, Convergence, FastConvergence, NLStatus, VerySlowConvergence, Divergence, get_new_W_γdt_cutoff +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl index 567e6b5eae..9e90a6b74c 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl @@ -12,6 +12,7 @@ import OrdinaryDiffEqCore using OrdinaryDiffEqDifferentiation: dolinsolve using OrdinaryDiffEqNonlinearSolve: NLNewton, build_nlsolver, markfirststage!, nlsolve!, nlsolvefail, du_alias_or_new +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqPDIRK/Project.toml b/lib/OrdinaryDiffEqPDIRK/Project.toml index 2e1b6bb3b4..ae8ce4bf5d 100644 --- a/lib/OrdinaryDiffEqPDIRK/Project.toml +++ b/lib/OrdinaryDiffEqPDIRK/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.1" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" diff --git a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl index 18a4e56205..fcea8fdd02 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl @@ -18,6 +18,8 @@ using OrdinaryDiffEqDifferentiation: dolinsolve using OrdinaryDiffEqNonlinearSolve: NLNewton, build_nlsolver, nlsolve!, nlsolvefail, markfirststage! +import ADTypes: AutoForwardDiff + include("algorithms.jl") include("alg_utils.jl") include("pdirk_caches.jl") diff --git a/lib/OrdinaryDiffEqSDIRK/Project.toml b/lib/OrdinaryDiffEqSDIRK/Project.toml index 6204b7309e..6318365f79 100644 --- a/lib/OrdinaryDiffEqSDIRK/Project.toml +++ b/lib/OrdinaryDiffEqSDIRK/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl index f9fc3bbd9e..44bbbaefdc 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl @@ -23,6 +23,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper, dolinsolve using OrdinaryDiffEqNonlinearSolve: du_alias_or_new, markfirststage!, build_nlsolver, nlsolve!, nlsolvefail, isnewton, get_W, set_new_W!, NLNewton, COEFFICIENT_MULTISTEP +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl index f16310de7e..0820259b15 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl @@ -19,6 +19,7 @@ using OrdinaryDiffEqNonlinearSolve: NLNewton, nlsolve!, isnewton, build_nlsolver using FastBroadcast, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import OrdinaryDiffEqCore +import ADTypes: AutoForwardDiff using Reexport @reexport using DiffEqBase From e3b5c17809dd790c3ce466dfad97fe9a3dff50a4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 16:13:02 -0400 Subject: [PATCH 028/203] more ADTypes adding --- lib/OrdinaryDiffEqIMEXMultistep/Project.toml | 1 + lib/OrdinaryDiffEqStabilizedIRK/Project.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml index ff8bd8f36b..88e0ed4746 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml +++ b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" diff --git a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml index da92cbbb91..8c2fab15cf 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml +++ b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" From 8e5d1c83129988fcffcc1681381fb5509eca1775 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 16:28:54 -0400 Subject: [PATCH 029/203] make sure to import AbstractADType --- lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl | 2 +- lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl | 2 +- .../src/OrdinaryDiffEqExtrapolation.jl | 2 +- lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl | 2 +- .../src/OrdinaryDiffEqIMEXMultistep.jl | 2 +- lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl | 2 +- .../src/OrdinaryDiffEqStabilizedIRK.jl | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index f5a56e2a13..4448fff60d 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -32,7 +32,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper using OrdinaryDiffEqNonlinearSolve: NLNewton, du_alias_or_new, build_nlsolver, nlsolve!, nlsolvefail, isnewton, markfirststage!, set_new_W!, DIRK, compute_step!, COEFFICIENT_MULTISTEP -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl index fbfcd66dd3..c47a886535 100644 --- a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl +++ b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl @@ -71,7 +71,7 @@ import DiffEqBase: calculate_residuals, import Polyester using MacroTools, Adapt -import ADTypes: AutoFiniteDiff, AutoForwardDiff +import ADTypes: AutoFiniteDiff, AutoForwardDiff, AbstractADType import Accessors: @reset using SciMLStructures: canonicalize, Tunable, isscimlstructure diff --git a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl index 7f6e2ab5ad..4e399c816f 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl @@ -25,7 +25,7 @@ import OrdinaryDiffEqDifferentiation: TimeDerivativeWrapper, UDerivativeWrapper, WOperator, TimeGradientWrapper, UJacobianWrapper, build_grad_config, build_jac_config, calc_J!, jacobian2W!, dolinsolve -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 0798bb2959..2fb2578501 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -31,7 +31,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper, build_J_W, build_jac_conf using OrdinaryDiffEqNonlinearSolve: du_alias_or_new, Convergence, FastConvergence, NLStatus, VerySlowConvergence, Divergence, get_new_W_γdt_cutoff -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl index 9e90a6b74c..99084493e3 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl @@ -12,7 +12,7 @@ import OrdinaryDiffEqCore using OrdinaryDiffEqDifferentiation: dolinsolve using OrdinaryDiffEqNonlinearSolve: NLNewton, build_nlsolver, markfirststage!, nlsolve!, nlsolvefail, du_alias_or_new -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl index fcea8fdd02..17285073a6 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl @@ -18,7 +18,7 @@ using OrdinaryDiffEqDifferentiation: dolinsolve using OrdinaryDiffEqNonlinearSolve: NLNewton, build_nlsolver, nlsolve!, nlsolvefail, markfirststage! -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType include("algorithms.jl") include("alg_utils.jl") diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl index 0820259b15..d415e80387 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl @@ -19,7 +19,7 @@ using OrdinaryDiffEqNonlinearSolve: NLNewton, nlsolve!, isnewton, build_nlsolver using FastBroadcast, MuladdMacro, RecursiveArrayTools import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, SA import OrdinaryDiffEqCore -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase From 72e815ac1a2005c1addf17303b354e0270612a35 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 16:43:07 -0400 Subject: [PATCH 030/203] import bool_to_ADType --- lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl | 2 +- .../src/OrdinaryDiffEqExtrapolation.jl | 2 +- lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl | 2 +- .../src/OrdinaryDiffEqIMEXMultistep.jl | 2 +- lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl | 3 ++- .../src/OrdinaryDiffEqStabilizedIRK.jl | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index 4448fff60d..b665cd416f 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -20,7 +20,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, step_accept_controller!, step_reject_controller!, post_newton_controller!, u_modified!, DAEAlgorithm, _unwrap_val, DummyController, - get_fsalfirstlast, generic_solver_docstring + get_fsalfirstlast, generic_solver_docstring, bool_to_ADType using OrdinaryDiffEqSDIRK: ImplicitEulerConstantCache, ImplicitEulerCache using TruncatedStacktraces, MuladdMacro, MacroTools, FastBroadcast, RecursiveArrayTools diff --git a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl index 4e399c816f..053c7a885b 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl @@ -17,7 +17,7 @@ import OrdinaryDiffEqCore: alg_order, alg_maximum_order, get_current_adaptive_or constvalue, PolyesterThreads, Sequential, BaseThreads, _digest_beta1_beta2, timedepentdtmin, _unwrap_val, _reshape, _vec, get_fsalfirstlast, generic_solver_docstring, - differentiation_rk_docstring + differentiation_rk_docstring, bool_to_ADType using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools, LinearSolve import OrdinaryDiffEqCore import FastPower diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 2fb2578501..558744512d 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -16,7 +16,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, PredictiveController, alg_can_repeat_jac, NewtonAlgorithm, fac_default_gamma, get_current_adaptive_order, get_fsalfirstlast, - isfirk, generic_solver_docstring + isfirk, generic_solver_docstring, bool_to_ADType using MuladdMacro, DiffEqBase, RecursiveArrayTools using SciMLOperators: AbstractSciMLOperator using LinearAlgebra: I, UniformScaling, mul!, lu diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl index 99084493e3..4b82f150b0 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEqCore: alg_order, issplit, OrdinaryDiffEqNewtonAlgorithm, _u OrdinaryDiffEqMutableCache, @cache, alg_cache, initialize!, perform_step!, @unpack, full_cache, get_fsalfirstlast, - generic_solver_docstring + generic_solver_docstring, bool_to_ADType using FastBroadcast import OrdinaryDiffEqCore diff --git a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl index 44bbbaefdc..1a2b07cc36 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl @@ -13,7 +13,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, constvalue, _unwrap_val, _ode_interpolant, trivial_limiter!, _ode_interpolant!, isesdirk, issplit, - ssp_coefficient, get_fsalfirstlast, generic_solver_docstring + ssp_coefficient, get_fsalfirstlast, generic_solver_docstring, + bool_to_ADType using TruncatedStacktraces, MuladdMacro, MacroTools, FastBroadcast, RecursiveArrayTools using SciMLBase: SplitFunction using LinearAlgebra: mul!, I diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl index d415e80387..b4f2fea7c0 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl @@ -11,7 +11,7 @@ import OrdinaryDiffEqCore: alg_order, alg_maximum_order, OrdinaryDiffEqAdaptiveImplicitAlgorithm, alg_cache, _unwrap_val, DEFAULT_PRECS, @cache, _reshape, _vec, full_cache, get_fsalfirstlast, - generic_solver_docstring + generic_solver_docstring, bool_to_ADType using OrdinaryDiffEqDifferentiation: dolinsolve, update_W! using OrdinaryDiffEqNonlinearSolve: NLNewton, nlsolve!, isnewton, build_nlsolver, From aa9b21fb09a4bb9d7bb98e3372783be4f4824d4a Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 16:46:13 -0400 Subject: [PATCH 031/203] missed one --- lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl index 17285073a6..a468f4e558 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl @@ -5,7 +5,8 @@ import OrdinaryDiffEqCore: isfsal, alg_order, _unwrap_val, OrdinaryDiffEqMutableCache, constvalue, alg_cache, uses_uprev, @unpack, unwrap_alg, @cache, DEFAULT_PRECS, @threaded, initialize!, perform_step!, isthreaded, - full_cache, get_fsalfirstlast, differentiation_rk_docstring + full_cache, get_fsalfirstlast, differentiation_rk_docstring, + bool_to_ADType import StaticArrays: SVector import MuladdMacro: @muladd import FastBroadcast: @.. From 1cf1b74b99ed6d4546c5b51307df8d0ae77b2bee Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 31 Oct 2024 18:47:16 -0400 Subject: [PATCH 032/203] needed for remake to work --- .../src/OrdinaryDiffEqBDF.jl | 1 + lib/OrdinaryDiffEqBDF/src/algorithms.jl | 67 ++++--- .../src/algorithms.jl | 18 +- .../src/algorithms.jl | 24 ++- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 24 ++- .../src/algorithms.jl | 12 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 6 +- .../src/OrdinaryDiffEqRosenbrock.jl | 4 +- .../src/algorithms.jl | 24 ++- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 175 ++++++++++++------ .../src/algorithms.jl | 6 +- 11 files changed, 240 insertions(+), 121 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index b665cd416f..072c572a52 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -32,6 +32,7 @@ using OrdinaryDiffEqDifferentiation: UJacobianWrapper using OrdinaryDiffEqNonlinearSolve: NLNewton, du_alias_or_new, build_nlsolver, nlsolve!, nlsolvefail, isnewton, markfirststage!, set_new_W!, DIRK, compute_step!, COEFFICIENT_MULTISTEP +import ADTypes import ADTypes: AutoForwardDiff, AbstractADType using Reexport diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 9beebd2c70..8617fb8e2b 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -120,10 +120,12 @@ function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta smooth_est = true, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ABDF2{ @@ -182,10 +184,12 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), tol = nothing, extrapolant = :linear, ark = false) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), @@ -208,10 +212,12 @@ function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag extrapolant = :linear, order, ark = false) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), @@ -316,10 +322,12 @@ function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant = :linear, kappa = -37 // 200, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end QNDF1{ @@ -378,10 +386,12 @@ function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant = :linear, kappa = -1 // 9, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end QNDF2{ @@ -451,10 +461,12 @@ function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), -37 // 200, -1 // 9, -823 // 10000, -83 // 2000, 0 // 1), controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end QNDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -500,10 +512,12 @@ function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end MEBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -562,10 +576,13 @@ function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), tol = nothing, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - if autodiff isa AbstractADType + println(autodiff) + if autodiff isa AbstracADType || autodiff <: AbstractADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end FBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -684,10 +701,12 @@ function DImplicitEuler(; extrapolant = :constant, controller = :Standard) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end DImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -729,10 +748,12 @@ function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt extrapolant = :constant, controller = :Standard) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end DABDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -796,10 +817,12 @@ function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), tol = nothing, extrapolant = :linear, controller = :Standard) where {MO} - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end DFBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index c92170a35e..a8a010fb97 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -39,10 +39,12 @@ for (Alg, Description, Ref) in [ chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end $Alg{_unwrap_val(chunk_size), typeof(AD_choice), @@ -85,10 +87,12 @@ for (Alg, Description, Ref) in [ concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end $Alg{_unwrap_val(chunk_size), typeof(AD_choice), @@ -149,10 +153,12 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index 8214f7739c..fe030b2499 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -73,10 +73,12 @@ function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForw max_order = 12, min_order = 3, init_order = 5, threading = false, sequence = :harmonic) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end linsolve = (linsolve === nothing && @@ -219,10 +221,12 @@ function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = Auto min_order = 1, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end # Enforce 1 <= min_order <= init_order <= max_order: @@ -405,10 +409,12 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end # Initialize algorithm ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), @@ -491,10 +497,12 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end # Initialize algorithm ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 051a770797..5fddb3ecc5 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -48,10 +48,12 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end RadauIIA3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -99,10 +101,12 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end RadauIIA5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -151,10 +155,12 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end RadauIIA9{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -197,10 +203,12 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index f5768b1313..71a9ff1f85 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -33,10 +33,12 @@ function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end CNAB2{ @@ -79,10 +81,12 @@ function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end CNLF2{ diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index d895ca53f4..d8d9b09662 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -34,10 +34,12 @@ function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standard linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, threading = true) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end PDIRK44{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 2562da74d6..69c16eebf5 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -12,7 +12,7 @@ import OrdinaryDiffEqCore: alg_order, alg_adaptive_order, isWmethod, isfsal, _un constvalue, only_diagonal_mass_matrix, calculate_residuals, has_stiff_interpolation, ODEIntegrator, resize_non_user_cache!, _ode_addsteps!, full_cache, - DerivativeOrderNotPossibleError + DerivativeOrderNotPossibleError, bool_to_ADType using MuladdMacro, FastBroadcast, RecursiveArrayTools import MacroTools using MacroTools: @capture @@ -22,7 +22,7 @@ import LinearSolve: UniformScaling import ForwardDiff using FiniteDiff using LinearAlgebra: mul!, diag, diagm, I, Diagonal, norm -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType import OrdinaryDiffEqCore using OrdinaryDiffEqDifferentiation: TimeDerivativeWrapper, TimeGradientWrapper, diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index c41b5913e2..a2dee8607e 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -117,10 +117,12 @@ for Alg in [ precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, stage_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or a `Bool`.") end $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -141,10 +143,12 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff() standardtag = Val{true}(), concrete_jac = nothing, factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end GeneralRosenbrock{ @@ -172,10 +176,12 @@ function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end RosenbrockW6S4OS{_unwrap_val(chunk_size), @@ -215,10 +221,12 @@ for Alg in [ standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 8bdaab0bee..e188c81eb7 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -115,10 +115,12 @@ function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), extrapolant = :constant, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -159,10 +161,12 @@ function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ImplicitMidpoint{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -209,10 +213,12 @@ function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -267,10 +273,12 @@ function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end TRBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -321,10 +329,12 @@ function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -370,10 +380,12 @@ function SDIRK22(; extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -429,10 +441,12 @@ function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :constant, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SSPSDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -481,10 +495,12 @@ function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Kvaerno3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -530,10 +546,12 @@ function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end KenCarp3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -572,10 +590,12 @@ function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end CFNLIRK3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -625,11 +645,12 @@ function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta smooth_est = true, extrapolant = :linear, controller = :PI, embedding = 3) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else - # deprecation path + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Cash4{ @@ -674,10 +695,12 @@ function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SFSDIRK4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -719,10 +742,12 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SFSDIRK5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -764,10 +789,12 @@ function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SFSDIRK6{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -809,10 +836,12 @@ function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SFSDIRK7{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -854,10 +883,12 @@ function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end SFSDIRK8{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -899,10 +930,12 @@ function Hairer4(; smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Hairer4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -942,10 +975,12 @@ function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Hairer42{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -994,10 +1029,12 @@ function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Kvaerno4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1046,10 +1083,12 @@ function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end Kvaerno5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1095,10 +1134,12 @@ function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end KenCarp4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1146,10 +1187,12 @@ function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end KenCarp47{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1195,10 +1238,12 @@ function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end KenCarp5{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1244,10 +1289,12 @@ function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end KenCarp58{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1292,10 +1339,12 @@ function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ESDIRK54I8L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1339,10 +1388,12 @@ function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ESDIRK436L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1386,10 +1437,12 @@ function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ESDIRK437L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1433,10 +1486,12 @@ function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ESDIRK547L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), @@ -1482,10 +1537,12 @@ function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end ESDIRK659L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index 1e4e3eb5cc..dd9e9c9ad6 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -25,10 +25,12 @@ function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag tol = nothing, extrapolant = :linear, controller = :Standard, eigen_est = nothing) - if autodiff isa AbstractADType + if autodiff isa AbstracADType || autodiff <: AbstractADType AD_choice = autodiff - else + elseif autodiff isa Bool AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) + else + error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") end IRKC{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), From b7d02d156c8b9ca78477cad14c68143ab38a12e7 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 4 Nov 2024 12:13:29 -0500 Subject: [PATCH 033/203] more imports --- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 5 +++-- .../src/OrdinaryDiffEqExponentialRK.jl | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 070524d8a3..d774158e54 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -9,12 +9,13 @@ import OrdinaryDiffEqCore: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCac constvalue, calculate_residuals, calculate_residuals!, trivial_limiter!, get_fsalfirstlast, generic_solver_docstring, - full_cache + full_cache, + bool_to_ADType import OrdinaryDiffEqLowOrderRK: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast import Static: False -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType import OrdinaryDiffEqCore using Reexport diff --git a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl index 7e78d7aabc..19833145f2 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEqCore: alg_order, alg_adaptive_order, ismultistep, ExponentialAlgorithm, fsal_typeof, isdtchangeable, calculate_residuals, calculate_residuals!, full_cache, get_fsalfirstlast, - generic_solver_docstring + generic_solver_docstring, bool_to_ADType import OrdinaryDiffEqCore using RecursiveArrayTools using MuladdMacro, FastBroadcast @@ -20,7 +20,7 @@ using ExponentialUtilities import RecursiveArrayTools: recursivecopy! using OrdinaryDiffEqDifferentiation: build_jac_config, UJacobianWrapper, UDerivativeWrapper, calc_J, calc_J! -import ADTypes: AutoForwardDiff +import ADTypes: AutoForwardDiff, AbstractADType using Reexport @reexport using DiffEqBase From 2be3ad809afd13867370771e90cf91097f63fd5c Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 4 Nov 2024 13:36:57 -0500 Subject: [PATCH 034/203] use AD.fdtype for derivative, change alg_autodiff to get AD --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 2 +- .../src/alg_utils.jl | 30 ++++++++++--------- .../src/derivative_wrappers.jl | 5 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index d5f89349d6..66e9c22949 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -232,7 +232,7 @@ function alg_difftype(alg::Union{ CJ}, DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST, CJ} - FDT + typeof(AD.fdtype) end function standardtag(alg::Union{ diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 50e605e409..d77e4c65be 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -2,28 +2,30 @@ function _alg_autodiff(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have an autodifferentiation option defined.") end -_alg_autodiff(::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} = Val{AD}() -_alg_autodiff(::DAEAlgorithm{CS, AD}) where {CS, AD} = Val{AD}() -_alg_autodiff(::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = Val{AD}() +_alg_autodiff(::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} = AD +_alg_autodiff(::DAEAlgorithm{CS, AD}) where {CS, AD} = AD +_alg_autodiff(::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = AD _alg_autodiff(alg::CompositeAlgorithm) = _alg_autodiff(alg.algs[end]) function _alg_autodiff(::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD} }) where { CS, AD } - Val{AD}() + AD end -function alg_autodiff(alg) - autodiff = _alg_autodiff(alg) - if autodiff == Val(false) - return AutoFiniteDiff() - elseif autodiff == Val(true) - return AutoForwardDiff() - else - return _unwrap_val(autodiff) - end -end +#function alg_autodiff(alg) +# autodiff = _alg_autodiff(alg) +# if autodiff == Val(false) +# return AutoFiniteDiff() +# elseif autodiff == Val(true) +# return AutoForwardDiff() +# else +# return _unwrap_val(autodiff) +# end +#end + +alg_autodiff(alg) = _alg_autodiff(alg) Base.@pure function determine_chunksize(u, alg::DiffEqBase.DEAlgorithm) determine_chunksize(u, get_chunksize(alg)) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 626d9fad7f..7efb0f7a45 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -80,7 +80,8 @@ function derivative!(df::AbstractArray{<:Number}, f, integrator, grad_config) alg = unwrap_alg(integrator, true) tmp = length(x) # We calculate derivative for all elements in gradient - if alg_autodiff(alg) isa AutoForwardDiff + autodiff_alg = alg_autodiff(alg) + if autodiff_alg isa AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(df))) else @@ -102,7 +103,7 @@ function derivative!(df::AbstractArray{<:Number}, f, df .= first.(ForwardDiff.partials.(grad_config)) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif autodiff_alg isa AutoFiniteDiff FiniteDiff.finite_difference_gradient!(df, f, x, grad_config, dir = diffdir(integrator)) fdtype = alg_difftype(alg) From c69f857db383217ac9e3eef023ccc5418def70fa Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 4 Nov 2024 19:53:52 -0500 Subject: [PATCH 035/203] switch to using _process_AD_choice --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 111 ++----- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 44 ++- lib/OrdinaryDiffEqCore/src/algorithms.jl | 2 +- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 14 +- .../src/algorithms.jl | 30 +- .../src/algorithms.jl | 40 +-- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 42 +-- .../src/algorithms.jl | 20 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 10 +- .../src/algorithms.jl | 42 +-- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 293 ++++-------------- .../src/algorithms.jl | 10 +- 12 files changed, 163 insertions(+), 495 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 8617fb8e2b..094041d65a 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -120,16 +120,10 @@ function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta smooth_est = true, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ABDF2{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}(linsolve, nlsolve, precs, κ, tol, smooth_est, extrapolant, controller, step_limiter!) @@ -184,15 +178,9 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), tol = nothing, extrapolant = :linear, ark = false) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -212,15 +200,9 @@ function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag extrapolant = :linear, order, ark = false) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -322,16 +304,10 @@ function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant = :linear, kappa = -37 // 200, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF1{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -386,16 +362,10 @@ function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant = :linear, kappa = -1 // 9, controller = :Standard, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF2{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -461,15 +431,9 @@ function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), -37 // 200, -1 // 9, -823 // 10000, -83 // 2000, 0 // 1), controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - QNDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + QNDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(kappa), typeof(step_limiter!)}( @@ -512,15 +476,9 @@ function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - MEBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + MEBDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -576,16 +534,9 @@ function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), tol = nothing, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - println(autodiff) - if autodiff isa AbstracADType || autodiff <: AbstractADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - FBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + FBDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}( @@ -701,15 +652,9 @@ function DImplicitEuler(; extrapolant = :constant, controller = :Standard) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + DImplicitEuler{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -748,15 +693,9 @@ function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt extrapolant = :constant, controller = :Standard) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DABDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + DABDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -817,15 +756,9 @@ function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), tol = nothing, extrapolant = :linear, controller = :Standard) where {MO} - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DFBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + DFBDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(max_order, linsolve, nlsolve, precs, κ, tol, extrapolant, diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 66e9c22949..a10ba40bfd 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -171,25 +171,31 @@ end function get_chunksize(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS}, - OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS}, - OrdinaryDiffEqImplicitAlgorithm{CS}, - OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS}, - DAEAlgorithm{CS}, - CompositeAlgorithm{CS}}) where {CS} - Val(CS) + +_get_fwd_chunksize(AD::AutoForwardDiff{CS}) where {CS} = Val(CS) +_get_fwd_chunksize_int(AD::AutoForwardDiff{CS}) where {CS} = CS +_get_fwd_chunksize(AD) = Val(0) + + +function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{AD}, + OrdinaryDiffEqAdaptiveExponentialAlgorithm{AD}, + OrdinaryDiffEqImplicitAlgorithm{AD}, + OrdinaryDiffEqAdaptiveImplicitAlgorithm{AD}, + DAEAlgorithm{AD}, + CompositeAlgorithm{AD}}) where {AD} + _get_fwd_chunksize(AD) end function get_chunksize_int(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -function get_chunksize_int(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS}, - OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS}, - OrdinaryDiffEqImplicitAlgorithm{CS}, - OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS}, - DAEAlgorithm{CS}, - CompositeAlgorithm{CS}}) where {CS} - CS +function get_chunksize_int(alg::Union{OrdinaryDiffEqExponentialAlgorithm{AD}, + OrdinaryDiffEqAdaptiveExponentialAlgorithm{AD}, + OrdinaryDiffEqImplicitAlgorithm{AD}, + OrdinaryDiffEqAdaptiveImplicitAlgorithm{AD}, + DAEAlgorithm{AD}, + CompositeAlgorithm{AD}}) where {AD} + _get_fwd_chunksize_int(AD) end # get_chunksize(alg::CompositeAlgorithm) = get_chunksize(alg.algs[alg.current_alg]) @@ -444,3 +450,13 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end print(io, ")") end + + +function get_chunksize(alg::AutoForwardDiff{chunksize}) where {chunksize} + Val(chunksize) +end + + +remake_AD(ad) + +remake_AD() \ No newline at end of file diff --git a/lib/OrdinaryDiffEqCore/src/algorithms.jl b/lib/OrdinaryDiffEqCore/src/algorithms.jl index 01c24467a6..b391cf61c4 100644 --- a/lib/OrdinaryDiffEqCore/src/algorithms.jl +++ b/lib/OrdinaryDiffEqCore/src/algorithms.jl @@ -61,7 +61,7 @@ function DiffEqBase.remake( kwargs...) where {CS, AD, FDT, ST, CJ} T = SciMLBase.remaker_of(thing) T(; SciMLBase.struct_as_namedtuple(thing)..., - chunk_size = Val{CS}(), autodiff = Val{AD}(), standardtag = Val{ST}(), + chunk_size = Val{CS}(), autodiff = AD(_get_fwd_tag(AD)), standardtag = Val{ST}(), concrete_jac = CJ === nothing ? CJ : Val{CJ}(), kwargs...) end diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index e3f21c8c88..9f6b6e278a 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -132,12 +132,20 @@ end isnewton(::Any) = false -function bool_to_ADType(AD::Val{true}, chunk_size, diff_type) +function bool_to_ADType(::Val{true}, chunk_size, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize)) end -function bool_to_ADType(AD::Val{false}, chunk_size, diff_type) +function bool_to_ADType(::Val{false}, chunk_size, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) AutoFiniteDiff(fdtype = diff_type) -end \ No newline at end of file +end + +# Functions to get ADType type from Bool or ADType object, or ADType type +_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = bool_to_ADType(ad_alg, chunksize, diff_type) + +_process_AD_choice(ad_alg::Type{<:AbstractADType}, chunksize, diff_type) = ad_alg + +_process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) = typeof(ad_alg) + diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index a8a010fb97..87eecc510a 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -39,15 +39,9 @@ for (Alg, Description, Ref) in [ chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), typeof(AD_choice), + $Alg{_unwrap_val(chunk_size), AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(krylov, m, iop) @@ -87,15 +81,9 @@ for (Alg, Description, Ref) in [ concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), typeof(AD_choice), + $Alg{_unwrap_val(chunk_size), AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(m, iop) @@ -153,15 +141,9 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, + $Alg{_unwrap_val(chunk_size), AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(adaptive_krylov, m, iop) diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index fe030b2499..8707f56ac8 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -73,13 +73,7 @@ function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForw max_order = 12, min_order = 3, init_order = 5, threading = false, sequence = :harmonic) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) linsolve = (linsolve === nothing && (threading == true || threading isa PolyesterThreads)) ? @@ -108,7 +102,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") :$(sequence) --> :harmonic" sequence = :harmonic end - ImplicitEulerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), + ImplicitEulerExtrapolation{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, max_order, min_order, @@ -221,13 +215,7 @@ function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = Auto min_order = 1, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Enforce 1 <= min_order <= init_order <= max_order: min_order = max(1, min_order) @@ -260,7 +248,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") end # Initialize algorithm - ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), + ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -409,15 +397,9 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), + ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -497,15 +479,9 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") sequence = :harmonic end - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), + ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 5fddb3ecc5..4b3a2f0dd0 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -48,15 +48,9 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end - - RadauIIA3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) + + RadauIIA3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -101,15 +95,9 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + RadauIIA5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -155,15 +143,9 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA9{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + RadauIIA9{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -203,15 +185,9 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + AdaptiveRadau{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index 71a9ff1f85..3470a3b193 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -33,16 +33,10 @@ function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNAB2{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -81,16 +75,10 @@ function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNLF2{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index d8d9b09662..080b819d17 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -34,15 +34,9 @@ function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standard linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, threading = true) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - PDIRK44{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + PDIRK44{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, nlsolve, precs, extrapolant, threading) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index a2dee8607e..8b310862b4 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -117,15 +117,9 @@ for Alg in [ precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, stage_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or a `Bool`.") - end - - $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) + + $Alg{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!), typeof(stage_limiter!)}(linsolve, precs, step_limiter!, @@ -143,16 +137,10 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff() standardtag = Val{true}(), concrete_jac = nothing, factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) GeneralRosenbrock{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(factorization), + _unwrap_val(chunk_size), AD_choice), typeof(factorization), _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, factorization) end @@ -176,16 +164,10 @@ function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RosenbrockW6S4OS{_unwrap_val(chunk_size), - typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, + AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) end @@ -221,15 +203,9 @@ for Alg in [ standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + $Alg{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index e188c81eb7..6ba1001b83 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -115,15 +115,9 @@ function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), extrapolant = :constant, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end - - ImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) + + ImplicitEuler{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, controller, step_limiter!) @@ -161,15 +155,9 @@ function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ImplicitMidpoint{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + ImplicitMidpoint{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -213,15 +201,9 @@ function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -272,16 +254,9 @@ function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end - - TRBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + TRBDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -329,15 +304,9 @@ function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SDIRK2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}( linsolve, nlsolve, precs, smooth_est, extrapolant, @@ -380,15 +349,9 @@ function SDIRK22(; extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -441,15 +404,9 @@ function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :constant, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SSPSDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SSPSDIRK2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -495,15 +452,9 @@ function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Kvaerno3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -546,15 +497,9 @@ function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + KenCarp3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -590,15 +535,9 @@ function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - CFNLIRK3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + CFNLIRK3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -645,16 +584,10 @@ function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta smooth_est = true, extrapolant = :linear, controller = :PI, embedding = 3) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Cash4{ - _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -695,15 +628,9 @@ function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SFSDIRK4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -742,15 +669,9 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SFSDIRK5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -789,15 +710,9 @@ function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK6{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SFSDIRK6{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -836,15 +751,9 @@ function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK7{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SFSDIRK7{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -883,15 +792,9 @@ function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK8{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + SFSDIRK8{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -930,15 +833,9 @@ function Hairer4(; smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Hairer4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -975,15 +872,9 @@ function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer42{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Hairer42{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1029,15 +920,9 @@ function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Kvaerno4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1083,15 +968,9 @@ function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + Kvaerno5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1134,15 +1013,9 @@ function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + KenCarp4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1187,15 +1060,9 @@ function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp47{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + KenCarp47{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1238,15 +1105,9 @@ function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp5{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + KenCarp5{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1289,15 +1150,9 @@ function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), smooth_est = true, extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp58{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + KenCarp58{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1339,15 +1194,9 @@ function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK54I8L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + ESDIRK54I8L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1388,15 +1237,9 @@ function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK436L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + ESDIRK436L2SA2{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1437,15 +1280,9 @@ function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK437L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + ESDIRK437L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1486,15 +1323,9 @@ function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK547L2SA2{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + ESDIRK547L2SA2{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1537,15 +1368,9 @@ function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK659L2SA{_unwrap_val(chunk_size),typeof(AD_choice), typeof(linsolve), + ESDIRK659L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index dd9e9c9ad6..580d0400b9 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -25,15 +25,9 @@ function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag tol = nothing, extrapolant = :linear, controller = :Standard, eigen_est = nothing) - if autodiff isa AbstracADType || autodiff <: AbstractADType - AD_choice = autodiff - elseif autodiff isa Bool - AD_choice = bool_to_ADType(autodiff, chunk_size, diff_type) - else - error("Keyword `autodiff` should be an `AbstractADType` or `Bool`.") - end + AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - IRKC{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), + IRKC{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(eigen_est)}(linsolve, nlsolve, precs, κ, tol, extrapolant, controller, eigen_est) From 602214ba365d8c3cf6f7834fe161f01ca93a25f3 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 4 Nov 2024 19:58:26 -0500 Subject: [PATCH 036/203] erroneous ) --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 22 +++---- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 9 +-- .../src/algorithms.jl | 6 +- .../src/algorithms.jl | 8 +-- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 8 +-- .../src/algorithms.jl | 4 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 2 +- .../src/algorithms.jl | 8 +-- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 58 +++++++++---------- .../src/algorithms.jl | 2 +- 10 files changed, 61 insertions(+), 66 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 094041d65a..197c48efa3 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -123,7 +123,7 @@ function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ABDF2{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}(linsolve, nlsolve, precs, κ, tol, smooth_est, extrapolant, controller, step_limiter!) @@ -180,7 +180,7 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -202,7 +202,7 @@ function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -307,7 +307,7 @@ function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF1{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -365,7 +365,7 @@ function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF2{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -433,7 +433,7 @@ function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - QNDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), + QNDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(kappa), typeof(step_limiter!)}( @@ -478,7 +478,7 @@ function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - MEBDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + MEBDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -536,7 +536,7 @@ function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - FBDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), + FBDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}( @@ -654,7 +654,7 @@ function DImplicitEuler(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DImplicitEuler{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + DImplicitEuler{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -695,7 +695,7 @@ function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DABDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + DABDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -758,7 +758,7 @@ function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DFBDF{MO, _unwrap_val(chunk_size), AD_choice), typeof(linsolve), + DFBDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(max_order, linsolve, nlsolve, precs, κ, tol, extrapolant, diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index a10ba40bfd..85bb60bdaf 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -452,11 +452,6 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end -function get_chunksize(alg::AutoForwardDiff{chunksize}) where {chunksize} - Val(chunksize) +function get_chunksize(alg::AutoForwardDiff{CS}) where {CS} + Val(CS) end - - -remake_AD(ad) - -remake_AD() \ No newline at end of file diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index 87eecc510a..8be1efc709 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -41,7 +41,7 @@ for (Alg, Description, Ref) in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice), + $Alg{_unwrap_val(chunk_size), AD_choice, diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(krylov, m, iop) @@ -83,7 +83,7 @@ for (Alg, Description, Ref) in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice), + $Alg{_unwrap_val(chunk_size), AD_choice, diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(m, iop) @@ -143,7 +143,7 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice), diff_type, + $Alg{_unwrap_val(chunk_size), AD_choice, diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(adaptive_krylov, m, iop) diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index 8707f56ac8..b099c0834b 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -102,7 +102,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") :$(sequence) --> :harmonic" sequence = :harmonic end - ImplicitEulerExtrapolation{_unwrap_val(chunk_size), AD_choice), + ImplicitEulerExtrapolation{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, max_order, min_order, @@ -248,7 +248,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") end # Initialize algorithm - ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), AD_choice), + ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -399,7 +399,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), AD_choice), + ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, @@ -481,7 +481,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), AD_choice), + ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 4b3a2f0dd0..367bed94df 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -50,7 +50,7 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + RadauIIA3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -97,7 +97,7 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + RadauIIA5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -145,7 +145,7 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA9{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + RadauIIA9{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -187,7 +187,7 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - AdaptiveRadau{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + AdaptiveRadau{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index 3470a3b193..d34343e3ca 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -36,7 +36,7 @@ function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNAB2{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -78,7 +78,7 @@ function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNLF2{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index 080b819d17..d961d88d1a 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -36,7 +36,7 @@ function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standard AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - PDIRK44{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + PDIRK44{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, nlsolve, precs, extrapolant, threading) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index 8b310862b4..c6211883e8 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -119,7 +119,7 @@ for Alg in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + $Alg{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!), typeof(stage_limiter!)}(linsolve, precs, step_limiter!, @@ -140,7 +140,7 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff() AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) GeneralRosenbrock{ - _unwrap_val(chunk_size), AD_choice), typeof(factorization), + _unwrap_val(chunk_size), AD_choice, typeof(factorization), _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, factorization) end @@ -167,7 +167,7 @@ function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RosenbrockW6S4OS{_unwrap_val(chunk_size), - AD_choice), typeof(linsolve), typeof(precs), diff_type, + AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) end @@ -205,7 +205,7 @@ for Alg in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + $Alg{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, precs) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 6ba1001b83..5b5dcaca1a 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -117,7 +117,7 @@ function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ImplicitEuler{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + ImplicitEuler{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, controller, step_limiter!) @@ -157,7 +157,7 @@ function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ImplicitMidpoint{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + ImplicitMidpoint{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -203,7 +203,7 @@ function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -256,7 +256,7 @@ function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt controller = :PI, step_limiter! = trivial_limiter!) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - TRBDF2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + TRBDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -306,7 +306,7 @@ function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SDIRK2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SDIRK2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}( linsolve, nlsolve, precs, smooth_est, extrapolant, @@ -351,7 +351,7 @@ function SDIRK22(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, @@ -406,7 +406,7 @@ function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SSPSDIRK2{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SSPSDIRK2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -454,7 +454,7 @@ function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Kvaerno3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -499,7 +499,7 @@ function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + KenCarp3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -537,7 +537,7 @@ function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - CFNLIRK3{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + CFNLIRK3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -587,7 +587,7 @@ function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Cash4{ - _unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -630,7 +630,7 @@ function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SFSDIRK4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -671,7 +671,7 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SFSDIRK5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -712,7 +712,7 @@ function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK6{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SFSDIRK6{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -753,7 +753,7 @@ function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK7{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SFSDIRK7{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -794,7 +794,7 @@ function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK8{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + SFSDIRK8{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, @@ -835,7 +835,7 @@ function Hairer4(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Hairer4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -874,7 +874,7 @@ function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer42{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Hairer42{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -922,7 +922,7 @@ function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Kvaerno4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -970,7 +970,7 @@ function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno5{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + Kvaerno5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1015,7 +1015,7 @@ function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp4{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), + KenCarp4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1062,7 +1062,7 @@ function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp47{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + KenCarp47{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1107,7 +1107,7 @@ function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp5{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + KenCarp5{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller, step_limiter!) @@ -1152,7 +1152,7 @@ function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp58{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + KenCarp58{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, controller) @@ -1196,7 +1196,7 @@ function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK54I8L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + ESDIRK54I8L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1239,7 +1239,7 @@ function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK436L2SA2{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + ESDIRK436L2SA2{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1282,7 +1282,7 @@ function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK437L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + ESDIRK437L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1325,7 +1325,7 @@ function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK547L2SA2{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + ESDIRK547L2SA2{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) @@ -1370,7 +1370,7 @@ function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK659L2SA{_unwrap_val(chunk_size),AD_choice), typeof(linsolve), + ESDIRK659L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, controller) diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index 580d0400b9..9be6e769da 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -27,7 +27,7 @@ function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - IRKC{_unwrap_val(chunk_size), AD_choice), typeof(linsolve), typeof(nlsolve), + IRKC{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(eigen_est)}(linsolve, nlsolve, precs, κ, tol, extrapolant, controller, eigen_est) From d50ca9924347bc2cd473440a718e4bcfabfe8d97 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 11:12:34 -0500 Subject: [PATCH 037/203] need to change to get the ADType type from alg_autodiff, then use in diff --- .../OrdinaryDiffEqAdamsBashforthMoulton.jl | 2 +- .../src/OrdinaryDiffEqBDF.jl | 3 ++- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 6 ++--- lib/OrdinaryDiffEqCore/src/algorithms.jl | 2 +- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 10 ++++----- .../src/OrdinaryDiffEqDifferentiation.jl | 2 +- .../src/alg_utils.jl | 2 +- .../src/derivative_utils.jl | 2 +- .../src/derivative_wrappers.jl | 22 +++++++++---------- .../src/OrdinaryDiffEqExponentialRK.jl | 2 +- .../src/OrdinaryDiffEqExtrapolation.jl | 2 +- .../src/OrdinaryDiffEqFIRK.jl | 3 ++- .../src/OrdinaryDiffEqIMEXMultistep.jl | 2 +- lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl | 2 +- .../src/OrdinaryDiffEqPDIRK.jl | 2 +- .../src/OrdinaryDiffEqRosenbrock.jl | 3 ++- .../src/OrdinaryDiffEqSDIRK.jl | 2 +- .../src/OrdinaryDiffEqStabilizedIRK.jl | 2 +- 18 files changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index d774158e54..1c26aac834 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEqCore: OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCac trivial_limiter!, get_fsalfirstlast, generic_solver_docstring, full_cache, - bool_to_ADType + _bool_to_ADType import OrdinaryDiffEqLowOrderRK: BS3ConstantCache, BS3Cache, RK4ConstantCache, RK4Cache import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index 072c572a52..584dea5e04 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -20,7 +20,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, step_accept_controller!, step_reject_controller!, post_newton_controller!, u_modified!, DAEAlgorithm, _unwrap_val, DummyController, - get_fsalfirstlast, generic_solver_docstring, bool_to_ADType + get_fsalfirstlast, generic_solver_docstring, _bool_to_ADType, + _process_AD_choice using OrdinaryDiffEqSDIRK: ImplicitEulerConstantCache, ImplicitEulerCache using TruncatedStacktraces, MuladdMacro, MacroTools, FastBroadcast, RecursiveArrayTools diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 85bb60bdaf..1b2d845729 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -12,7 +12,7 @@ end function SciMLBase.forwarddiffs_model(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorithm, DAEAlgorithm, OrdinaryDiffEqImplicitAlgorithm, ExponentialAlgorithm}) - alg_autodiff(alg) isa AutoForwardDiff + nameof(alg_autodiff(alg)) == :AutoForwardDiff end SciMLBase.forwarddiffs_model_time(alg::RosenbrockAlgorithm) = true @@ -172,8 +172,8 @@ function get_chunksize(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -_get_fwd_chunksize(AD::AutoForwardDiff{CS}) where {CS} = Val(CS) -_get_fwd_chunksize_int(AD::AutoForwardDiff{CS}) where {CS} = CS +_get_fwd_chunksize(AD::AutoForwardDiff{CS, T}) where {CS, T} = Val(CS) +_get_fwd_chunksize_int(AD::AutoForwardDiff{CS, T}) where {CS, T} = CS _get_fwd_chunksize(AD) = Val(0) diff --git a/lib/OrdinaryDiffEqCore/src/algorithms.jl b/lib/OrdinaryDiffEqCore/src/algorithms.jl index b391cf61c4..500e926fc2 100644 --- a/lib/OrdinaryDiffEqCore/src/algorithms.jl +++ b/lib/OrdinaryDiffEqCore/src/algorithms.jl @@ -61,7 +61,7 @@ function DiffEqBase.remake( kwargs...) where {CS, AD, FDT, ST, CJ} T = SciMLBase.remaker_of(thing) T(; SciMLBase.struct_as_namedtuple(thing)..., - chunk_size = Val{CS}(), autodiff = AD(_get_fwd_tag(AD)), standardtag = Val{ST}(), + chunk_size = Val{CS}(), autodiff = AD, standardtag = Val{ST}(), concrete_jac = CJ === nothing ? CJ : Val{CJ}(), kwargs...) end diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 9f6b6e278a..027be53f95 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -132,18 +132,18 @@ end isnewton(::Any) = false -function bool_to_ADType(::Val{true}, chunk_size, diff_type) - Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) +function _bool_to_ADType(::Val{true}, chunk_size, diff_type) + Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize)) end -function bool_to_ADType(::Val{false}, chunk_size, diff_type) - Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :bool_to_ADType) +function _bool_to_ADType(::Val{false}, chunk_size, diff_type) + Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) AutoFiniteDiff(fdtype = diff_type) end # Functions to get ADType type from Bool or ADType object, or ADType type -_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = bool_to_ADType(ad_alg, chunksize, diff_type) +_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(ad_alg, chunksize, diff_type) _process_AD_choice(ad_alg::Type{<:AbstractADType}, chunksize, diff_type) = ad_alg diff --git a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl index bc1e42339d..c9fcaa68ef 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl @@ -27,7 +27,7 @@ import StaticArrays: SArray, MVector, SVector, @SVector, StaticArray, MMatrix, S using DiffEqBase: TimeGradientWrapper, UJacobianWrapper, TimeDerivativeWrapper, UDerivativeWrapper -using SciMLBase: AbstractSciMLOperator +using SciMLBase: AbstractSciMLOperator, constructorof import OrdinaryDiffEqCore using OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveImplicitAlgorithm, DAEAlgorithm, diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index d77e4c65be..bec21e770a 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -50,7 +50,7 @@ function DiffEqBase.prepare_alg( # If not using autodiff or norecompile mode or very large bitsize (like a dual number u0 already) # don't use a large chunksize as it will either error or not be beneficial - if !(alg_autodiff(alg) isa AutoForwardDiff) || + if !(nameof(alg_autodiff(alg)) == :AutoForwardDiff) || (isbitstype(T) && sizeof(T) > 24) || (prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl index abf994e5bc..250e1fb02b 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl @@ -144,7 +144,7 @@ function calc_J!(J, integrator, cache, next_step::Bool = false) f.jac(J, uprev, p, t) else @unpack du1, uf, jac_config = cache - + println(typeof(cache)) uf.f = nlsolve_f(f, alg) uf.t = t if !(p isa DiffEqBase.NullParameters) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 7efb0f7a45..e58d930d43 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -125,7 +125,7 @@ function derivative(f, x::Union{Number, AbstractArray{<:Number}}, local d tmp = length(x) # We calculate derivative for all elements in gradient alg = unwrap_alg(integrator, true) - if alg_autodiff(alg) isa AutoForwardDiff + if nameof(alg_autodiff(alg)) == :AutoForwardDiff OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) if integrator.iter == 1 try @@ -136,7 +136,7 @@ function derivative(f, x::Union{Number, AbstractArray{<:Number}}, else d = ForwardDiff.derivative(f, x) end - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff d = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(alg), dir = diffdir(integrator)) if alg_difftype(alg) === Val{:central} || alg_difftype(alg) === Val{:forward} @@ -192,7 +192,7 @@ end function jacobian(f, x, integrator) alg = unwrap_alg(integrator, true) local tmp - if alg_autodiff(alg) isa AutoForwardDiff + if nameof(alg_autodiff(alg)) == :AutoForwardDiff if integrator.iter == 1 try J, tmp = jacobian_autodiff(f, x, integrator.f, alg) @@ -202,7 +202,7 @@ function jacobian(f, x, integrator) else J, tmp = jacobian_autodiff(f, x, integrator.f, alg) end - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff jac_prototype = integrator.f.jac_prototype sparsity, colorvec = sparsity_colorvec(integrator.f, x) dir = diffdir(integrator) @@ -230,7 +230,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number}, fx::AbstractArray{<:Number}, integrator::DiffEqBase.DEIntegrator, jac_config) alg = unwrap_alg(integrator, true) - if alg_autodiff(alg) isa AutoForwardDiff + if nameof(alg_autodiff(alg)) == :AutoForwardDiff if integrator.iter == 1 try forwarddiff_color_jacobian!(J, f, x, jac_config) @@ -241,7 +241,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number}, forwarddiff_color_jacobian!(J, f, x, jac_config) end OrdinaryDiffEqCore.increment_nf!(integrator.stats, maximum(jac_config.colorvec)) - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff isforward = alg_difftype(alg) === Val{:forward} if isforward forwardcache = get_tmp_cache(integrator, alg, unwrap_cache(integrator, true))[2] @@ -280,9 +280,9 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 end sparsity, colorvec = sparsity_colorvec(f, u) - - if alg_autodiff(alg) isa AutoForwardDiff + if nameof(alg_autodiff(alg)) == :AutoForwardDiff _chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... + println(get_chunksize(alg)) T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) else @@ -290,7 +290,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 end jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff if alg_difftype(alg) !== Val{:complex} jac_config = FiniteDiff.JacobianCache(tmp, du1, du2, alg_difftype(alg), colorvec = colorvec, @@ -358,7 +358,7 @@ end function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} if !DiffEqBase.has_tgrad(f) - if alg_autodiff(alg) isa AutoForwardDiff + if nameof(alg_autodiff(alg)) == :AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(du1))) else @@ -380,7 +380,7 @@ function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} (ForwardDiff.Partials((one(eltype(du1)),)),)) .* false) end - elseif alg_autodiff(alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff grad_config = FiniteDiff.GradientCache(du1, t, alg_difftype(alg)) else error("$alg_autodiff not yet supported in build_grad_config function") diff --git a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl index 19833145f2..6fe57c7b40 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/OrdinaryDiffEqExponentialRK.jl @@ -10,7 +10,7 @@ import OrdinaryDiffEqCore: alg_order, alg_adaptive_order, ismultistep, ExponentialAlgorithm, fsal_typeof, isdtchangeable, calculate_residuals, calculate_residuals!, full_cache, get_fsalfirstlast, - generic_solver_docstring, bool_to_ADType + generic_solver_docstring, _bool_to_ADType, _process_AD_choice import OrdinaryDiffEqCore using RecursiveArrayTools using MuladdMacro, FastBroadcast diff --git a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl index 053c7a885b..81cda321b9 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl @@ -17,7 +17,7 @@ import OrdinaryDiffEqCore: alg_order, alg_maximum_order, get_current_adaptive_or constvalue, PolyesterThreads, Sequential, BaseThreads, _digest_beta1_beta2, timedepentdtmin, _unwrap_val, _reshape, _vec, get_fsalfirstlast, generic_solver_docstring, - differentiation_rk_docstring, bool_to_ADType + differentiation_rk_docstring, _bool_to_ADType, _process_AD_choice using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools, LinearSolve import OrdinaryDiffEqCore import FastPower diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 558744512d..c7eda015ad 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -16,7 +16,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, PredictiveController, alg_can_repeat_jac, NewtonAlgorithm, fac_default_gamma, get_current_adaptive_order, get_fsalfirstlast, - isfirk, generic_solver_docstring, bool_to_ADType + isfirk, generic_solver_docstring, _bool_to_ADType, + _process_AD_choice using MuladdMacro, DiffEqBase, RecursiveArrayTools using SciMLOperators: AbstractSciMLOperator using LinearAlgebra: I, UniformScaling, mul!, lu diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl index 4b82f150b0..998c4a96f2 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/OrdinaryDiffEqIMEXMultistep.jl @@ -5,7 +5,7 @@ import OrdinaryDiffEqCore: alg_order, issplit, OrdinaryDiffEqNewtonAlgorithm, _u OrdinaryDiffEqMutableCache, @cache, alg_cache, initialize!, perform_step!, @unpack, full_cache, get_fsalfirstlast, - generic_solver_docstring, bool_to_ADType + generic_solver_docstring, _bool_to_ADType, _process_AD_choice using FastBroadcast import OrdinaryDiffEqCore diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl index 3bed6a453a..0408ff5f26 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl @@ -72,7 +72,7 @@ mutable struct DAEResidualJacobianWrapper{isAD, F, pType, duType, uType, alphaTy uprev::uprevType t::tType function DAEResidualJacobianWrapper(alg, f, p, α, invγdt, tmp, uprev, t) - isautodiff = alg_autodiff(alg) isa AutoForwardDiff + isautodiff = nameof(alg_autodiff(alg)) == :AutoForwardDiff if isautodiff tmp_du = PreallocationTools.dualcache(uprev) tmp_u = PreallocationTools.dualcache(uprev) diff --git a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl index a468f4e558..393aade86a 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/OrdinaryDiffEqPDIRK.jl @@ -6,7 +6,7 @@ import OrdinaryDiffEqCore: isfsal, alg_order, _unwrap_val, uses_uprev, @unpack, unwrap_alg, @cache, DEFAULT_PRECS, @threaded, initialize!, perform_step!, isthreaded, full_cache, get_fsalfirstlast, differentiation_rk_docstring, - bool_to_ADType + _bool_to_ADType, _process_AD_choice import StaticArrays: SVector import MuladdMacro: @muladd import FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 69c16eebf5..6ba64ee4ab 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -12,7 +12,8 @@ import OrdinaryDiffEqCore: alg_order, alg_adaptive_order, isWmethod, isfsal, _un constvalue, only_diagonal_mass_matrix, calculate_residuals, has_stiff_interpolation, ODEIntegrator, resize_non_user_cache!, _ode_addsteps!, full_cache, - DerivativeOrderNotPossibleError, bool_to_ADType + DerivativeOrderNotPossibleError, _bool_to_ADType, + _process_AD_choice using MuladdMacro, FastBroadcast, RecursiveArrayTools import MacroTools using MacroTools: @capture diff --git a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl index 1a2b07cc36..f69aefe945 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/OrdinaryDiffEqSDIRK.jl @@ -14,7 +14,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, trivial_limiter!, _ode_interpolant!, isesdirk, issplit, ssp_coefficient, get_fsalfirstlast, generic_solver_docstring, - bool_to_ADType + _bool_to_ADType, _process_AD_choice using TruncatedStacktraces, MuladdMacro, MacroTools, FastBroadcast, RecursiveArrayTools using SciMLBase: SplitFunction using LinearAlgebra: mul!, I diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl index b4f2fea7c0..b2e154c6f4 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/OrdinaryDiffEqStabilizedIRK.jl @@ -11,7 +11,7 @@ import OrdinaryDiffEqCore: alg_order, alg_maximum_order, OrdinaryDiffEqAdaptiveImplicitAlgorithm, alg_cache, _unwrap_val, DEFAULT_PRECS, @cache, _reshape, _vec, full_cache, get_fsalfirstlast, - generic_solver_docstring, bool_to_ADType + generic_solver_docstring, _bool_to_ADType, _process_AD_choice using OrdinaryDiffEqDifferentiation: dolinsolve, update_W! using OrdinaryDiffEqNonlinearSolve: NLNewton, nlsolve!, isnewton, build_nlsolver, From 427ed531ab8fef0efb67650e7eb45f3cc5b1c538 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 15:35:50 -0500 Subject: [PATCH 038/203] need nameofs --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 2 +- .../src/derivative_wrappers.jl | 5 ++--- .../src/linsolve_utils.jl | 4 ++-- lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl | 10 +++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 0034e55d9a..f60aff3dcd 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -150,7 +150,7 @@ function _initialize_dae!(integrator, prob::AbstractDEProblem, isAD = if iu0 === nothing AutoForwardDiff elseif has_autodiff(integrator.alg) - alg_autodiff(integrator.alg) isa AutoForwardDiff + nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff else true end diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index e58d930d43..61ed338d25 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -81,7 +81,7 @@ function derivative!(df::AbstractArray{<:Number}, f, alg = unwrap_alg(integrator, true) tmp = length(x) # We calculate derivative for all elements in gradient autodiff_alg = alg_autodiff(alg) - if autodiff_alg isa AutoForwardDiff + if nameof(autodiff_alg) == :AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(df))) else @@ -103,7 +103,7 @@ function derivative!(df::AbstractArray{<:Number}, f, df .= first.(ForwardDiff.partials.(grad_config)) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - elseif autodiff_alg isa AutoFiniteDiff + elseif nameof(autodiff_alg) == :AutoFiniteDiff FiniteDiff.finite_difference_gradient!(df, f, x, grad_config, dir = diffdir(integrator)) fdtype = alg_difftype(alg) @@ -282,7 +282,6 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 sparsity, colorvec = sparsity_colorvec(f, u) if nameof(alg_autodiff(alg)) == :AutoForwardDiff _chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... - println(get_chunksize(alg)) T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) else diff --git a/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl index aa48161e1b..93a46b5730 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl @@ -32,9 +32,9 @@ function dolinsolve(integrator, linsolve; A = nothing, linu = nothing, b = nothi if integrator isa SciMLBase.DEIntegrator && _alg.linsolve !== nothing && !LinearSolve.needs_concrete_A(_alg.linsolve) && linsolve.A isa WOperator && linsolve.A.J isa AbstractSciMLOperator - if alg_autodiff(_alg) isa AutoForwardDiff + if nameof(alg_autodiff(_alg)) == :AutoForwardDiff integrator.stats.nf += linres.iters - elseif alg_autodiff(_alg) isa AutoFiniteDiff + elseif nameof(alg_autodiff(_alg)) == :AutoFiniteDiff OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) * linres.iters else error("$alg_autodiff not yet supported in dolinsolve function") diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl index b5cffde762..75fdf9f177 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl @@ -87,7 +87,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, alg::ShampineCollocation tmp = copy(_u0) end - isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || + isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u0) !== typeof(_u0) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) @@ -249,7 +249,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, tmp = copy(_u0) end - isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u0) !== typeof(_u0) + isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u0) !== typeof(_u0) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) _tmp = PreallocationTools.dualcache(tmp, chunk) @@ -392,7 +392,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, tmp = DiffEqBase.value.(tmp) end - isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u) !== typeof(_u) + isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u) !== typeof(_u) if isAD csize = count(algebraic_vars) if !(p isa SciMLBase.NullParameters) && typeof(_u) !== typeof(u) @@ -462,7 +462,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, integrator.opts.internalnorm(resid, t) <= alg.abstol && return - isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff + isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff if isAD chunk = ForwardDiff.pickchunksize(count(algebraic_vars)) _tmp = PreallocationTools.dualcache(similar(u0), chunk) @@ -545,7 +545,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, error("differential_vars must be set for DAE initialization to occur. Either set consistent initial conditions, differential_vars, or use a different initialization algorithm.") end - isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u) !== typeof(_u) + isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u) !== typeof(_u) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) _tmp = PreallocationTools.dualcache(tmp, chunk) From 34f3c362000f815fc881acce4602911b2c817f7d Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 17:12:03 -0500 Subject: [PATCH 039/203] no need to use CS now I thinkg --- lib/OrdinaryDiffEqCore/src/algorithms.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/algorithms.jl b/lib/OrdinaryDiffEqCore/src/algorithms.jl index 500e926fc2..18241648f3 100644 --- a/lib/OrdinaryDiffEqCore/src/algorithms.jl +++ b/lib/OrdinaryDiffEqCore/src/algorithms.jl @@ -88,7 +88,8 @@ struct CompositeAlgorithm{CS, T, F} <: OrdinaryDiffEqCompositeAlgorithm algs::T choice_function::F function CompositeAlgorithm(algs::T, choice_function::F) where {T, F} - CS = mapreduce(alg -> has_chunksize(alg) ? get_chunksize_int(alg) : 0, max, algs) + #CS = mapreduce(alg -> has_chunksize(alg) ? get_chunksize_int(alg) : 0, max, algs) + CS = mapreduce(alg -> 0, max, algs) new{CS, T, F}(algs, choice_function) end end From 4d1a8644133eec19605927842f2a32d2060463e4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 17:12:20 -0500 Subject: [PATCH 040/203] fix getting chunksize --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 39 ++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 1b2d845729..6ffd3b31ab 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -172,31 +172,36 @@ function get_chunksize(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -_get_fwd_chunksize(AD::AutoForwardDiff{CS, T}) where {CS, T} = Val(CS) -_get_fwd_chunksize_int(AD::AutoForwardDiff{CS, T}) where {CS, T} = CS +_get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) +_get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS _get_fwd_chunksize(AD) = Val(0) +_get_fwd_chunksize_int(AD) = 0 +_get_fwd_tag(::Type{AutoForwardDiff{CS,T}}) where {CS,T} = T -function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{AD}, - OrdinaryDiffEqAdaptiveExponentialAlgorithm{AD}, - OrdinaryDiffEqImplicitAlgorithm{AD}, - OrdinaryDiffEqAdaptiveImplicitAlgorithm{AD}, - DAEAlgorithm{AD}, - CompositeAlgorithm{AD}}) where {AD} +function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, + OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}, + OrdinaryDiffEqImplicitAlgorithm{CS, AD}, + OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}, + DAEAlgorithm{CS, AD}, + CompositeAlgorithm{CS, AD}}) where {CS, AD} _get_fwd_chunksize(AD) end function get_chunksize_int(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -function get_chunksize_int(alg::Union{OrdinaryDiffEqExponentialAlgorithm{AD}, - OrdinaryDiffEqAdaptiveExponentialAlgorithm{AD}, - OrdinaryDiffEqImplicitAlgorithm{AD}, - OrdinaryDiffEqAdaptiveImplicitAlgorithm{AD}, - DAEAlgorithm{AD}, - CompositeAlgorithm{AD}}) where {AD} + +function get_chunksize_int(alg::Union{ + OrdinaryDiffEqExponentialAlgorithm{CS}, + OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS}, + OrdinaryDiffEqImplicitAlgorithm{CS, AD}, + OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}, + DAEAlgorithm{CS, AD}, + CompositeAlgorithm{CS, AD}}) where {CS, AD} _get_fwd_chunksize_int(AD) end + # get_chunksize(alg::CompositeAlgorithm) = get_chunksize(alg.algs[alg.current_alg]) function alg_autodiff end @@ -452,6 +457,6 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end -function get_chunksize(alg::AutoForwardDiff{CS}) where {CS} - Val(CS) -end +#function get_chunksize(alg::AutoForwardDiff{CS}) where {CS} +# Val(CS) +#end From c1111bc9ff6e163aacfe4a260db72a3a7f4b1d2b Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 17:12:31 -0500 Subject: [PATCH 041/203] fix bools --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 027be53f95..91ad7daed1 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -134,18 +134,20 @@ isnewton(::Any) = false function _bool_to_ADType(::Val{true}, chunk_size, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize)) + typeof(AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize))) end function _bool_to_ADType(::Val{false}, chunk_size, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - AutoFiniteDiff(fdtype = diff_type) + typeof(AutoFiniteDiff(fdtype = diff_type)) end # Functions to get ADType type from Bool or ADType object, or ADType type -_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(ad_alg, chunksize, diff_type) +_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(Val(ad_alg), chunksize, diff_type) + + +_process_AD_choice(ad_alg::Type{<:AbstractADType}, chunksize, diff_type) = ad_alg -_process_AD_choice(ad_alg::Type{<:AbstractADType}, chunksize, diff_type) = ad_alg _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) = typeof(ad_alg) From 5db75a6cfc57bfe22d60c84d6037e6374fa558a3 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 17:13:02 -0500 Subject: [PATCH 042/203] change prepare_alg --- .../src/alg_utils.jl | 22 +++++++++++++------ .../src/derivative_utils.jl | 1 - .../src/algorithms.jl | 1 - 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index bec21e770a..76def40efd 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -50,11 +50,15 @@ function DiffEqBase.prepare_alg( # If not using autodiff or norecompile mode or very large bitsize (like a dual number u0 already) # don't use a large chunksize as it will either error or not be beneficial - if !(nameof(alg_autodiff(alg)) == :AutoForwardDiff) || - (isbitstype(T) && sizeof(T) > 24) || - (prob.f isa ODEFunction && - prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) - return remake(alg, chunk_size = Val{1}()) + if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if !(isbitstype(T) && sizeof(T) > 24) || + (prob.f isa ODEFunction && + prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) + return remake(alg, autodiff = constructorof(alg_autodiff(alg))(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) + end + return alg + else + return alg end L = StaticArrayInterface.known_length(typeof(u0)) @@ -68,10 +72,14 @@ function DiffEqBase.prepare_alg( end cs = ForwardDiff.pickchunksize(x) - return remake(alg, chunk_size = Val{cs}()) + return remake(alg, + autodiff = constructorof(alg_autodiff(alg))( + chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) else # statically sized cs = pick_static_chunksize(Val{L}()) - return remake(alg, chunk_size = cs) + return remake( + alg, autodiff = constructorof(alg_autodiff(alg))( + chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) end end diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl index 250e1fb02b..21b23c60fa 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl @@ -144,7 +144,6 @@ function calc_J!(J, integrator, cache, next_step::Bool = false) f.jac(J, uprev, p, t) else @unpack du1, uf, jac_config = cache - println(typeof(cache)) uf.f = nlsolve_f(f, alg) uf.t = t if !(p isa DiffEqBase.NullParameters) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index c6211883e8..e0174e4bd3 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -118,7 +118,6 @@ for Alg in [ stage_limiter! = trivial_limiter!) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!), From 7be088ea89e29adbc04e7a47559075e3458c037b Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 5 Nov 2024 17:13:16 -0500 Subject: [PATCH 043/203] import _get_fwd_tag --- .../src/OrdinaryDiffEqDifferentiation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl index c9fcaa68ef..d8c8baf9f6 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl @@ -44,7 +44,7 @@ using OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveImplici FastConvergence, Convergence, SlowConvergence, VerySlowConvergence, Divergence, NLStatus, MethodType, constvalue -import OrdinaryDiffEqCore: get_chunksize, resize_J_W!, resize_nlsolver!, alg_autodiff +import OrdinaryDiffEqCore: get_chunksize, resize_J_W!, resize_nlsolver!, alg_autodiff, _get_fwd_tag using FastBroadcast: @.. From a961a6bf0b35fe625d9805252c9b723748b40ff5 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 09:39:32 -0500 Subject: [PATCH 044/203] dumb typo --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 91ad7daed1..1f4c766494 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -132,12 +132,12 @@ end isnewton(::Any) = false -function _bool_to_ADType(::Val{true}, chunk_size, diff_type) +function _bool_to_ADType(::Val{true}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoForwardDiff(chunk_size = SciMLBase._unwrap_val(chunksize))) + typeof(AutoForwardDiff(chunksize = SciMLBase._unwrap_val(chunksize))) end -function _bool_to_ADType(::Val{false}, chunk_size, diff_type) +function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) typeof(AutoFiniteDiff(fdtype = diff_type)) end From 54abcb53515b9a3da4c436bfaaebfafe7d79d137 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 10:14:22 -0500 Subject: [PATCH 045/203] get the correct fdtype --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 6ffd3b31ab..e83253246d 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -178,6 +178,8 @@ _get_fwd_chunksize(AD) = Val(0) _get_fwd_chunksize_int(AD) = 0 _get_fwd_tag(::Type{AutoForwardDiff{CS,T}}) where {CS,T} = T +_get_fdtype(::Type{AutoFiniteDiff{T1, T2, T3}}) where {T1, T2, T3} = T1 + function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}, @@ -234,6 +236,8 @@ function get_current_alg_autodiff(alg::CompositeAlgorithm, cache) _eval_index(alg_autodiff, alg.algs, cache.current)::Bool end + + function alg_difftype(alg::Union{ OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ }, @@ -243,7 +247,7 @@ function alg_difftype(alg::Union{ CJ}, DAEAlgorithm{CS, AD, FDT, ST, CJ}}) where {CS, AD, FDT, ST, CJ} - typeof(AD.fdtype) + _get_fdtype(AD) end function standardtag(alg::Union{ From 458f6ba45009676a63faadcd042fb8cc060524cd Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 14:47:22 -0500 Subject: [PATCH 046/203] path for just chunksize --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 1f4c766494..28c43b4b76 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -139,15 +139,17 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoFiniteDiff(fdtype = diff_type)) + typeof(AutoFiniteDiff(fdtype = diff_type())) end # Functions to get ADType type from Bool or ADType object, or ADType type _process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(Val(ad_alg), chunksize, diff_type) +function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) + # need a path for if just chunksize is specified in the Algorithm construction + if !(chunksize === Val{0}()) + return _bool_to_ADType(Val{true}(), chunksize, diff_type) + end -_process_AD_choice(ad_alg::Type{<:AbstractADType}, chunksize, diff_type) = ad_alg - - -_process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) = typeof(ad_alg) - + typeof(ad_alg) +end From 02a843f261662dcabdc53ef158e7c70acac4312d Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 14:49:20 -0500 Subject: [PATCH 047/203] need to account for when chunksize is nothing --- .../src/derivative_wrappers.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 61ed338d25..096f8947e0 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -281,12 +281,19 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 sparsity, colorvec = sparsity_colorvec(f, u) if nameof(alg_autodiff(alg)) == :AutoForwardDiff - _chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... + #_chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... + _chunksize = get_chunksize(alg) + println("_chunksize = $_chunksize") T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) else typeof(ForwardDiff.Tag(uf, eltype(u))) end + + if _chunksize === Val{nothing}() + _chunksize = nothing + end + jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff @@ -324,6 +331,8 @@ function resize_jac_config!(jac_config::SparseDiffTools.ForwardColorJacCache, i) resize!(jac_config.fx, i) resize!(jac_config.dx, i) resize!(jac_config.t, i) + println("jac_config = $jac_config") + println(" Val(ForwardDiff.npartials(jac_config.t[1])) = $(Val(ForwardDiff.npartials(jac_config.t[1])))") ps = SparseDiffTools.adapt.(DiffEqBase.parameterless_type(jac_config.dx), SparseDiffTools.generate_chunked_partials(jac_config.dx, 1:length(jac_config.dx), @@ -380,6 +389,8 @@ function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} false) end elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + println(alg) + println(alg_difftype(alg)) grad_config = FiniteDiff.GradientCache(du1, t, alg_difftype(alg)) else error("$alg_autodiff not yet supported in build_grad_config function") From 6d23e178e24ed41aa856ce2c511dc3fcfc6f9ee8 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 15:00:19 -0500 Subject: [PATCH 048/203] no println --- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 096f8947e0..0f1ec61c30 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -283,7 +283,6 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 if nameof(alg_autodiff(alg)) == :AutoForwardDiff #_chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... _chunksize = get_chunksize(alg) - println("_chunksize = $_chunksize") T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) else From 914641a81acf941021e79db96d7e49d7aec77049 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 15:31:55 -0500 Subject: [PATCH 049/203] no prints --- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 0f1ec61c30..ad84637acd 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -330,8 +330,6 @@ function resize_jac_config!(jac_config::SparseDiffTools.ForwardColorJacCache, i) resize!(jac_config.fx, i) resize!(jac_config.dx, i) resize!(jac_config.t, i) - println("jac_config = $jac_config") - println(" Val(ForwardDiff.npartials(jac_config.t[1])) = $(Val(ForwardDiff.npartials(jac_config.t[1])))") ps = SparseDiffTools.adapt.(DiffEqBase.parameterless_type(jac_config.dx), SparseDiffTools.generate_chunked_partials(jac_config.dx, 1:length(jac_config.dx), From 4fe1ac0e3284025bdd8fd515d28ecf8634101cbf Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 15:40:57 -0500 Subject: [PATCH 050/203] stop print --- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index ad84637acd..3eebaa7736 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -386,8 +386,6 @@ function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} false) end elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff - println(alg) - println(alg_difftype(alg)) grad_config = FiniteDiff.GradientCache(du1, t, alg_difftype(alg)) else error("$alg_autodiff not yet supported in build_grad_config function") From ee4bd4cc2fb6978592e695eda7a4a5b4b7cc4ae4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 6 Nov 2024 16:12:35 -0500 Subject: [PATCH 051/203] use constructorof here --- lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl index 21b23c60fa..5f70501692 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl @@ -711,7 +711,7 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits}, _f = islin ? (isode ? f.f : f.f1.f) : f jacvec = JacVec((du, u, p, t) -> _f(du, u, p, t), copy(u), p, t; - autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag()) + autodiff = constructorof(alg_autodiff(alg))(), tag = OrdinaryDiffEqTag()) J = jacvec W = WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec) elseif alg.linsolve !== nothing && !LinearSolve.needs_concrete_A(alg.linsolve) || @@ -734,7 +734,7 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits}, (u, p, t) -> _f(u, p, t) end jacvec = JacVec(__f, copy(u), p, t; - autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag()) + autodiff = constructorof(alg_autodiff(alg))(), tag = OrdinaryDiffEqTag()) WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec) end else From 048c5aaf64e56face657b37a108353c7c494db76 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 11:34:30 -0500 Subject: [PATCH 052/203] fix prepare_alg --- .../src/alg_utils.jl | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 76def40efd..391018191c 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -50,15 +50,21 @@ function DiffEqBase.prepare_alg( # If not using autodiff or norecompile mode or very large bitsize (like a dual number u0 already) # don't use a large chunksize as it will either error or not be beneficial - if nameof(alg_autodiff(alg)) == :AutoForwardDiff - if !(isbitstype(T) && sizeof(T) > 24) || - (prob.f isa ODEFunction && - prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) - return remake(alg, autodiff = constructorof(alg_autodiff(alg))(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) + # If prob.f.f is a FunctionWrappersWrappers from ODEFunction, need to set chunksize to 1 + + if nameof(alg_autodiff(alg)) == :AutoForwardDiff && ((prob.f isa ODEFunction && + prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) || (isbitstype(T) && sizeof(T) > 24)) + return remake(alg, autodiff = constructorof(alg_autodiff(alg))(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) + end + + # If the autodiff alg is AutoFiniteDiff, prob.f.f isa FunctionWrappersWrapper, + # and fdtype is complex, fdtype needs to change to something not complex + if nameof(alg_autodiff(alg)) == :AutoFiniteDiff + if alg_difftype(alg) == Val{:complex} && (prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) + @warn "AutoFiniteDiff fdtype complex is not compatible with this function" + return remake(alg, autodiff = constructorof(alg_autodiff(alg))(fdtype = Val{:forward}())) end return alg - else - return alg end L = StaticArrayInterface.known_length(typeof(u0)) @@ -77,6 +83,7 @@ function DiffEqBase.prepare_alg( chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) else # statically sized cs = pick_static_chunksize(Val{L}()) + cs = SciMLBase._unwrap_val(cs) return remake( alg, autodiff = constructorof(alg_autodiff(alg))( chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) From 5d1a9a10dda3e05825bc930ebd7bf5034b43bfb1 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 11:57:17 -0500 Subject: [PATCH 053/203] change default alg --- lib/OrdinaryDiffEqDefault/src/default_alg.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDefault/src/default_alg.jl b/lib/OrdinaryDiffEqDefault/src/default_alg.jl index 9f0fb62e69..156fdc26f2 100644 --- a/lib/OrdinaryDiffEqDefault/src/default_alg.jl +++ b/lib/OrdinaryDiffEqDefault/src/default_alg.jl @@ -40,10 +40,12 @@ function isdefaultalg(alg::CompositeAlgorithm{ end function DiffEqBase.__init(prob::ODEProblem, ::Nothing, args...; kwargs...) - DiffEqBase.init(prob, DefaultODEAlgorithm(autodiff = false), args...; wrap = Val(false), kwargs...) + DiffEqBase.init( + prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), args...; wrap = Val(false), kwargs...) end function DiffEqBase.__solve(prob::ODEProblem, ::Nothing, args...; kwargs...) - DiffEqBase.solve(prob, DefaultODEAlgorithm(autodiff = false), args...; wrap = Val(false), kwargs...) + DiffEqBase.solve( + prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), args...; wrap = Val(false), kwargs...) end function is_stiff(integrator, alg, ntol, stol, is_stiffalg, current) From 0d6f6854811c01834acbff66e225b22d91e43ca7 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 11:57:31 -0500 Subject: [PATCH 054/203] fix the tests to use ADTypes --- .../test/dae_convergence_tests.jl | 16 ++++---- .../test/dae_initialization_tests.jl | 2 +- .../src/OrdinaryDiffEqDefault.jl | 2 +- .../test/default_solver_tests.jl | 6 +-- .../test/ode_rosenbrock_tests.jl | 29 ++++++++------- .../test/sdirk_convergence_tests.jl | 2 +- test/downstream/delaydiffeq.jl | 2 +- test/integrators/ode_cache_tests.jl | 4 +- test/integrators/resize_tests.jl | 6 +-- test/interface/ad_tests.jl | 2 +- test/interface/autodiff_error_tests.jl | 13 +++---- test/interface/complex_tests.jl | 6 +-- test/interface/composite_algorithm_test.jl | 2 +- test/interface/dae_initialization_tests.jl | 9 +++-- .../interface/differentiation_traits_tests.jl | 6 +-- test/interface/jacobian_tests.jl | 2 +- test/interface/linear_nonlinear_tests.jl | 37 ++++++++++--------- test/interface/nojac.jl | 2 +- test/interface/norecompile.jl | 4 +- test/interface/scalar_handling_tests.jl | 3 +- test/interface/static_array_tests.jl | 26 ++++++------- test/interface/stats_tests.jl | 8 ++-- test/interface/stiffness_detection_test.jl | 6 +-- test/interface/units_tests.jl | 8 ++-- test/regression/iipvsoop_tests.jl | 33 ++++++++++------- 25 files changed, 124 insertions(+), 112 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl b/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl index bd0d5891c4..1366e07840 100644 --- a/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl +++ b/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl @@ -22,13 +22,13 @@ prob_dae_linear_iip = DAEProblem( sim11 = test_convergence(dts, prob, DImplicitEuler()) @test sim11.𝒪est[:final]≈1 atol=testTol - sim12 = test_convergence(dts, prob, DImplicitEuler(; autodiff = false)) + sim12 = test_convergence(dts, prob, DImplicitEuler(; autodiff = AutoFiniteDiff())) @test sim12.𝒪est[:final]≈1 atol=testTol sim13 = test_convergence(dts, prob, DABDF2()) @test sim13.𝒪est[:final]≈2 atol=testTol - sim14 = test_convergence(dts, prob, DABDF2(; autodiff = false)) + sim14 = test_convergence(dts, prob, DABDF2(; autodiff = AutoFiniteDiff())) @test sim14.𝒪est[:final]≈2 atol=testTol @test_nowarn solve(prob, DFBDF()) @@ -46,13 +46,13 @@ prob_dae_linear_iip_jac = DAEProblem( sim11 = test_convergence(dts, prob, DImplicitEuler()) @test sim11.𝒪est[:final]≈1 atol=testTol - sim12 = test_convergence(dts, prob, DImplicitEuler(; autodiff = false)) + sim12 = test_convergence(dts, prob, DImplicitEuler(; autodiff = AutoFiniteDiff())) @test sim12.𝒪est[:final]≈1 atol=testTol sim13 = test_convergence(dts, prob, DABDF2()) @test sim13.𝒪est[:final]≈2 atol=testTol - sim14 = test_convergence(dts, prob, DABDF2(; autodiff = false)) + sim14 = test_convergence(dts, prob, DABDF2(; autodiff = AutoFiniteDiff())) @test sim14.𝒪est[:final]≈2 atol=testTol @test_nowarn solve(prob, DFBDF()) @@ -76,13 +76,13 @@ prob_dae_linear_oop = DAEProblem( sim21 = test_convergence(dts, prob, DImplicitEuler()) @test sim21.𝒪est[:final]≈1 atol=testTol - sim22 = test_convergence(dts, prob, DImplicitEuler(; autodiff = false)) + sim22 = test_convergence(dts, prob, DImplicitEuler(; autodiff = AutoFiniteDiff())) @test sim22.𝒪est[:final]≈1 atol=testTol sim23 = test_convergence(dts, prob, DABDF2()) @test sim23.𝒪est[:final]≈2 atol=testTol - sim24 = test_convergence(dts, prob, DABDF2(; autodiff = false)) + sim24 = test_convergence(dts, prob, DABDF2(; autodiff = AutoFiniteDiff())) @test sim24.𝒪est[:final]≈2 atol=testTol @test_nowarn solve(prob, DFBDF()) @@ -100,13 +100,13 @@ prob_dae_linear_oop = DAEProblem( sim21 = test_convergence(dts, prob, DImplicitEuler()) @test sim21.𝒪est[:final]≈1 atol=testTol - sim22 = test_convergence(dts, prob, DImplicitEuler(; autodiff = false)) + sim22 = test_convergence(dts, prob, DImplicitEuler(; autodiff = AutoFiniteDiff())) @test sim22.𝒪est[:final]≈1 atol=testTol sim23 = test_convergence(dts, prob, DABDF2()) @test sim23.𝒪est[:final]≈2 atol=testTol - sim24 = test_convergence(dts, prob, DABDF2(; autodiff = false)) + sim24 = test_convergence(dts, prob, DABDF2(; autodiff = AutoFiniteDiff())) @test sim24.𝒪est[:final]≈2 atol=testTol @test_nowarn solve(prob, DFBDF()) diff --git a/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl b/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl index cc8d574fd1..d7032a43f6 100644 --- a/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl +++ b/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl @@ -56,7 +56,7 @@ tspan = (0.0, 100000.0) differential_vars = [true, true, false] prob = DAEProblem(f, du₀, u₀, tspan, differential_vars = differential_vars) integrator = init(prob, DABDF2()) -integrator2 = init(prob, DABDF2(autodiff = false)) +integrator2 = init(prob, DABDF2(autodiff = AutoFiniteDiff())) @test integrator.du[1]≈-0.04 atol=1e-9 @test integrator.du[2]≈0.04 atol=1e-9 diff --git a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl index 182b3c70c1..d642aee60a 100644 --- a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl +++ b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl @@ -29,7 +29,7 @@ PrecompileTools.@compile_workload begin prob_list = [] default_ode = [ - DefaultODEAlgorithm(autodiff = false) + DefaultODEAlgorithm(autodiff = AutoFiniteDiff()) ] default_autodiff_ode = [ diff --git a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl index c62ff80880..c28421df19 100644 --- a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl +++ b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl @@ -39,7 +39,7 @@ function rober(u, p, t) end prob_rober = ODEProblem(rober, [1.0, 0.0, 0.0], (0.0, 1e3), (0.04, 3e7, 1e4)) sol = solve(prob_rober) -rosensol = solve(prob_rober, AutoTsit5(Rosenbrock23(autodiff = false))) +rosensol = solve(prob_rober, AutoTsit5(Rosenbrock23(autodiff = AutoFiniteDiff()))) #test that cache is type stable @test typeof(sol.interp.cache.cache3) == typeof(rosensol.interp.cache.caches[2]) # test that default has the same performance as AutoTsit5(Rosenbrock23()) (which we expect it to use for this). @@ -51,7 +51,7 @@ rosensol = solve(prob_rober, AutoTsit5(Rosenbrock23(autodiff = false))) sol = solve(prob_rober, reltol = 1e-7, abstol = 1e-7) rosensol = solve( - prob_rober, AutoVern7(Rodas5P(autodiff = false)), reltol = 1e-7, abstol = 1e-7) + prob_rober, AutoVern7(Rodas5P(autodiff = AutoFiniteDiff())), reltol = 1e-7, abstol = 1e-7) #test that cache is type stable @test typeof(sol.interp.cache.cache4) == typeof(rosensol.interp.cache.caches[2]) # test that default has the same performance as AutoTsit5(Rosenbrock23()) (which we expect it to use for this). @@ -79,7 +79,7 @@ for n in (100, 600) prob_ex_rober = ODEProblem(ODEFunction(exrober; jac_prototype), vcat([1.0, 0.0, 0.0], ones(n)), (0.0, 100.0), (0.04, 3e7, 1e4)) global sol = solve(prob_ex_rober) - fsol = solve(prob_ex_rober, AutoTsit5(FBDF(; autodiff = false, linsolve))) + fsol = solve(prob_ex_rober, AutoTsit5(FBDF(; autodiff = AutoFiniteDiff(), linsolve))) # test that default has the same performance as AutoTsit5(Rosenbrock23()) (which we expect it to use for this). @test sol.stats.naccept == fsol.stats.naccept @test sol.stats.nf == fsol.stats.nf diff --git a/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl index d384937120..47d3975f63 100644 --- a/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl +++ b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl @@ -510,11 +510,12 @@ import LinearSolve sol = solve(prob, Rodas4()) @test length(sol) < 20 - sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) + sim = test_convergence( + dts, prob, Rodas4(autodiff = AutoFiniteDiff()), dense_errors = true) @test sim.𝒪est[:final]≈4 atol=testTol @test sim.𝒪est[:L2]≈4 atol=testTol - sol = solve(prob, Rodas4(autodiff = false)) + sol = solve(prob, Rodas4(autodiff = AutoFiniteDiff())) @test length(sol) < 20 sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) @@ -549,29 +550,30 @@ import LinearSolve println("Rodas4 with finite diff") - sim = test_convergence(dts, prob, Rodas4(autodiff = false), dense_errors = true) + sim = test_convergence( + dts, prob, Rodas4(autodiff = AutoFiniteDiff()), dense_errors = true) @test sim.𝒪est[:final]≈4 atol=testTol @test sim.𝒪est[:L2]≈4 atol=testTol - sol = solve(prob, Rodas4(autodiff = false)) + sol = solve(prob, Rodas4(autodiff = AutoFiniteDiff())) @test length(sol) < 20 - sim = test_convergence(dts, prob, Rodas4(autodiff = false, - diff_type = Val{:forward}), + sim = test_convergence( + dts, prob, Rodas4(autodiff = AutoFiniteDiff(fdtype = Val(:forward))), dense_errors = true) @test sim.𝒪est[:final]≈4 atol=testTol @test sim.𝒪est[:L2]≈4 atol=testTol - sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:forward})) + sol = solve(prob, Rodas4(autodiff = AutoFiniteDiff(fdtype = Val(:forward)))) @test length(sol) < 20 - sim = test_convergence(dts, prob, Rodas4(autodiff = false, - diff_type = Val{:complex}), + sim = test_convergence( + dts, prob, Rodas4(autodiff = AutoFiniteDiff(fdtype = Val(:complex))), dense_errors = true) @test sim.𝒪est[:final]≈4 atol=testTol @test sim.𝒪est[:L2]≈4 atol=testTol - sol = solve(prob, Rodas4(autodiff = false, diff_type = Val{:complex})) + sol = solve(prob, Rodas4(autodiff = AutoFiniteDiff(fdtype = Val(:forward)))) @test length(sol) < 20 sim = test_convergence(dts, prob, Rodas42(), dense_errors = true) @@ -597,11 +599,12 @@ import LinearSolve println("Rodas4P2 with finite diff") - sim = test_convergence(dts, prob, Rodas4P2(autodiff = false), dense_errors = true) + sim = test_convergence( + dts, prob, Rodas4P2(autodiff = AutoFiniteDiff()), dense_errors = true) @test sim.𝒪est[:final]≈4 atol=testTol @test sim.𝒪est[:L2]≈4 atol=testTol - sol = solve(prob, Rodas4P2(autodiff = false)) + sol = solve(prob, Rodas4P2(autodiff = AutoFiniteDiff())) @test length(sol) < 20 ### Rodas5 @@ -687,7 +690,7 @@ import LinearSolve @test length(sol) < 20 prob = ODEProblem((u, p, t) -> 0.9u, 0.1, (0.0, 1.0)) - @test_nowarn solve(prob, Rosenbrock23(autodiff = false)) + @test_nowarn solve(prob, Rosenbrock23(autodiff = AutoFiniteDiff())) end @testset "Convergence with time-dependent matrix-free Jacobian" begin diff --git a/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl b/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl index 4e9cd86216..5f7ee42212 100644 --- a/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl +++ b/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl @@ -56,7 +56,7 @@ testTol = 0.2 sim14 = test_convergence(dts, prob, TRBDF2()) @test sim14.𝒪est[:final]≈2 atol=testTol - sim152 = test_convergence(dts, prob, TRBDF2(autodiff = false)) + sim152 = test_convergence(dts, prob, TRBDF2(autodiff = AutoFiniteDiff())) @test sim152.𝒪est[:final]≈2 atol=testTol + 0.1 sim15 = test_convergence(dts, prob, SDIRK2()) diff --git a/test/downstream/delaydiffeq.jl b/test/downstream/delaydiffeq.jl index b68f8144c4..65fe2d6aa8 100644 --- a/test/downstream/delaydiffeq.jl +++ b/test/downstream/delaydiffeq.jl @@ -43,4 +43,4 @@ h(p, t) = [1.0, 1.0] h(p, t; idxs = 1) = 1.0 p = [1.5, 1.0, 3.0, 1.0, 1.0] prob = DDEProblem(lotka_volterra!, uₒ, h, tspan, p, constant_lags = (p[end],)) -sol = solve(prob, MethodOfSteps(AutoTsit5(Rosenbrock23(autodiff = false)))) +sol = solve(prob, MethodOfSteps(AutoTsit5(Rosenbrock23(autodiff = AutoFiniteDiff())))) diff --git a/test/integrators/ode_cache_tests.jl b/test/integrators/ode_cache_tests.jl index 8e766a319b..c6ae85aaee 100644 --- a/test/integrators/ode_cache_tests.jl +++ b/test/integrators/ode_cache_tests.jl @@ -79,9 +79,9 @@ for alg in broken_CACHE_TEST_ALGS @test_broken length(solve(prob, alg, callback = callback, dt = 1 / 2)[end]) > 1 end -sol = solve(prob, Rodas4(chunk_size = 1), callback = callback, dt = 1 / 2) +sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 1)), callback = callback, dt = 1 / 2) @test length(sol[end]) > 1 -sol = solve(prob, Rodas5(chunk_size = 1), callback = callback, dt = 1 / 2) +sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 1)), callback = callback, dt = 1 / 2) @test length(sol[end]) > 1 # cache tests resizing multidimensional arrays diff --git a/test/integrators/resize_tests.jl b/test/integrators/resize_tests.jl index fb5dc583de..5961b8a20c 100644 --- a/test/integrators/resize_tests.jl +++ b/test/integrators/resize_tests.jl @@ -38,7 +38,7 @@ resize!(i, 5) @test length(i.cache.nlsolver.cache.weight) == 5 solve!(i) -i = init(prob, ImplicitEuler(; autodiff = false)) +i = init(prob, ImplicitEuler(; autodiff = AutoFiniteDiff())) resize!(i, 5) @test length(i.cache.atmp) == 5 @test length(i.cache.uprev) == 5 @@ -83,7 +83,7 @@ resize!(i, 5) @test length(i.cache.jac_config.p) == 5 solve!(i) -i = init(prob, Rosenbrock23(; autodiff = false)) +i = init(prob, Rosenbrock23(; autodiff = AutoFiniteDiff())) resize!(i, 5) @test length(i.cache.u) == 5 @test length(i.cache.uprev) == 5 @@ -185,7 +185,7 @@ end runSim(BS3()) runSim(Rosenbrock23()) -runSim(Rosenbrock23(autodiff = false)) +runSim(Rosenbrock23(autodiff = AutoFiniteDiff())) # https://github.com/SciML/OrdinaryDiffEq.jl/issues/1990 @testset "resize! with SplitODEProblem" begin diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index 1a85c97ad8..7072b66da9 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -205,7 +205,7 @@ of_a = p -> begin prob = ODEProblem(f_a, u0, tspan, p) # sol = solve(prob, Tsit5()) # works # sol = solve(prob, Rodas5(autodiff=false)) # works - sol = solve(prob, Rodas5(autodiff = true), abstol = 1e-14, reltol = 1e-14) # fails + sol = solve(prob, Rodas5(autodiff = AutoForwardDiff()), abstol = 1e-14, reltol = 1e-14) # fails return sum(t -> abs2(t[1]), sol([1.0, 2.0, 3.0])) end diff --git a/test/interface/autodiff_error_tests.jl b/test/interface/autodiff_error_tests.jl index 195c7bdab4..7672077e87 100644 --- a/test/interface/autodiff_error_tests.jl +++ b/test/interface/autodiff_error_tests.jl @@ -50,13 +50,12 @@ prob = ODEProblem(lorenz2!, u0, tspan) ## https://discourse.julialang.org/t/rodas4-using-dual-number-for-time-with-autodiff-false/98256 for alg in [ - Rosenbrock23(autodiff = false), - Rodas4(autodiff = false), - Rodas5(autodiff = false), - QNDF(autodiff = false), - TRBDF2(autodiff = false), - KenCarp4(autodiff = false), - FBDF(autodiff = false) + Rosenbrock23(autodiff = AutoFiniteDiff()), + Rodas4(autodiff = AutoFiniteDiff()), + Rodas5(autodiff = AutoFiniteDiff()), + QNDF(autodiff = AutoFiniteDiff()), + TRBDF2(autodiff = AutoFiniteDiff()), + KenCarp4(autodiff = AutoFiniteDiff()), ] u = [0.0, 0.0] function f1(u, p, t) diff --git a/test/interface/complex_tests.jl b/test/interface/complex_tests.jl index bf3a154d29..5555146072 100644 --- a/test/interface/complex_tests.jl +++ b/test/interface/complex_tests.jl @@ -45,20 +45,20 @@ end @testset "Complex Tests on Implicit Finite Diff Methods. alg=$alg" for alg in implicit ψ0 = [1.0 + 0.0im; 0.0] prob = ODEProblem(fun_inplace, ψ0, (-T, T)) - sol = solve(prob, alg(autodiff = false)) + sol = solve(prob, alg(autodiff = AutoFiniteDiff())) @test norm(sol(T))≈1 atol=1e-2 end @testset "Complex Tests on Implicit Finite Diff Out-of-place Methods. alg=$alg" for alg in implicit ψ0 = [1.0 + 0.0im; 0.0] prob = ODEProblem(fun, ψ0, (-T, T)) - sol = solve(prob, alg(autodiff = false)) + sol = solve(prob, alg(autodiff = AutoFiniteDiff())) @test norm(sol(T))≈1 atol=1e-2 end @testset "Complex Tests on Implicit Finite Diff Out-of-place Methods SArray. alg=$alg" for alg in implicit ψ0 = @SArray [1.0 + 0.0im; 0.0] prob = ODEProblem(fun, ψ0, (-T, T)) - sol = solve(prob, alg(autodiff = false)) + sol = solve(prob, alg(autodiff = AutoFiniteDiff())) @test norm(sol(T))≈1 atol=1e-2 end diff --git a/test/interface/composite_algorithm_test.jl b/test/interface/composite_algorithm_test.jl index 01bedd5953..d0b498dbbe 100644 --- a/test/interface/composite_algorithm_test.jl +++ b/test/interface/composite_algorithm_test.jl @@ -78,7 +78,7 @@ sol = solve(prob, @test sol.t[end] == 1000.0 prob = remake(prob_ode_2Dlinear, u0 = rand(ComplexF64, 2, 2)) -sol = solve(prob, AutoTsit5(Rosenbrock23(autodiff = false))) # Complex and AD don't mix +sol = solve(prob, AutoTsit5(Rosenbrock23(autodiff = AutoFiniteDiff()))) # Complex and AD don't mix @test sol.retcode == ReturnCode.Success # https://github.com/SciML/ModelingToolkit.jl/issues/3043 diff --git a/test/interface/dae_initialization_tests.jl b/test/interface/dae_initialization_tests.jl index e00d8270e5..648fbcf15b 100644 --- a/test/interface/dae_initialization_tests.jl +++ b/test/interface/dae_initialization_tests.jl @@ -15,7 +15,8 @@ M = [1.0 0 0 0 0 0] f_oop = ODEFunction(rober_oop, mass_matrix = M) prob_mm = ODEProblem(f_oop, [1.0, 0.0, 0.0], (0.0, 1e5), (0.04, 3e7, 1e4)) -sol = solve(prob_mm, Rosenbrock23(autodiff = false), reltol = 1e-8, abstol = 1e-8) +sol = solve( + prob_mm, Rosenbrock23(autodiff = AutoFiniteDiff()), reltol = 1e-8, abstol = 1e-8) @test sol[1] == [1.0, 0.0, 0.0] # Ensure initialization is unchanged if it works at the start! sol = solve(prob_mm, Rosenbrock23(), reltol = 1e-8, abstol = 1e-8, initializealg = ShampineCollocationInit()) @@ -25,7 +26,7 @@ prob_mm = ODEProblem(f_oop, [1.0, 0.0, 0.2], (0.0, 1e5), (0.04, 3e7, 1e4)) sol = solve(prob_mm, Rosenbrock23(), reltol = 1e-8, abstol = 1e-8) @test sum(sol[1]) ≈ 1 @test sol[1] ≈ [1.0, 0.0, 0.0] -for alg in [Rosenbrock23(autodiff = false), Trapezoid()] +for alg in [Rosenbrock23(autodiff = AutoFiniteDiff()), Trapezoid()] local sol sol = solve(prob_mm, alg, reltol = 1e-8, abstol = 1e-8, initializealg = ShampineCollocationInit()) @@ -45,7 +46,7 @@ M = [1.0 0 0 0 0 0] f = ODEFunction(rober, mass_matrix = M) prob_mm = ODEProblem(f, [1.0, 0.0, 0.0], (0.0, 1e5), (0.04, 3e7, 1e4)) -sol = solve(prob_mm, Rodas5(autodiff = false), reltol = 1e-8, abstol = 1e-8) +sol = solve(prob_mm, Rodas5(autodiff = AutoFiniteDiff()), reltol = 1e-8, abstol = 1e-8) @test sol[1] == [1.0, 0.0, 0.0] # Ensure initialization is unchanged if it works at the start! sol = solve(prob_mm, Rodas5(), reltol = 1e-8, abstol = 1e-8, initializealg = ShampineCollocationInit()) @@ -56,7 +57,7 @@ sol = solve(prob_mm, Rodas5(), reltol = 1e-8, abstol = 1e-8) @test sum(sol[1]) ≈ 1 @test sol[1] ≈ [1.0, 0.0, 0.0] -for alg in [Rodas5(autodiff = false), Trapezoid()] +for alg in [Rodas5(autodiff = AutoFiniteDiff()), Trapezoid()] local sol sol = solve(prob_mm, alg, reltol = 1e-8, abstol = 1e-8, initializealg = ShampineCollocationInit()) diff --git a/test/interface/differentiation_traits_tests.jl b/test/interface/differentiation_traits_tests.jl index d2c3c51d38..bde01186cd 100644 --- a/test/interface/differentiation_traits_tests.jl +++ b/test/interface/differentiation_traits_tests.jl @@ -35,11 +35,11 @@ good_sol = solve(prob, Rosenbrock23()) prob2 = ODEProblem(Lotka, ones(2), (0.0, 10.0)) -sol = solve(prob2, Rosenbrock23(autodiff = true)) +sol = solve(prob2, Rosenbrock23(autodiff = AutoForwardDiff())) @test ≈(good_sol[:, end], sol[:, end], rtol = 1e-2) -sol = solve(prob2, Rosenbrock23(autodiff = true, chunk_size = 1)) +sol = solve(prob2, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 1))) @test ≈(good_sol[:, end], sol[:, end], rtol = 1e-2) -sol = solve(prob2, Rosenbrock23(autodiff = false)) +sol = solve(prob2, Rosenbrock23(autodiff = AutoFiniteDiff())) @test ≈(good_sol[:, end], sol[:, end], rtol = 1e-2) diff --git a/test/interface/jacobian_tests.jl b/test/interface/jacobian_tests.jl index d23d29d642..698b116ee9 100644 --- a/test/interface/jacobian_tests.jl +++ b/test/interface/jacobian_tests.jl @@ -86,7 +86,7 @@ function rober(du, u, p, t) nothing end prob1 = ODEProblem(rober, [1.0, 0.0, 0.0], (0.0, 1e5), (0.04, 3e7, 1e4, true)) -sol1 = solve(prob1, TRBDF2(chunk_size = chunksize)) +sol1 = solve(prob1, TRBDF2(autodiff = AutoForwardDiff(chunksize = chunksize))) prob = ODEProblem(rober, [1.0, 0.0, 0.0], (0.0, 1e5), (0.04, 3e7, 1e4, false)) sol = solve(prob, TRBDF2()) @test sol.u[end] == sol1.u[end] diff --git a/test/interface/linear_nonlinear_tests.jl b/test/interface/linear_nonlinear_tests.jl index b948996346..6a0ce27742 100644 --- a/test/interface/linear_nonlinear_tests.jl +++ b/test/interface/linear_nonlinear_tests.jl @@ -35,70 +35,71 @@ function precslr(W, du, u, p, t, newW, Plprev, Prprev, solverdata) Pr, Pr end -sol = @test_nowarn solve(prob, TRBDF2(autodiff = false)); +sol = @test_nowarn solve(prob, TRBDF2(autodiff = AutoFiniteDiff())); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES())); + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES())); @test length(sol.t) < 20 solref = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), smooth_est = false)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precsl, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precsr, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - QNDF(autodiff = false, linsolve = KrylovJL_GMRES(), + QNDF(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), concrete_jac = true)); @test length(sol.t) < 25 sol = @test_nowarn solve(prob, - Rosenbrock23(autodiff = false, + Rosenbrock23(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - Rodas4(autodiff = false, linsolve = KrylovJL_GMRES(), + Rodas4(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, concrete_jac = true)); @test length(sol.t) < 20 -sol = @test_nowarn solve(prob, TRBDF2(autodiff = false)); +sol = @test_nowarn solve(prob, TRBDF2(autodiff = AutoFiniteDiff())); @test length(sol.t) < 20 -sol = @test_nowarn solve(prob, TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES())); +sol = @test_nowarn solve( + prob, TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES())); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), smooth_est = false)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precsl, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precsr, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - TRBDF2(autodiff = false, linsolve = KrylovJL_GMRES(), + TRBDF2(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, smooth_est = false, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - QNDF(autodiff = false, linsolve = KrylovJL_GMRES(), + QNDF(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), concrete_jac = true)); @test length(sol.t) < 25 sol = @test_nowarn solve(prob, - Rosenbrock23(autodiff = false, linsolve = KrylovJL_GMRES(), + Rosenbrock23(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, concrete_jac = true)); @test length(sol.t) < 20 sol = @test_nowarn solve(prob, - Rodas4(autodiff = false, linsolve = KrylovJL_GMRES(), + Rodas4(autodiff = AutoFiniteDiff(), linsolve = KrylovJL_GMRES(), precs = precslr, concrete_jac = true)); @test length(sol.t) < 20 diff --git a/test/interface/nojac.jl b/test/interface/nojac.jl index 9a252ddfea..be9071a4ae 100644 --- a/test/interface/nojac.jl +++ b/test/interface/nojac.jl @@ -253,6 +253,6 @@ integ = init(prob, Rosenbrock23(linsolve = SimpleLUFactorization()), abstol = 1e integ = init(prob, Rosenbrock23(linsolve = GenericLUFactorization()), abstol = 1e-6, reltol = 1e-6) @test integ.cache.jac_config === nothing -integ = init(prob, Rosenbrock23(linsolve = RFLUFactorization(), chunk_size = Val{3}()), +integ = init(prob, Rosenbrock23(linsolve = RFLUFactorization(), autodiff = AutoForwardDiff(chunksize = 3)), abstol = 1e-6, reltol = 1e-6) @test integ.cache.jac_config === nothing diff --git a/test/interface/norecompile.jl b/test/interface/norecompile.jl index 4eee7b9e6e..7b28ae4ce3 100644 --- a/test/interface/norecompile.jl +++ b/test/interface/norecompile.jl @@ -15,13 +15,13 @@ end lorenzprob = ODEProblem(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[]) t1 = @elapsed sol1 = solve(lorenzprob, Rosenbrock23()) -t2 = @elapsed sol2 = solve(lorenzprob, Rosenbrock23(autodiff = false)) +t2 = @elapsed sol2 = solve(lorenzprob, Rosenbrock23(autodiff = AutoFiniteDiff())) lorenzprob2 = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[]) t3 = @elapsed sol3 = solve(lorenzprob2, Rosenbrock23()) -t4 = @elapsed sol4 = solve(lorenzprob2, Rosenbrock23(autodiff = false)) +t4 = @elapsed sol4 = solve(lorenzprob2, Rosenbrock23(autodiff = AutoFiniteDiff())) @test sol1.retcode === ReturnCode.Success @test sol2.retcode === ReturnCode.Success diff --git a/test/interface/scalar_handling_tests.jl b/test/interface/scalar_handling_tests.jl index f7103a5d9a..1ad2d08556 100644 --- a/test/interface/scalar_handling_tests.jl +++ b/test/interface/scalar_handling_tests.jl @@ -1,4 +1,5 @@ using OrdinaryDiffEq # https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/390 -solve(ODEProblem((x, p, t) -> -x, 1.0, (0.0, 50.0)), Rosenbrock23(autodiff = false)) +solve(ODEProblem((x, p, t) -> -x, 1.0, (0.0, 50.0)), + Rosenbrock23(autodiff = AutoFiniteDiff())) diff --git a/test/interface/static_array_tests.jl b/test/interface/static_array_tests.jl index 5849de74bd..9773be6354 100644 --- a/test/interface/static_array_tests.jl +++ b/test/interface/static_array_tests.jl @@ -58,7 +58,7 @@ end u0 = @SVector [1.0, 0.0, 0.0] tspan = (0.0, 100.0) prob = ODEProblem(lorenz_static, u0, tspan) -solve(prob, dt = 0.1, Rosenbrock23(autodiff = false)) +solve(prob, dt = 0.1, Rosenbrock23(autodiff = AutoFiniteDiff())) # Check that ArrayPartitions of static vectors work #https://github.com/SciML/OrdinaryDiffEq.jl/issues/1308 @@ -94,8 +94,8 @@ function rober(u, p, t) end prob = ODEProblem{false}(rober, SA[1.0, 0.0, 0.0], (0.0, 1e5), SA[0.04, 3e7, 1e4]) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(chunk_size = Val{3}()), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas4(chunk_size = Val{3}()), save_everystep = false) +@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) +@test_nowarn sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) function hires_4(u, p, t) y1, y2, y3, y4 = u @@ -109,8 +109,8 @@ end u0 = SA[1, 0, 0, 0.0057] prob = ODEProblem(hires_4, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(chunk_size = Val{4}()), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(chunk_size = Val{4}()), save_everystep = false) +@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) +@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) function hires_5(u, p, t) y1, y2, y3, y4, y5 = u @@ -125,8 +125,8 @@ end u0 = SA[1, 0, 0, 0, 0.0057] prob = ODEProblem(hires_5, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(chunk_size = Val{5}()), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas4(chunk_size = Val{5}()), save_everystep = false) +@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) +@test_nowarn sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) function hires(u, p, t) y1, y2, y3, y4, y5, y6, y7, y8 = u @@ -145,8 +145,8 @@ end u0 = SA[1, 0, 0, 0, 0, 0, 0, 0.0057] prob = ODEProblem(hires, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(chunk_size = Val{8}()), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(chunk_size = Val{8}()), save_everystep = false) +@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) const k1 = 0.35e0 const k2 = 0.266e2 @@ -235,8 +235,8 @@ u0[9] = 0.01 u0[17] = 0.007 u0 = SA[u0...] prob = ODEProblem(pollu, u0, (0.0, 60.0)) -@test_nowarn sol = solve(prob, Rosenbrock23(chunk_size = Val{8}()), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(chunk_size = Val{8}()), save_everystep = false) +@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) # DFBDF g1(du, u, p, t) = du .^ 2 - conj.(u) @@ -261,11 +261,11 @@ du0 = SA[-0.5051593302918506 - 0.87178524227302im, -0.5011616766671037 + 0.8651123244481334im, -0.5065728050401669 + 0.8738635859036186im] prob = DAEProblem(g1, du0, u0, (0.0, 10.0)) -sol1 = solve(prob, DFBDF(autodiff = false), reltol = 1e-8, abstol = 1e-8) +sol1 = solve(prob, DFBDF(autodiff = AutoFiniteDiff()), reltol = 1e-8, abstol = 1e-8) g2(resid, du, u, p, t) = resid .= du .^ 2 - conj.(u) prob = DAEProblem(g2, Array(du0), Array(u0), (0.0, 10.0)) -sol2 = solve(prob, DFBDF(autodiff = false), reltol = 1e-8, abstol = 1e-8) +sol2 = solve(prob, DFBDF(autodiff = AutoFiniteDiff()), reltol = 1e-8, abstol = 1e-8) @test all(iszero, sol1[:, 1] - sol2[:, 1]) @test all(abs.(sol1[:, end] .- sol2[:, end]) .< 1.5e-6) diff --git a/test/interface/stats_tests.jl b/test/interface/stats_tests.jl index 13f06cb127..69f7716127 100644 --- a/test/interface/stats_tests.jl +++ b/test/interface/stats_tests.jl @@ -23,10 +23,10 @@ probip = ODEProblem(g, u0, tspan) @test x[] == sol.stats.nf end @testset "$alg" for alg in [Rodas5P, KenCarp4] - @testset "$kwargs" for kwargs in [(autodiff = true,), - (autodiff = false, diff_type = Val{:forward}), - (autodiff = false, diff_type = Val{:central}), - (autodiff = false, diff_type = Val{:complex}),] + @testset "$kwargs" for kwargs in [(autodiff = AutoForwardDiff(),), + (autodiff = AutoFiniteDiff(fdtype = Val{:forward})), + (autodiff = AutoFiniteDiff(fdtype = Val{:central})), + (autodiff = AutoFiniteDiff(fdtype = Val{:complex}))] x[] = 0 sol = solve(prob, alg(;kwargs...)) @test x[] == sol.stats.nf diff --git a/test/interface/stiffness_detection_test.jl b/test/interface/stiffness_detection_test.jl index 4ae725c460..fe03eecc55 100644 --- a/test/interface/stiffness_detection_test.jl +++ b/test/interface/stiffness_detection_test.jl @@ -20,14 +20,14 @@ probArr = [prob1, prob2, prob3] for prob in [prob2, prob3], u0 in [prob.u0, Dual.(prob.u0, prob.u0)] prob′ = remake(prob3, u0 = u0) - @test_nowarn solve(prob′, AutoTsit5(Rosenbrock23(autodiff = false))) + @test_nowarn solve(prob′, AutoTsit5(Rosenbrock23(autodiff = AutoFiniteDiff()))) end # Test if switching back and forth is_switching_fb(sol) = all(i -> count(isequal(i), sol.alg_choice[2:end]) > 5, (1, 2)) for (i, prob) in enumerate(probArr) println(i) - sol = @test_nowarn solve(prob, AutoTsit5(Rosenbrock23(autodiff = false)), + sol = @test_nowarn solve(prob, AutoTsit5(Rosenbrock23(autodiff = AutoFiniteDiff())), maxiters = 1000) @test is_switching_fb(sol) alg = AutoTsit5(Rodas5(); maxstiffstep = 5, maxnonstiffstep = 5, stiffalgfirst = true) @@ -61,7 +61,7 @@ for (i, prob) in enumerate(probArr) @test length(sol.t) < 570 @test is_switching_fb(sol) sol = solve(prob, - AutoVern9(KenCarp3(autodiff = false); maxstiffstep = 4, + AutoVern9(KenCarp3(autodiff = AutoFiniteDiff()); maxstiffstep = 4, maxnonstiffstep = 1), maxiters = 1000) @test length(sol.t) < 570 @test is_switching_fb(sol) diff --git a/test/interface/units_tests.jl b/test/interface/units_tests.jl index 280116dba2..7d0f717b5e 100644 --- a/test/interface/units_tests.jl +++ b/test/interface/units_tests.jl @@ -55,10 +55,10 @@ end sol = solve(prob, alg) end - for alg in [AutoVern6(Rodas5(autodiff = false)), - AutoVern7(Rodas5(autodiff = false)), - AutoVern8(Rodas5(autodiff = false)), - AutoVern9(Rodas5(autodiff = false))] + for alg in [AutoVern6(Rodas5(autodiff = AutoFiniteDiff())), + AutoVern7(Rodas5(autodiff = AutoFiniteDiff())), + AutoVern8(Rodas5(autodiff = AutoFiniteDiff())), + AutoVern9(Rodas5(autodiff = AutoFiniteDiff()))] @show alg @test_broken sol = solve(prob, alg) end diff --git a/test/regression/iipvsoop_tests.jl b/test/regression/iipvsoop_tests.jl index e3f2756410..0d00727eed 100644 --- a/test/regression/iipvsoop_tests.jl +++ b/test/regression/iipvsoop_tests.jl @@ -10,28 +10,35 @@ sol = solve(prob, Tsit5()) # Make sure various differentiation forms work on scalars sol1 = solve(prob, Rosenbrock23(), abstol = 1e-12, reltol = 1e-12) -sol2 = solve(prob, Rosenbrock23(autodiff = false), abstol = 1e-12, reltol = 1e-12) -sol3 = solve(prob, Rosenbrock23(autodiff = false, diff_type = Val{:central}), +sol2 = solve( + prob, Rosenbrock23(autodiff = AutoFiniteDiff()), abstol = 1e-12, reltol = 1e-12) +sol3 = solve(prob, Rosenbrock23(autodiff = AutoFiniteDiff(fdtype = Val(:central))), abstol = 1e-12, reltol = 1e-12) -sol4 = solve(prob, Rosenbrock23(autodiff = false, diff_type = Val{:complex}), +sol4 = solve(prob, Rosenbrock23(autodiff = AutoFiniteDiff(fdtype = Val(:complex))), abstol = 1e-12, reltol = 1e-12) sol5 = solve(prob, KenCarp4(), abstol = 1e-12, reltol = 1e-12) -sol6 = solve(prob, KenCarp4(autodiff = false), abstol = 1e-12, reltol = 1e-12) -sol7 = solve(prob, KenCarp4(autodiff = false, diff_type = Val{:central}), abstol = 1e-12, +sol6 = solve(prob, KenCarp4(autodiff = AutoFiniteDiff()), abstol = 1e-12, reltol = 1e-12) +sol7 = solve( + prob, KenCarp4(autodiff = AutoFiniteDiff(fdtype = Val(:central))), abstol = 1e-12, reltol = 1e-12) -sol8 = solve(prob, KenCarp4(autodiff = false, diff_type = Val{:complex}), abstol = 1e-12, +sol8 = solve( + prob, KenCarp4(autodiff = AutoFiniteDiff(fdtype = Val(:complex))), abstol = 1e-12, reltol = 1e-12) sol9 = solve(prob, KenCarp47(), abstol = 1e-12, reltol = 1e-12) -sol10 = solve(prob, KenCarp47(autodiff = false), abstol = 1e-12, reltol = 1e-12) -sol11 = solve(prob, KenCarp47(autodiff = false, diff_type = Val{:central}), abstol = 1e-12, +sol10 = solve(prob, KenCarp47(autodiff = AutoFiniteDiff()), abstol = 1e-12, reltol = 1e-12) +sol11 = solve( + prob, KenCarp47(autodiff = AutoFiniteDiff(fdtype = Val(:central))), abstol = 1e-12, reltol = 1e-12) -sol12 = solve(prob, KenCarp47(autodiff = false, diff_type = Val{:complex}), abstol = 1e-12, +sol12 = solve( + prob, KenCarp47(autodiff = AutoFiniteDiff(fdtype = Val(:complex))), abstol = 1e-12, reltol = 1e-12) sol13 = solve(prob, KenCarp58(), abstol = 1e-12, reltol = 1e-12) -sol14 = solve(prob, KenCarp58(autodiff = false), abstol = 1e-12, reltol = 1e-12) -sol15 = solve(prob, KenCarp58(autodiff = false, diff_type = Val{:central}), abstol = 1e-12, +sol14 = solve(prob, KenCarp58(autodiff = AutoFiniteDiff()), abstol = 1e-12, reltol = 1e-12) +sol15 = solve( + prob, KenCarp58(autodiff = AutoFiniteDiff(fdtype = Val(:central))), abstol = 1e-12, reltol = 1e-12) -sol16 = solve(prob, KenCarp58(autodiff = false, diff_type = Val{:complex}), abstol = 1e-12, +sol16 = solve( + prob, KenCarp58(autodiff = AutoFiniteDiff(fdtype = Val(:complex))), abstol = 1e-12, reltol = 1e-12) ts = 0.0:0.1:1.0 @@ -87,7 +94,7 @@ end working_sdirk_algs = [ImplicitMidpoint(), ImplicitEuler(), - ImplicitMidpoint(autodiff = false), + ImplicitMidpoint(autodiff = AutoFiniteDiff()), SSPSDIRK2()] sdirk_algs = [Trapezoid(), From 6694e08d879ef7e5f3e72cebe79409f4b09c3be3 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 12:31:13 -0500 Subject: [PATCH 055/203] make sure ADTypes is usable in Defaults --- lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl | 2 +- lib/OrdinaryDiffEqDefault/Project.toml | 1 + lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl index 584dea5e04..6821fc464b 100644 --- a/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl +++ b/lib/OrdinaryDiffEqBDF/src/OrdinaryDiffEqBDF.jl @@ -34,7 +34,7 @@ using OrdinaryDiffEqNonlinearSolve: NLNewton, du_alias_or_new, build_nlsolver, nlsolve!, nlsolvefail, isnewton, markfirststage!, set_new_W!, DIRK, compute_step!, COEFFICIENT_MULTISTEP import ADTypes -import ADTypes: AutoForwardDiff, AbstractADType +import ADTypes: AutoForwardDiff, AutoFiniteDiff, AbstractADType using Reexport @reexport using DiffEqBase diff --git a/lib/OrdinaryDiffEqDefault/Project.toml b/lib/OrdinaryDiffEqDefault/Project.toml index 6962deaa5f..77522b46e6 100644 --- a/lib/OrdinaryDiffEqDefault/Project.toml +++ b/lib/OrdinaryDiffEqDefault/Project.toml @@ -4,6 +4,7 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl index d642aee60a..a5ecee57c5 100644 --- a/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl +++ b/lib/OrdinaryDiffEqDefault/src/OrdinaryDiffEqDefault.jl @@ -11,6 +11,7 @@ using OrdinaryDiffEqBDF: FBDF import OrdinaryDiffEqCore import OrdinaryDiffEqCore: is_mass_matrix_alg, default_autoswitch, isdefaultalg +import ADTypes: AutoFiniteDiff, AutoForwardDiff, AbstractADType import LinearSolve using LinearAlgebra: I, isdiag using EnumX From 94ed7cb8daa0e2b676be1ee2ea1fa607100620ca Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 12:35:34 -0500 Subject: [PATCH 056/203] make sure tests use ADTypes --- lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl | 2 +- lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl | 2 +- test/integrators/ode_cache_tests.jl | 2 +- test/integrators/resize_tests.jl | 2 +- test/interface/ad_tests.jl | 2 +- test/interface/autodiff_error_tests.jl | 2 +- test/interface/complex_tests.jl | 2 +- test/interface/composite_algorithm_test.jl | 2 +- test/interface/dae_initialization_tests.jl | 2 +- test/interface/differentiation_traits_tests.jl | 2 +- test/interface/jacobian_tests.jl | 2 +- test/interface/linear_nonlinear_tests.jl | 2 +- test/interface/nojac.jl | 2 +- test/interface/norecompile.jl | 2 +- test/interface/scalar_handling_tests.jl | 2 +- test/interface/static_array_tests.jl | 2 +- test/interface/stats_tests.jl | 2 +- test/interface/stiffness_detection_test.jl | 2 +- test/interface/units_tests.jl | 2 +- test/regression/iipvsoop_tests.jl | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl b/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl index 1366e07840..1829c679a0 100644 --- a/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl +++ b/lib/OrdinaryDiffEqBDF/test/dae_convergence_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEqBDF, DiffEqDevTools +using OrdinaryDiffEqBDF, DiffEqDevTools, ADTypes using Test, Random Random.seed!(100) diff --git a/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl b/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl index d7032a43f6..154f499c07 100644 --- a/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl +++ b/lib/OrdinaryDiffEqBDF/test/dae_initialization_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEqBDF, StaticArrays, LinearAlgebra, Test +using OrdinaryDiffEqBDF, StaticArrays, LinearAlgebra, Test, ADTypes using OrdinaryDiffEqNonlinearSolve f = function (du, u, p, t) diff --git a/test/integrators/ode_cache_tests.jl b/test/integrators/ode_cache_tests.jl index c6ae85aaee..4337e41bb6 100644 --- a/test/integrators/ode_cache_tests.jl +++ b/test/integrators/ode_cache_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, OrdinaryDiffEqCore, DiffEqBase, Test +using OrdinaryDiffEq, OrdinaryDiffEqCore, DiffEqBase, Test, ADTypes using Random, SparseDiffTools using OrdinaryDiffEqDefault using ElasticArrays, LinearSolve diff --git a/test/integrators/resize_tests.jl b/test/integrators/resize_tests.jl index 5961b8a20c..1b2933d1a9 100644 --- a/test/integrators/resize_tests.jl +++ b/test/integrators/resize_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes f(du, u, p, t) = du .= u prob = ODEProblem(f, [1.0], (0.0, 1.0)) diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index 7072b66da9..e5bde66e85 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -1,5 +1,5 @@ using Test -using OrdinaryDiffEq, Calculus, ForwardDiff, FiniteDiff, LinearAlgebra +using OrdinaryDiffEq, Calculus, ForwardDiff, FiniteDiff, LinearAlgebra, ADTypes function f(du, u, p, t) du[1] = -p[1] diff --git a/test/interface/autodiff_error_tests.jl b/test/interface/autodiff_error_tests.jl index 7672077e87..7b37ab87f6 100644 --- a/test/interface/autodiff_error_tests.jl +++ b/test/interface/autodiff_error_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes using OrdinaryDiffEqDifferentiation const a = Float64[1.0] diff --git a/test/interface/complex_tests.jl b/test/interface/complex_tests.jl index 5555146072..9d9092d71d 100644 --- a/test/interface/complex_tests.jl +++ b/test/interface/complex_tests.jl @@ -2,7 +2,7 @@ using Test using StaticArrays, LinearAlgebra -using OrdinaryDiffEq, DiffEqBase +using OrdinaryDiffEq, DiffEqBase, ADTypes H(t) = -im * (@SMatrix [t 1; 1 -t]) diff --git a/test/interface/composite_algorithm_test.jl b/test/interface/composite_algorithm_test.jl index d0b498dbbe..1e3ebe8574 100644 --- a/test/interface/composite_algorithm_test.jl +++ b/test/interface/composite_algorithm_test.jl @@ -1,6 +1,6 @@ using OrdinaryDiffEq, OrdinaryDiffEqCore, Test, LinearAlgebra import ODEProblemLibrary: prob_ode_linear, prob_ode_2Dlinear -using DiffEqDevTools +using DiffEqDevTools, ADTypes prob = prob_ode_2Dlinear choice_function(integrator) = (Int(integrator.t < 0.5) + 1) diff --git a/test/interface/dae_initialization_tests.jl b/test/interface/dae_initialization_tests.jl index 648fbcf15b..3657f461f3 100644 --- a/test/interface/dae_initialization_tests.jl +++ b/test/interface/dae_initialization_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, StaticArrays, LinearAlgebra, Test +using OrdinaryDiffEq, StaticArrays, LinearAlgebra, Test, ADTypes ## Mass Matrix diff --git a/test/interface/differentiation_traits_tests.jl b/test/interface/differentiation_traits_tests.jl index bde01186cd..75742eb88e 100644 --- a/test/interface/differentiation_traits_tests.jl +++ b/test/interface/differentiation_traits_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes jac_called = Ref(false) tgrad_called = Ref(false) diff --git a/test/interface/jacobian_tests.jl b/test/interface/jacobian_tests.jl index 698b116ee9..3b3bb0c248 100644 --- a/test/interface/jacobian_tests.jl +++ b/test/interface/jacobian_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, ForwardDiff, Test +using OrdinaryDiffEq, ForwardDiff, Test, ADTypes function d_alembert(du, u, p, t) du[1] = p[1] - p[2] * u[1] + p[3] * t diff --git a/test/interface/linear_nonlinear_tests.jl b/test/interface/linear_nonlinear_tests.jl index 6a0ce27742..6930d59b4c 100644 --- a/test/interface/linear_nonlinear_tests.jl +++ b/test/interface/linear_nonlinear_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test, Random, LinearAlgebra, LinearSolve +using OrdinaryDiffEq, Test, Random, LinearAlgebra, LinearSolve, ADTypes Random.seed!(123) A = 0.01 * rand(3, 3) diff --git a/test/interface/nojac.jl b/test/interface/nojac.jl index be9071a4ae..46230434de 100644 --- a/test/interface/nojac.jl +++ b/test/interface/nojac.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, LinearSolve, Test +using OrdinaryDiffEq, LinearSolve, Test, ADTypes const N = 32 const xyd_brusselator = range(0, stop = 1, length = N) diff --git a/test/interface/norecompile.jl b/test/interface/norecompile.jl index 7b28ae4ce3..989031de95 100644 --- a/test/interface/norecompile.jl +++ b/test/interface/norecompile.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes function f(du, u, p, t) du[1] = 0.2u[1] du[2] = 0.4u[2] diff --git a/test/interface/scalar_handling_tests.jl b/test/interface/scalar_handling_tests.jl index 1ad2d08556..c9d20773a0 100644 --- a/test/interface/scalar_handling_tests.jl +++ b/test/interface/scalar_handling_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq +using OrdinaryDiffEq, ADTypes # https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/390 solve(ODEProblem((x, p, t) -> -x, 1.0, (0.0, 50.0)), diff --git a/test/interface/static_array_tests.jl b/test/interface/static_array_tests.jl index 9773be6354..44d85fe05f 100644 --- a/test/interface/static_array_tests.jl +++ b/test/interface/static_array_tests.jl @@ -1,6 +1,6 @@ using StaticArrays, Test using OrdinaryDiffEq, OrdinaryDiffEqCore, OrdinaryDiffEqNonlinearSolve -using RecursiveArrayTools +using RecursiveArrayTools, ADTypes u0 = VectorOfArray([fill(2, MVector{2, Float64}), ones(MVector{2, Float64})]) g0(u, p, t) = SA[u[1] + u[2], u[1]] diff --git a/test/interface/stats_tests.jl b/test/interface/stats_tests.jl index 69f7716127..7da3902e10 100644 --- a/test/interface/stats_tests.jl +++ b/test/interface/stats_tests.jl @@ -1,5 +1,5 @@ # stats.nf tests -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes x = Ref(0) function f(u, p, t) x[] += 1 diff --git a/test/interface/stiffness_detection_test.jl b/test/interface/stiffness_detection_test.jl index fe03eecc55..503f0bb7a9 100644 --- a/test/interface/stiffness_detection_test.jl +++ b/test/interface/stiffness_detection_test.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEq, Test +using OrdinaryDiffEq, Test, ADTypes import ODEProblemLibrary: van using ForwardDiff: Dual diff --git a/test/interface/units_tests.jl b/test/interface/units_tests.jl index 7d0f717b5e..cad23ebc91 100644 --- a/test/interface/units_tests.jl +++ b/test/interface/units_tests.jl @@ -1,5 +1,5 @@ using OrdinaryDiffEq, RecursiveArrayTools, Unitful -using LinearAlgebra, Test +using LinearAlgebra, Test, ADTypes @testset "Algorithms" begin algs = [ diff --git a/test/regression/iipvsoop_tests.jl b/test/regression/iipvsoop_tests.jl index 0d00727eed..b316f5bb31 100644 --- a/test/regression/iipvsoop_tests.jl +++ b/test/regression/iipvsoop_tests.jl @@ -1,5 +1,5 @@ using OrdinaryDiffEq, Test -using OrdinaryDiffEqCore +using OrdinaryDiffEqCore, ADTypes f(u, p, t) = 0.98u u0 = 1.0 From bc0ab6f6e4b631fbbe0be55588354f8fc55e5571 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 13:07:26 -0500 Subject: [PATCH 057/203] fix stats_test --- test/interface/stats_tests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/interface/stats_tests.jl b/test/interface/stats_tests.jl index 7da3902e10..a35607a536 100644 --- a/test/interface/stats_tests.jl +++ b/test/interface/stats_tests.jl @@ -24,9 +24,9 @@ probip = ODEProblem(g, u0, tspan) end @testset "$alg" for alg in [Rodas5P, KenCarp4] @testset "$kwargs" for kwargs in [(autodiff = AutoForwardDiff(),), - (autodiff = AutoFiniteDiff(fdtype = Val{:forward})), - (autodiff = AutoFiniteDiff(fdtype = Val{:central})), - (autodiff = AutoFiniteDiff(fdtype = Val{:complex}))] + (autodiff = AutoFiniteDiff(fdtype = Val{:forward}()),), + (autodiff = AutoFiniteDiff(fdtype = Val{:central}()),), + (autodiff = AutoFiniteDiff(fdtype = Val{:complex}()),)] x[] = 0 sol = solve(prob, alg(;kwargs...)) @test x[] == sol.stats.nf From afc70626759f4d9ab9ba85e1856e394b2a78287c Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 13:20:58 -0500 Subject: [PATCH 058/203] fix sparsediff_tests --- test/interface/sparsediff_tests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/interface/sparsediff_tests.jl b/test/interface/sparsediff_tests.jl index 63983ade09..10304b5b57 100644 --- a/test/interface/sparsediff_tests.jl +++ b/test/interface/sparsediff_tests.jl @@ -2,6 +2,7 @@ using Test using OrdinaryDiffEq using SparseArrays using LinearAlgebra +using ADTypes ## in-place #https://github.com/JuliaDiffEq/SparseDiffTools.jl/blob/master/test/test_integration.jl @@ -51,7 +52,7 @@ for f in [f_oop, f_ip] odefun_std = ODEFunction(f) prob_std = ODEProblem(odefun_std, u0, tspan) - for ad in [true, false] + for ad in [AutoForwardDiff(), AutoFiniteDiff()] for Solver in [Rodas5, Rosenbrock23, Trapezoid, KenCarp4] for tol in [nothing, 1e-10] sol_std = solve(prob_std, Solver(autodiff = ad), reltol = tol, abstol = tol) From a360016d821f2eff26e06a9b2ea187871407c771 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 14:39:55 -0500 Subject: [PATCH 059/203] fix DAE initialization --- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 +- lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 593f27ee77..57e685d8fd 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -26,7 +26,7 @@ import SciMLStructures: canonicalize, Tunable, isscimlstructure import OrdinaryDiffEqCore import SciMLOperators: islinear -import OrdinaryDiffEqCore: nlsolve_f, set_new_W!, set_W_γdt! +import OrdinaryDiffEqCore: nlsolve_f, set_new_W!, set_W_γdt!, _ADType_to_Bool @static if isdefined(OrdinaryDiffEqCore, :default_nlsolve) import OrdinaryDiffEqCore: default_nlsolve diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl index 75fdf9f177..23d3fa47fb 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl @@ -573,7 +573,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, if alg.nlsolve !== nothing nlsolve = alg.nlsolve else - nlsolve = NewtonRaphson(autodiff = alg_autodiff(integrator.alg)) + nlsolve = NewtonRaphson(autodiff = _ADType_to_Bool(alg_autodiff(integrator.alg))) end nlfunc = NonlinearFunction(nlequation!; jac_prototype = f.jac_prototype) From fb734e626bd02247e97041119f977a928eea4bdf Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 14:40:13 -0500 Subject: [PATCH 060/203] add deprecated AD kwargs testset --- test/interface/ad_tests.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index e5bde66e85..28ab9907af 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -318,3 +318,28 @@ function f(x) end K_ = [-1.0 0.0; 1.0 -1.0] @test isapprox(ForwardDiff.jacobian(f, K_)[2], 0.00226999, atol = 1e-6) + + +@testset "deprecated AD keyword arguments still work" for (alg, rtol) in SOLVERS_FOR_AD + f = (du, u, p, t) -> du .= -0.5 * u + alg1 = alg(autodiff = AutoForwardDiff()) + alg2 = alg(autodiff = true) + + alg3 = alg(autodiff = AutoFiniteDiff()) + alg4 = alg(autodiff = false) + + alg5 = alg(autodiff = AutoForwardDiff(chunksize = 5)) + alg6 = alg(autodiff = true, chunk_size = 5) + + alg7 = alg(autodiff = AutoFiniteDiff(fdtype = Val(:central))) + alg8 = alg(autodiff = false, diff_type = Val(:central)) + + alg9 = alg(autodiff = AutoForwardDiff(chunksize = 1)) + alg10 = alg(chunk_size = 1) + + @test alg1 == alg2 + @test alg3 == alg4 + @test alg5 == alg6 + @test alg7 == alg8 + @test alg9 == alg10 +end \ No newline at end of file From 1dd781d168bc34c97d2753455b9c90cb7b916db4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 14:48:51 -0500 Subject: [PATCH 061/203] no call for diff_type --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 28c43b4b76..3c89378b80 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -139,7 +139,7 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoFiniteDiff(fdtype = diff_type())) + typeof(AutoFiniteDiff(fdtype = diff_type)) end # Functions to get ADType type from Bool or ADType object, or ADType type From 3160e89fa23fcfd82f481c693595b72b7cf94198 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 14:49:05 -0500 Subject: [PATCH 062/203] add _ADType_to_Bool utility function --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 3c89378b80..8afd86e1ef 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -139,7 +139,7 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoFiniteDiff(fdtype = diff_type)) + typeof(AutoFiniteDiff(fdtype = diff_type())) end # Functions to get ADType type from Bool or ADType object, or ADType type @@ -153,3 +153,8 @@ function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) typeof(ad_alg) end + + +_ADType_to_Bool(::Type{AutoForwardDiff}) = true + +_ADType_to_Bool(::Type{AutoFiniteDiff}) = false \ No newline at end of file From 44397d7020ad8f0efffd26d6b372177e9e5409bd Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 14:58:41 -0500 Subject: [PATCH 063/203] make 0 nothing, no callable diff_type --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 8afd86e1ef..3b4f6af3a9 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -134,12 +134,13 @@ isnewton(::Any) = false function _bool_to_ADType(::Val{true}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoForwardDiff(chunksize = SciMLBase._unwrap_val(chunksize))) + chunksize = SciMLBase._unwrap_val(chunksize) == 0 ? nothing : SciMLBase._unwrap_val(chunksize) + typeof(AutoForwardDiff(chunksize = chunksize)) end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoFiniteDiff(fdtype = diff_type())) + typeof(AutoFiniteDiff(fdtype = diff_type)) end # Functions to get ADType type from Bool or ADType object, or ADType type From f809d43f092a423e5387ae75ca32d67064f5ee20 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 15:41:17 -0500 Subject: [PATCH 064/203] check for types in bool to ADType --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 3b4f6af3a9..b45776b7cd 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -140,7 +140,11 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - typeof(AutoFiniteDiff(fdtype = diff_type)) + if diff_type isa Type + return typeof(AutoFiniteDiff(fdtype = diff_type())) + else + return typeof(AutoFiniteDiff(fdtype = diff_type)) + end end # Functions to get ADType type from Bool or ADType object, or ADType type From 77ac54ab79e3751c61676eea2d63fdd3d42ded2c Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 16:55:58 -0500 Subject: [PATCH 065/203] fix the AD tests --- test/interface/ad_tests.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index 28ab9907af..aa4734945f 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -320,7 +320,12 @@ K_ = [-1.0 0.0; 1.0 -1.0] @test isapprox(ForwardDiff.jacobian(f, K_)[2], 0.00226999, atol = 1e-6) -@testset "deprecated AD keyword arguments still work" for (alg, rtol) in SOLVERS_FOR_AD +implicit_algs = +[FBDF, + Rosenbrock23, + TRBDF2] + +@testset "deprecated AD keyword arguments still work" for alg in implicit_algs f = (du, u, p, t) -> du .= -0.5 * u alg1 = alg(autodiff = AutoForwardDiff()) alg2 = alg(autodiff = true) @@ -337,9 +342,9 @@ K_ = [-1.0 0.0; 1.0 -1.0] alg9 = alg(autodiff = AutoForwardDiff(chunksize = 1)) alg10 = alg(chunk_size = 1) - @test alg1 == alg2 - @test alg3 == alg4 - @test alg5 == alg6 - @test alg7 == alg8 - @test alg9 == alg10 + @test OrdinaryDiffEq.alg_autodiff(alg1) == OrdinaryDiffEq.alg_autodiff(alg2) + @test OrdinaryDiffEq.alg_autodiff(alg3) == OrdinaryDiffEq.alg_autodiff(alg4) + @test OrdinaryDiffEq.alg_autodiff(alg5) == OrdinaryDiffEq.alg_autodiff(alg6) + @test OrdinaryDiffEq.alg_autodiff(alg7) == OrdinaryDiffEq.alg_autodiff(alg8) + @test OrdinaryDiffEq.alg_autodiff(alg9) == OrdinaryDiffEq.alg_autodiff(alg10) end \ No newline at end of file From c09909be497cb3fd74c6aaeac47bad8c2db40a09 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 16:56:55 -0500 Subject: [PATCH 066/203] test set name --- test/interface/ad_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index aa4734945f..26f98f1aa4 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -325,7 +325,7 @@ implicit_algs = Rosenbrock23, TRBDF2] -@testset "deprecated AD keyword arguments still work" for alg in implicit_algs +@testset "deprecated AD keyword arguments still work with $alg" for alg in implicit_algs f = (du, u, p, t) -> du .= -0.5 * u alg1 = alg(autodiff = AutoForwardDiff()) alg2 = alg(autodiff = true) From edb4bf03caed75658b9188005d1522bbea383b14 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 18:39:51 -0500 Subject: [PATCH 067/203] fix ADType to bool conversion --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index b45776b7cd..c5b580be5f 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -160,6 +160,6 @@ function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) end -_ADType_to_Bool(::Type{AutoForwardDiff}) = true +_ADType_to_Bool(::Type{T}) where {T <: AutoForwardDiff} = true -_ADType_to_Bool(::Type{AutoFiniteDiff}) = false \ No newline at end of file +_ADType_to_Bool(::Type{T}) where {T <: AutoFiniteDiff} = false \ No newline at end of file From c957db9ab7e9697c85fa1dfb62be48511aa684ce Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 7 Nov 2024 19:40:22 -0500 Subject: [PATCH 068/203] use constructor for NLSolve autodiff --- lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl index 23d3fa47fb..6a2b0b985b 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl @@ -573,7 +573,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, if alg.nlsolve !== nothing nlsolve = alg.nlsolve else - nlsolve = NewtonRaphson(autodiff = _ADType_to_Bool(alg_autodiff(integrator.alg))) + nlsolve = NewtonRaphson(autodiff = constructorof(alg_autodiff(integrator.alg))()) end nlfunc = NonlinearFunction(nlequation!; jac_prototype = f.jac_prototype) From a60dadec92e6a084ca41444c938ae20466ba66e5 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 8 Nov 2024 10:06:52 -0500 Subject: [PATCH 069/203] fix DAE initialization --- lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl index 6a2b0b985b..d49f71c64e 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl @@ -573,7 +573,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, if alg.nlsolve !== nothing nlsolve = alg.nlsolve else - nlsolve = NewtonRaphson(autodiff = constructorof(alg_autodiff(integrator.alg))()) + nlsolve = NewtonRaphson(autodiff = SciMLBase.constructorof(alg_autodiff(integrator.alg))()) end nlfunc = NonlinearFunction(nlequation!; jac_prototype = f.jac_prototype) From c38825983432b72a884b24f4fc31032c5261f25b Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 8 Nov 2024 10:07:06 -0500 Subject: [PATCH 070/203] add ADTypes to test --- test/downstream/delaydiffeq.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/downstream/delaydiffeq.jl b/test/downstream/delaydiffeq.jl index 65fe2d6aa8..f3d2e3ac53 100644 --- a/test/downstream/delaydiffeq.jl +++ b/test/downstream/delaydiffeq.jl @@ -1,4 +1,4 @@ -using DelayDiffEq, DDEProblemLibrary +using DelayDiffEq, DDEProblemLibrary, ADTypes using Test @testset "Constant delays" begin From e6670d55b6807daf9c84888e2fe1177666dd7010 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 8 Nov 2024 10:07:30 -0500 Subject: [PATCH 071/203] more using ADTypes --- lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl | 2 +- lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl | 2 +- lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl index c28421df19..751ca5c4ec 100644 --- a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl +++ b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl @@ -1,5 +1,5 @@ using OrdinaryDiffEqDefault, OrdinaryDiffEqTsit5, OrdinaryDiffEqVerner, - OrdinaryDiffEqRosenbrock, OrdinaryDiffEqBDF + OrdinaryDiffEqRosenbrock, OrdinaryDiffEqBDF, ADTypes using Test, LinearSolve, LinearAlgebra, SparseArrays, StaticArrays f_2dlinear = (du, u, p, t) -> (@. du = p * u) diff --git a/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl index 47d3975f63..7b95c25071 100644 --- a/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl +++ b/lib/OrdinaryDiffEqRosenbrock/test/ode_rosenbrock_tests.jl @@ -1,4 +1,4 @@ -using OrdinaryDiffEqRosenbrock, DiffEqDevTools, Test, LinearAlgebra, LinearSolve +using OrdinaryDiffEqRosenbrock, DiffEqDevTools, Test, LinearAlgebra, LinearSolve, ADTypes import ODEProblemLibrary: prob_ode_linear, prob_ode_2Dlinear, prob_ode_bigfloatlinear, prob_ode_bigfloat2Dlinear diff --git a/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl b/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl index 5f7ee42212..884e8bc7f3 100644 --- a/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl +++ b/lib/OrdinaryDiffEqSDIRK/test/sdirk_convergence_tests.jl @@ -1,5 +1,5 @@ # This definitely needs cleaning -using OrdinaryDiffEqSDIRK, ODEProblemLibrary, DiffEqDevTools +using OrdinaryDiffEqSDIRK, ODEProblemLibrary, DiffEqDevTools, ADTypes using Test, Random Random.seed!(100) From 7124802f0d0ca60d98768782a86f0330e527fa52 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 8 Nov 2024 12:58:32 -0500 Subject: [PATCH 072/203] update deps --- lib/OrdinaryDiffEqBDF/Project.toml | 4 ++-- lib/OrdinaryDiffEqDefault/Project.toml | 4 ++-- lib/OrdinaryDiffEqExponentialRK/Project.toml | 6 +++--- lib/OrdinaryDiffEqExtrapolation/Project.toml | 6 +++--- lib/OrdinaryDiffEqFIRK/Project.toml | 4 ++-- lib/OrdinaryDiffEqIMEXMultistep/Project.toml | 6 +++--- lib/OrdinaryDiffEqPDIRK/Project.toml | 6 +++--- lib/OrdinaryDiffEqRosenbrock/Project.toml | 4 ++-- lib/OrdinaryDiffEqSDIRK/Project.toml | 6 +++--- lib/OrdinaryDiffEqStabilizedIRK/Project.toml | 6 +++--- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/Project.toml b/lib/OrdinaryDiffEqBDF/Project.toml index d0752ea049..78bd532385 100644 --- a/lib/OrdinaryDiffEqBDF/Project.toml +++ b/lib/OrdinaryDiffEqBDF/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqBDF" uuid = "6ad6398a-0878-4a85-9266-38940aa047c8" authors = ["ParamThakkar123 "] -version = "1.1.2" +version = "1.2" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -32,7 +32,7 @@ LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5.13" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.1" +OrdinaryDiffEqCore = "1.11" OrdinaryDiffEqDifferentiation = "<0.0.1, 1" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" OrdinaryDiffEqSDIRK = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqDefault/Project.toml b/lib/OrdinaryDiffEqDefault/Project.toml index 77522b46e6..32759422cb 100644 --- a/lib/OrdinaryDiffEqDefault/Project.toml +++ b/lib/OrdinaryDiffEqDefault/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqDefault" uuid = "50262376-6c5a-4cf5-baba-aaf4f84d72d7" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -25,7 +25,7 @@ EnumX = "1.0.4" LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" OrdinaryDiffEqBDF = "<0.0.1, 1" -OrdinaryDiffEqCore = "1.1" +OrdinaryDiffEqCore = "1.11" OrdinaryDiffEqRosenbrock = "<0.0.1, 1" OrdinaryDiffEqTsit5 = "<0.0.1, 1" OrdinaryDiffEqVerner = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqExponentialRK/Project.toml b/lib/OrdinaryDiffEqExponentialRK/Project.toml index 99079c409b..34763c0607 100644 --- a/lib/OrdinaryDiffEqExponentialRK/Project.toml +++ b/lib/OrdinaryDiffEqExponentialRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqExponentialRK" uuid = "e0540318-69ee-4070-8777-9e2de6de23de" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -26,8 +26,8 @@ FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqSDIRK = "<0.0.1, 1" OrdinaryDiffEqTsit5 = "<0.0.1, 1" OrdinaryDiffEqVerner = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqExtrapolation/Project.toml b/lib/OrdinaryDiffEqExtrapolation/Project.toml index 917b72b001..f8d5829c70 100644 --- a/lib/OrdinaryDiffEqExtrapolation/Project.toml +++ b/lib/OrdinaryDiffEqExtrapolation/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqExtrapolation" uuid = "becaefa8-8ca2-5cf9-886d-c06f3d2bd2c4" authors = ["Chris Rackauckas ", "Yingbo Ma "] -version = "1.2.1" +version = "1.3.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -23,8 +23,8 @@ FastBroadcast = "0.3.5" FastPower = "1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" Polyester = "0.7.16" Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" diff --git a/lib/OrdinaryDiffEqFIRK/Project.toml b/lib/OrdinaryDiffEqFIRK/Project.toml index 24d6114f04..72ba71b59b 100644 --- a/lib/OrdinaryDiffEqFIRK/Project.toml +++ b/lib/OrdinaryDiffEqFIRK/Project.toml @@ -30,8 +30,8 @@ LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" diff --git a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml index 88e0ed4746..a207a3e0e2 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml +++ b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqIMEXMultistep" uuid = "9f002381-b378-40b7-97a6-27a27c83f129" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -16,8 +16,8 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" Reexport = "1.2.2" diff --git a/lib/OrdinaryDiffEqPDIRK/Project.toml b/lib/OrdinaryDiffEqPDIRK/Project.toml index ae8ce4bf5d..1357830781 100644 --- a/lib/OrdinaryDiffEqPDIRK/Project.toml +++ b/lib/OrdinaryDiffEqPDIRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqPDIRK" uuid = "5dd0a6cf-3d4b-4314-aa06-06d4e299bc89" authors = ["ParamThakkar123 "] -version = "1.1.1" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -20,8 +20,8 @@ DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Polyester = "0.7.16" Random = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index 2769329879..3ffa130076 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -34,8 +34,8 @@ LinearSolve = "2.32.0" MacroTools = "0.5.13" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" Polyester = "0.7.16" PrecompileTools = "1.2.1" Preferences = "1.4.3" diff --git a/lib/OrdinaryDiffEqSDIRK/Project.toml b/lib/OrdinaryDiffEqSDIRK/Project.toml index 6318365f79..3800d52a50 100644 --- a/lib/OrdinaryDiffEqSDIRK/Project.toml +++ b/lib/OrdinaryDiffEqSDIRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqSDIRK" uuid = "2d112036-d095-4a1e-ab9a-08536f3ecdbf" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -25,8 +25,8 @@ FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5.13" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" diff --git a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml index 8c2fab15cf..c3916cc528 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml +++ b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqStabilizedIRK" uuid = "e3e12d00-db14-5390-b879-ac3dd2ef6296" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -21,8 +21,8 @@ DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.1" -OrdinaryDiffEqDifferentiation = "<0.0.1, 1" +OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" From bcb75191c27eaff5e06ba337de59ffd4922ba66d Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 15:46:10 -0500 Subject: [PATCH 073/203] allow for Values in derivative wrapper for Algs not updated yet --- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 3eebaa7736..f6629c10c8 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -81,7 +81,7 @@ function derivative!(df::AbstractArray{<:Number}, f, alg = unwrap_alg(integrator, true) tmp = length(x) # We calculate derivative for all elements in gradient autodiff_alg = alg_autodiff(alg) - if nameof(autodiff_alg) == :AutoForwardDiff + if nameof(autodiff_alg) == :AutoForwardDiff || autodiff_alg == Val{true} T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(df))) else @@ -103,7 +103,7 @@ function derivative!(df::AbstractArray{<:Number}, f, df .= first.(ForwardDiff.partials.(grad_config)) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - elseif nameof(autodiff_alg) == :AutoFiniteDiff + elseif nameof(autodiff_alg) == :AutoFiniteDiff || autodiff_alg == Val{false} FiniteDiff.finite_difference_gradient!(df, f, x, grad_config, dir = diffdir(integrator)) fdtype = alg_difftype(alg) From 67c470dc0bea4bb4c5982936ce781c2e31c5ae26 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:19:11 -0500 Subject: [PATCH 074/203] change back to alg_autodiff gives constructed ADType, for compat --- .../src/alg_utils.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 391018191c..dd2ad501b6 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -18,13 +18,26 @@ end # autodiff = _alg_autodiff(alg) # if autodiff == Val(false) # return AutoFiniteDiff() -# elseif autodiff == Val(true) +# elseif autodiff == Val(true) # return AutoForwardDiff() # else # return _unwrap_val(autodiff) # end #end +function alg_autodiff(alg) + autodiff = _alg_autodiff(alg) + if nameof(autodiff) == :AutoForwardDiff + return AutoForwardDiff() + elseif nameof(autodiff) == :AutoFiniteDiff + return AutoFiniteDiff() + elseif autodiff == Val{true} + return AutoForwardDiff() + elseif autodiff == Val{false} + return AutoFiniteDiff() + end +end + alg_autodiff(alg) = _alg_autodiff(alg) Base.@pure function determine_chunksize(u, alg::DiffEqBase.DEAlgorithm) From 62918b2fa353f28d848060edcc7f685ee0b0b52b Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:27:18 -0500 Subject: [PATCH 075/203] fix util --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index e83253246d..3684bbd753 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -12,7 +12,7 @@ end function SciMLBase.forwarddiffs_model(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorithm, DAEAlgorithm, OrdinaryDiffEqImplicitAlgorithm, ExponentialAlgorithm}) - nameof(alg_autodiff(alg)) == :AutoForwardDiff + alg_autodiff(alg) isa AutoForwardDiff end SciMLBase.forwarddiffs_model_time(alg::RosenbrockAlgorithm) = true @@ -176,9 +176,9 @@ _get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) _get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS _get_fwd_chunksize(AD) = Val(0) _get_fwd_chunksize_int(AD) = 0 -_get_fwd_tag(::Type{AutoForwardDiff{CS,T}}) where {CS,T} = T +_get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T -_get_fdtype(::Type{AutoFiniteDiff{T1, T2, T3}}) where {T1, T2, T3} = T1 +_get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, From a70c0d1e66f268af6c3f00a3e51b3dca8b1060cf Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:28:02 -0500 Subject: [PATCH 076/203] fix derivative wrappers --- .../src/derivative_wrappers.jl | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index f6629c10c8..c7f4a1df34 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -81,7 +81,7 @@ function derivative!(df::AbstractArray{<:Number}, f, alg = unwrap_alg(integrator, true) tmp = length(x) # We calculate derivative for all elements in gradient autodiff_alg = alg_autodiff(alg) - if nameof(autodiff_alg) == :AutoForwardDiff || autodiff_alg == Val{true} + if autodiff_alg isa AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(df))) else @@ -103,7 +103,7 @@ function derivative!(df::AbstractArray{<:Number}, f, df .= first.(ForwardDiff.partials.(grad_config)) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - elseif nameof(autodiff_alg) == :AutoFiniteDiff || autodiff_alg == Val{false} + elseif autodiff_alg isa AutoFiniteDiff FiniteDiff.finite_difference_gradient!(df, f, x, grad_config, dir = diffdir(integrator)) fdtype = alg_difftype(alg) @@ -125,7 +125,7 @@ function derivative(f, x::Union{Number, AbstractArray{<:Number}}, local d tmp = length(x) # We calculate derivative for all elements in gradient alg = unwrap_alg(integrator, true) - if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) if integrator.iter == 1 try @@ -136,7 +136,7 @@ function derivative(f, x::Union{Number, AbstractArray{<:Number}}, else d = ForwardDiff.derivative(f, x) end - elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + elseif alg_autodiff(alg) isa AutoFiniteDiff d = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(alg), dir = diffdir(integrator)) if alg_difftype(alg) === Val{:central} || alg_difftype(alg) === Val{:forward} @@ -192,7 +192,7 @@ end function jacobian(f, x, integrator) alg = unwrap_alg(integrator, true) local tmp - if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff if integrator.iter == 1 try J, tmp = jacobian_autodiff(f, x, integrator.f, alg) @@ -202,7 +202,7 @@ function jacobian(f, x, integrator) else J, tmp = jacobian_autodiff(f, x, integrator.f, alg) end - elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + elseif alg_autodiff(alg) isa AutoFiniteDiff jac_prototype = integrator.f.jac_prototype sparsity, colorvec = sparsity_colorvec(integrator.f, x) dir = diffdir(integrator) @@ -230,7 +230,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number}, fx::AbstractArray{<:Number}, integrator::DiffEqBase.DEIntegrator, jac_config) alg = unwrap_alg(integrator, true) - if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff if integrator.iter == 1 try forwarddiff_color_jacobian!(J, f, x, jac_config) @@ -241,7 +241,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number}, forwarddiff_color_jacobian!(J, f, x, jac_config) end OrdinaryDiffEqCore.increment_nf!(integrator.stats, maximum(jac_config.colorvec)) - elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + elseif alg_autodiff(alg) isa AutoFiniteDiff isforward = alg_difftype(alg) === Val{:forward} if isforward forwardcache = get_tmp_cache(integrator, alg, unwrap_cache(integrator, true))[2] @@ -280,7 +280,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 end sparsity, colorvec = sparsity_colorvec(f, u) - if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff #_chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... _chunksize = get_chunksize(alg) T = if standardtag(alg) @@ -295,7 +295,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) - elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + elseif alg_autodiff(alg) isa SAutoFiniteDiff if alg_difftype(alg) !== Val{:complex} jac_config = FiniteDiff.JacobianCache(tmp, du1, du2, alg_difftype(alg), colorvec = colorvec, @@ -363,7 +363,7 @@ end function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} if !DiffEqBase.has_tgrad(f) - if nameof(alg_autodiff(alg)) == :AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(du1))) else @@ -385,7 +385,7 @@ function build_grad_config(alg, f::F1, tf::F2, du1, t) where {F1, F2} (ForwardDiff.Partials((one(eltype(du1)),)),)) .* false) end - elseif nameof(alg_autodiff(alg)) == :AutoFiniteDiff + elseif alg_autodiff(alg) isa AutoFiniteDiff grad_config = FiniteDiff.GradientCache(du1, t, alg_difftype(alg)) else error("$alg_autodiff not yet supported in build_grad_config function") From 2479e24802db14718d9ad469395b7e9b33752c8d Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:39:58 -0500 Subject: [PATCH 077/203] fix linsolves --- lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl index 93a46b5730..aa48161e1b 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/linsolve_utils.jl @@ -32,9 +32,9 @@ function dolinsolve(integrator, linsolve; A = nothing, linu = nothing, b = nothi if integrator isa SciMLBase.DEIntegrator && _alg.linsolve !== nothing && !LinearSolve.needs_concrete_A(_alg.linsolve) && linsolve.A isa WOperator && linsolve.A.J isa AbstractSciMLOperator - if nameof(alg_autodiff(_alg)) == :AutoForwardDiff + if alg_autodiff(_alg) isa AutoForwardDiff integrator.stats.nf += linres.iters - elseif nameof(alg_autodiff(_alg)) == :AutoFiniteDiff + elseif alg_autodiff(_alg) isa AutoFiniteDiff OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) * linres.iters else error("$alg_autodiff not yet supported in dolinsolve function") From f69e6b9c42b694ba45b1b983f6bc3a07a1f9bf65 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:40:13 -0500 Subject: [PATCH 078/203] fix prepare_alg --- .../src/alg_utils.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index dd2ad501b6..0a7288d7dc 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -65,17 +65,17 @@ function DiffEqBase.prepare_alg( # don't use a large chunksize as it will either error or not be beneficial # If prob.f.f is a FunctionWrappersWrappers from ODEFunction, need to set chunksize to 1 - if nameof(alg_autodiff(alg)) == :AutoForwardDiff && ((prob.f isa ODEFunction && + if alg_autodiff(alg) isa AutoForwardDiff && ((prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) || (isbitstype(T) && sizeof(T) > 24)) - return remake(alg, autodiff = constructorof(alg_autodiff(alg))(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) + return remake(alg, autodiff = AutoForwardDiff(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) end # If the autodiff alg is AutoFiniteDiff, prob.f.f isa FunctionWrappersWrapper, # and fdtype is complex, fdtype needs to change to something not complex - if nameof(alg_autodiff(alg)) == :AutoFiniteDiff + if alg_autodiff(alg) isa AutoFiniteDiff if alg_difftype(alg) == Val{:complex} && (prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) @warn "AutoFiniteDiff fdtype complex is not compatible with this function" - return remake(alg, autodiff = constructorof(alg_autodiff(alg))(fdtype = Val{:forward}())) + return remake(alg, autodiff = AutoFiniteDiff(fdtype = Val{:forward}())) end return alg end @@ -92,14 +92,13 @@ function DiffEqBase.prepare_alg( cs = ForwardDiff.pickchunksize(x) return remake(alg, - autodiff = constructorof(alg_autodiff(alg))( - chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) + autodiff = AutoForwardDiff( + chunksize = cs)) else # statically sized cs = pick_static_chunksize(Val{L}()) cs = SciMLBase._unwrap_val(cs) return remake( - alg, autodiff = constructorof(alg_autodiff(alg))( - chunksize = cs, tag = _get_fwd_tag(alg_autodiff(alg)))) + alg, autodiff = AutoForwardDiff(chunksize = cs)) end end From 0074bd198b1374ac5343da1e1d4fb36b11e068d4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 16:48:37 -0500 Subject: [PATCH 079/203] get rid of bad definition of alg_autodiff --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 0a7288d7dc..fdc427176b 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -38,8 +38,6 @@ function alg_autodiff(alg) end end -alg_autodiff(alg) = _alg_autodiff(alg) - Base.@pure function determine_chunksize(u, alg::DiffEqBase.DEAlgorithm) determine_chunksize(u, get_chunksize(alg)) end From dc6aaf20252201fdc4b524c9ef560193288e9187 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 17:03:08 -0500 Subject: [PATCH 080/203] small fixes --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 1 + lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 3684bbd753..92272b01a9 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -179,6 +179,7 @@ _get_fwd_chunksize_int(AD) = 0 _get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T _get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 +_get_fdtype(::Type{AutoFiniteDiff{T1,T2,T3}}) where {T1, T2, T3} = T1 function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index c7f4a1df34..f05b05cdb4 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -295,7 +295,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) - elseif alg_autodiff(alg) isa SAutoFiniteDiff + elseif alg_autodiff(alg) isa AutoFiniteDiff if alg_difftype(alg) !== Val{:complex} jac_config = FiniteDiff.JacobianCache(tmp, du1, du2, alg_difftype(alg), colorvec = colorvec, From 9a6f8f3fd81058e71906c9b3d6446a00409c4aa1 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 17:08:39 -0500 Subject: [PATCH 081/203] other nameof --- lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl index 0408ff5f26..3bed6a453a 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl @@ -72,7 +72,7 @@ mutable struct DAEResidualJacobianWrapper{isAD, F, pType, duType, uType, alphaTy uprev::uprevType t::tType function DAEResidualJacobianWrapper(alg, f, p, α, invγdt, tmp, uprev, t) - isautodiff = nameof(alg_autodiff(alg)) == :AutoForwardDiff + isautodiff = alg_autodiff(alg) isa AutoForwardDiff if isautodiff tmp_du = PreallocationTools.dualcache(uprev) tmp_u = PreallocationTools.dualcache(uprev) From 5fd3c20530ab338d74afccb0b9ca9b9cf8276e04 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 17:24:10 -0500 Subject: [PATCH 082/203] fixing constructorof --- .../src/derivative_utils.jl | 4 ++-- .../src/initialize_dae.jl | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl index 5f70501692..21b23c60fa 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_utils.jl @@ -711,7 +711,7 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits}, _f = islin ? (isode ? f.f : f.f1.f) : f jacvec = JacVec((du, u, p, t) -> _f(du, u, p, t), copy(u), p, t; - autodiff = constructorof(alg_autodiff(alg))(), tag = OrdinaryDiffEqTag()) + autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag()) J = jacvec W = WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec) elseif alg.linsolve !== nothing && !LinearSolve.needs_concrete_A(alg.linsolve) || @@ -734,7 +734,7 @@ function build_J_W(alg, u, uprev, p, t, dt, f::F, ::Type{uEltypeNoUnits}, (u, p, t) -> _f(u, p, t) end jacvec = JacVec(__f, copy(u), p, t; - autodiff = constructorof(alg_autodiff(alg))(), tag = OrdinaryDiffEqTag()) + autodiff = alg_autodiff(alg), tag = OrdinaryDiffEqTag()) WOperator{IIP}(f.mass_matrix, dt, J, u, jacvec) end else diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl index d49f71c64e..b5cffde762 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/initialize_dae.jl @@ -87,7 +87,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, alg::ShampineCollocation tmp = copy(_u0) end - isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || + isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u0) !== typeof(_u0) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) @@ -249,7 +249,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, tmp = copy(_u0) end - isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u0) !== typeof(_u0) + isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u0) !== typeof(_u0) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) _tmp = PreallocationTools.dualcache(tmp, chunk) @@ -392,7 +392,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, tmp = DiffEqBase.value.(tmp) end - isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u) !== typeof(_u) + isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u) !== typeof(_u) if isAD csize = count(algebraic_vars) if !(p isa SciMLBase.NullParameters) && typeof(_u) !== typeof(u) @@ -462,7 +462,7 @@ function _initialize_dae!(integrator, prob::ODEProblem, integrator.opts.internalnorm(resid, t) <= alg.abstol && return - isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff + isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff if isAD chunk = ForwardDiff.pickchunksize(count(algebraic_vars)) _tmp = PreallocationTools.dualcache(similar(u0), chunk) @@ -545,7 +545,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, error("differential_vars must be set for DAE initialization to occur. Either set consistent initial conditions, differential_vars, or use a different initialization algorithm.") end - isAD = nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff || typeof(u) !== typeof(_u) + isAD = alg_autodiff(integrator.alg) isa AutoForwardDiff || typeof(u) !== typeof(_u) if isAD chunk = ForwardDiff.pickchunksize(length(tmp)) _tmp = PreallocationTools.dualcache(tmp, chunk) @@ -573,7 +573,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, if alg.nlsolve !== nothing nlsolve = alg.nlsolve else - nlsolve = NewtonRaphson(autodiff = SciMLBase.constructorof(alg_autodiff(integrator.alg))()) + nlsolve = NewtonRaphson(autodiff = alg_autodiff(integrator.alg)) end nlfunc = NonlinearFunction(nlequation!; jac_prototype = f.jac_prototype) From 1b420d63f86c5ced952bcfc14105d31a22233d65 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 18:07:36 -0500 Subject: [PATCH 083/203] another dang nameof --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index f60aff3dcd..0034e55d9a 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -150,7 +150,7 @@ function _initialize_dae!(integrator, prob::AbstractDEProblem, isAD = if iu0 === nothing AutoForwardDiff elseif has_autodiff(integrator.alg) - nameof(alg_autodiff(integrator.alg)) == :AutoForwardDiff + alg_autodiff(integrator.alg) isa AutoForwardDiff else true end From 03fc1feff7326b67e826bd3a6a59f494011b3f22 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 11 Nov 2024 20:19:44 -0500 Subject: [PATCH 084/203] swap alg_autodiff around --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index fdc427176b..ebe0d64622 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -27,13 +27,14 @@ end function alg_autodiff(alg) autodiff = _alg_autodiff(alg) - if nameof(autodiff) == :AutoForwardDiff + + if autodiff == Val{true} return AutoForwardDiff() - elseif nameof(autodiff) == :AutoFiniteDiff + elseif autodiff == Val{false} return AutoFiniteDiff() - elseif autodiff == Val{true} + elseif nameof(autodiff) == :AutoForwardDiff return AutoForwardDiff() - elseif autodiff == Val{false} + elseif nameof(autodiff) == :AutoFiniteDiff return AutoFiniteDiff() end end From 0a0ad841502dc48e23e5443c7c7dddd5fe4bb377 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 09:49:10 -0500 Subject: [PATCH 085/203] fix compatibility with Val(::Bool) for other algs --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index ebe0d64622..82af1bfb1b 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -28,9 +28,9 @@ end function alg_autodiff(alg) autodiff = _alg_autodiff(alg) - if autodiff == Val{true} + if autodiff == Val(true) return AutoForwardDiff() - elseif autodiff == Val{false} + elseif autodiff == Val(false) return AutoFiniteDiff() elseif nameof(autodiff) == :AutoForwardDiff return AutoForwardDiff() From 8fbb34666802343ac885c75b86b8fe9ff5111ff0 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 14:36:00 -0500 Subject: [PATCH 086/203] fix fallback for get_chunksize --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 92272b01a9..54445e4089 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -174,8 +174,8 @@ end _get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) _get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS -_get_fwd_chunksize(AD) = Val(0) -_get_fwd_chunksize_int(AD) = 0 +_get_fwd_chunksize(AD) = Val(nothing) +_get_fwd_chunksize_int(AD) = nothing _get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T _get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 From 50f483a3a3c38cd6887c053a754c63c7a6af46b7 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 14:36:42 -0500 Subject: [PATCH 087/203] change to chunksize 1 for fallback --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 54445e4089..4de4ea39d2 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -174,8 +174,8 @@ end _get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) _get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS -_get_fwd_chunksize(AD) = Val(nothing) -_get_fwd_chunksize_int(AD) = nothing +_get_fwd_chunksize(AD) = Val(1) +_get_fwd_chunksize_int(AD) = 1 _get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T _get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 From 153f17cc2364e974063bf990d63ed9dd62564a10 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 15:36:30 -0500 Subject: [PATCH 088/203] change back to checking for Val(0) --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 4 ++-- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 4de4ea39d2..92272b01a9 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -174,8 +174,8 @@ end _get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) _get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS -_get_fwd_chunksize(AD) = Val(1) -_get_fwd_chunksize_int(AD) = 1 +_get_fwd_chunksize(AD) = Val(0) +_get_fwd_chunksize_int(AD) = 0 _get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T _get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index f05b05cdb4..d5c4872997 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -281,8 +281,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 sparsity, colorvec = sparsity_colorvec(f, u) if alg_autodiff(alg) isa AutoForwardDiff - #_chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... - _chunksize = get_chunksize(alg) + _chunksize = get_chunksize(alg) === Val(0) ? nothing : get_chunksize(alg) # SparseDiffEq uses different convection... T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) else @@ -292,7 +291,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 if _chunksize === Val{nothing}() _chunksize = nothing end - + println("_chunksize = $_chunksize") jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) elseif alg_autodiff(alg) isa AutoFiniteDiff From bc41895ddf65271d3d511b734c315f2842512386 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 17:38:50 -0500 Subject: [PATCH 089/203] no print --- lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index d5c4872997..0f9178a0ce 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -291,7 +291,6 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 if _chunksize === Val{nothing}() _chunksize = nothing end - println("_chunksize = $_chunksize") jac_config = ForwardColorJacCache(uf, uprev, _chunksize; colorvec = colorvec, sparsity = sparsity, tag = T) elseif alg_autodiff(alg) isa AutoFiniteDiff From 03e8337f7dd9f3b5f5f04265a1a797a490c12587 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 20:16:09 -0500 Subject: [PATCH 090/203] make sure AbstractADType is imported --- .../src/OrdinaryDiffEqDifferentiation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl index d8c8baf9f6..c3613a2233 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl @@ -1,6 +1,6 @@ module OrdinaryDiffEqDifferentiation -import ADTypes: AutoFiniteDiff, AutoForwardDiff +import ADTypes: AutoFiniteDiff, AutoForwardDiff, AbstractADType import SparseDiffTools: SparseDiffTools, matrix_colors, forwarddiff_color_jacobian!, forwarddiff_color_jacobian, ForwardColorJacCache, From d6dec75d5f88082d4fc9034a293bbae3d4ea55c1 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 13 Nov 2024 13:06:47 -0500 Subject: [PATCH 091/203] switch back CI --- .github/workflows/CI.yml | 2 +- .github/workflows/Downstream.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 296ae17352..406e0e61a1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -94,4 +94,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: lcov.info - fail_ci_if_error: false + fail_ci_if_error: true diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 9ebbc15439..d672b643bd 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -75,4 +75,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: lcov.info - fail_ci_if_error: false + fail_ci_if_error: true From 866f6bdfd0f9523e63121ae2ef99d889111d6a3d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 15 Nov 2024 16:33:11 -0100 Subject: [PATCH 092/203] Update CI.yml --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 406e0e61a1..296ae17352 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -94,4 +94,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: lcov.info - fail_ci_if_error: true + fail_ci_if_error: false From d96125a1e63676b6d970df0f6c47dfb69f274aa8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 15 Nov 2024 16:33:26 -0100 Subject: [PATCH 093/203] Update Downstream.yml --- .github/workflows/Downstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index d672b643bd..9ebbc15439 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -75,4 +75,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: lcov.info - fail_ci_if_error: true + fail_ci_if_error: false From 7257796252475af98300957030cf92e592b19b4f Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 18 Nov 2024 11:26:33 -0500 Subject: [PATCH 094/203] utils return ADTypes --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 8 ++++---- .../src/alg_utils.jl | 17 ++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index c5b580be5f..ac022c3462 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -135,15 +135,15 @@ isnewton(::Any) = false function _bool_to_ADType(::Val{true}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) chunksize = SciMLBase._unwrap_val(chunksize) == 0 ? nothing : SciMLBase._unwrap_val(chunksize) - typeof(AutoForwardDiff(chunksize = chunksize)) + AutoForwardDiff(chunksize = chunksize) end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) if diff_type isa Type - return typeof(AutoFiniteDiff(fdtype = diff_type())) + return AutoFiniteDiff(fdtype = diff_type()) else - return typeof(AutoFiniteDiff(fdtype = diff_type)) + return AutoFiniteDiff(fdtype = diff_type) end end @@ -156,7 +156,7 @@ function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) return _bool_to_ADType(Val{true}(), chunksize, diff_type) end - typeof(ad_alg) + ad_alg end diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 82af1bfb1b..16cd5ba005 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -14,17 +14,6 @@ function _alg_autodiff(::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, AD end -#function alg_autodiff(alg) -# autodiff = _alg_autodiff(alg) -# if autodiff == Val(false) -# return AutoFiniteDiff() -# elseif autodiff == Val(true) -# return AutoForwardDiff() -# else -# return _unwrap_val(autodiff) -# end -#end - function alg_autodiff(alg) autodiff = _alg_autodiff(alg) @@ -32,10 +21,8 @@ function alg_autodiff(alg) return AutoForwardDiff() elseif autodiff == Val(false) return AutoFiniteDiff() - elseif nameof(autodiff) == :AutoForwardDiff - return AutoForwardDiff() - elseif nameof(autodiff) == :AutoFiniteDiff - return AutoFiniteDiff() + else + return autodiff end end From 2051965340a84342ec8b0fb0aed27f5041d0e4df Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:16:06 -0500 Subject: [PATCH 095/203] SDIRK ADType --- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 153 ++++++++++++++-------- 1 file changed, 95 insertions(+), 58 deletions(-) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 5b5dcaca1a..53bca9e138 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -106,6 +106,7 @@ struct ImplicitEuler{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -117,10 +118,10 @@ function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ImplicitEuler{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + ImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, - nlsolve, precs, extrapolant, controller, step_limiter!) + nlsolve, precs, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring("A second order A-stable symplectic and symmetric implicit solver. @@ -147,6 +148,7 @@ struct ImplicitMidpoint{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: precs::P extrapolant::Symbol step_limiter!::StepLimiter + autodiff::AD end function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -157,13 +159,13 @@ function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ImplicitMidpoint{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + ImplicitMidpoint{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, - step_limiter!) + step_limiter!, AD_choice) end @doc SDIRK_docstring( @@ -192,6 +194,7 @@ struct Trapezoid{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -203,14 +206,15 @@ function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc SDIRK_docstring("A second order A-B-L-S-stable one-step ESDIRK method. @@ -247,6 +251,7 @@ struct TRBDF2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -256,10 +261,10 @@ function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt controller = :PI, step_limiter! = trivial_limiter!) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - TRBDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + TRBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end TruncatedStacktraces.@truncate_stacktrace TRBDF2 @@ -296,6 +301,7 @@ struct SDIRK2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -306,12 +312,13 @@ function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SDIRK2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}( linsolve, nlsolve, precs, smooth_est, extrapolant, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc SDIRK_docstring("Description TBD", @@ -340,6 +347,7 @@ struct SDIRK22{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function SDIRK22(; @@ -351,14 +359,15 @@ function SDIRK22(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Trapezoid{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, extrapolant, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc SDIRK_docstring( @@ -395,6 +404,7 @@ struct SSPSDIRK2{CS, AD, F, F2, P, FDT, ST, CJ} <: smooth_est::Bool extrapolant::Symbol controller::Symbol + autodiff::AD end function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -406,10 +416,10 @@ function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SSPSDIRK2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SSPSDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring("An A-L stable stiffly-accurate 3rd order ESDIRK method.", @@ -454,10 +464,10 @@ function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Kvaerno3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring( @@ -489,6 +499,7 @@ struct KenCarp3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -499,10 +510,10 @@ function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + KenCarp3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring("Third order method.", @@ -528,6 +539,7 @@ struct CFNLIRK3{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -537,12 +549,13 @@ function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - CFNLIRK3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + CFNLIRK3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("An A-L stable 4th order SDIRK method.", @@ -577,6 +590,7 @@ struct Cash4{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol embedding::Int controller::Symbol + autodiff::AD end function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -587,7 +601,7 @@ function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Cash4{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, @@ -595,7 +609,8 @@ function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta smooth_est, extrapolant, embedding, - controller) + controller, + AD_choice) end @doc SDIRK_docstring("Method of order 4.", @@ -621,6 +636,7 @@ struct SFSDIRK4{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -630,12 +646,13 @@ function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SFSDIRK4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("Method of order 5.", @@ -661,6 +678,7 @@ struct SFSDIRK5{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -671,12 +689,13 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SFSDIRK5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("Method of order 6.", @@ -702,6 +721,7 @@ struct SFSDIRK6{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -712,12 +732,13 @@ function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK6{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SFSDIRK6{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("Method of order 7.", @@ -743,6 +764,7 @@ struct SFSDIRK7{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -753,12 +775,13 @@ function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK7{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SFSDIRK7{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("Method of order 8.", @@ -784,6 +807,7 @@ struct SFSDIRK8{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -794,12 +818,13 @@ function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SFSDIRK8{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + SFSDIRK8{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc SDIRK_docstring("An A-L stable 4th order SDIRK method.", @@ -825,6 +850,7 @@ struct Hairer4{CS, AD, F, F2, P, FDT, ST, CJ} <: smooth_est::Bool extrapolant::Symbol controller::Symbol + autodiff::AD end function Hairer4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -835,10 +861,10 @@ function Hairer4(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Hairer4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring("An A-L stable 4th order SDIRK method.", @@ -864,6 +890,7 @@ struct Hairer42{CS, AD, F, F2, P, FDT, ST, CJ} <: smooth_est::Bool extrapolant::Symbol controller::Symbol + autodiff::AD end function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -874,10 +901,10 @@ function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Hairer42{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Hairer42{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring("An A-L stable stiffly-accurate 4th order ESDIRK method.", @@ -912,6 +939,7 @@ struct Kvaerno4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -922,10 +950,10 @@ function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Kvaerno4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring("An A-L stable stiffly-accurate 5th order ESDIRK method.", @@ -960,6 +988,7 @@ struct Kvaerno5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -970,10 +999,10 @@ function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - Kvaerno5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + Kvaerno5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring( @@ -1005,6 +1034,7 @@ struct KenCarp4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1015,10 +1045,10 @@ function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp4{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + KenCarp4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end TruncatedStacktraces.@truncate_stacktrace KenCarp4 @@ -1052,6 +1082,7 @@ struct KenCarp47{CS, AD, F, F2, P, FDT, ST, CJ} <: smooth_est::Bool extrapolant::Symbol controller::Symbol + autodiff::AD end function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1062,10 +1093,10 @@ function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp47{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + KenCarp47{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring( @@ -1097,6 +1128,7 @@ struct KenCarp5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1107,10 +1139,10 @@ function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp5{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + KenCarp5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!)}(linsolve, nlsolve, precs, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc SDIRK_docstring( @@ -1142,6 +1174,7 @@ struct KenCarp58{CS, AD, F, F2, P, FDT, ST, CJ} <: smooth_est::Bool extrapolant::Symbol controller::Symbol + autodiff::AD end function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1152,10 +1185,10 @@ function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - KenCarp58{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + KenCarp58{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, smooth_est, extrapolant, - controller) + controller, AD_choice) end # `smooth_est` is not necessary, as the embedded method is also L-stable @@ -1187,6 +1220,7 @@ struct ESDIRK54I8L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1196,10 +1230,10 @@ function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK54I8L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + ESDIRK54I8L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring( @@ -1230,6 +1264,7 @@ struct ESDIRK436L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1239,10 +1274,10 @@ function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK436L2SA2{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + ESDIRK436L2SA2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring( @@ -1282,10 +1317,10 @@ function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK437L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + ESDIRK437L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring( @@ -1316,6 +1351,7 @@ struct ESDIRK547L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1325,10 +1361,10 @@ function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK547L2SA2{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + ESDIRK547L2SA2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, - controller) + controller, AD_choice) end @doc SDIRK_docstring( @@ -1361,6 +1397,7 @@ struct ESDIRK659L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -1370,8 +1407,8 @@ function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - ESDIRK659L2SA{_unwrap_val(chunk_size),AD_choice, typeof(linsolve), + ESDIRK659L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, extrapolant, - controller) + controller, AD_choice) end From 42211b42e53e8bfd1917cb8cd7b8c63989fd7256 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:21:46 -0500 Subject: [PATCH 096/203] PDIRK and BDF ADTypes --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 59 ++++++++++++++--------- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 5 +- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 197c48efa3..3a9f161903 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -112,6 +112,7 @@ struct ABDF2{CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -123,10 +124,10 @@ function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ABDF2{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}(linsolve, nlsolve, precs, κ, tol, - smooth_est, extrapolant, controller, step_limiter!) + smooth_est, extrapolant, controller, step_limiter!, AD_choice) end @doc BDF_docstring( @@ -170,6 +171,7 @@ struct SBDF{CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: extrapolant::Symbol order::Int ark::Bool + autodiff::AD end function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -180,7 +182,7 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -189,7 +191,8 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), tol, extrapolant, order, - ark) + ark, + AD_choice) end # All keyword form needed for remake @@ -202,7 +205,7 @@ function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - SBDF{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(linsolve, nlsolve, @@ -211,7 +214,8 @@ function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag tol, extrapolant, order, - ark) + ark, + AD_choice) end """ @@ -296,6 +300,7 @@ struct QNDF1{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: kappa::κType controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -307,7 +312,7 @@ function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF1{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -315,7 +320,8 @@ function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant, kappa, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc BDF_docstring( @@ -354,6 +360,7 @@ struct QNDF2{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: kappa::κType controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -365,7 +372,7 @@ function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF2{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(kappa), typeof(step_limiter!)}(linsolve, nlsolve, @@ -373,7 +380,8 @@ function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta extrapolant, kappa, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc BDF_docstring( @@ -420,6 +428,7 @@ struct QNDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T, κType, StepLimiter} <: kappa::κType controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), @@ -433,12 +442,12 @@ function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - QNDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), + QNDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(kappa), typeof(step_limiter!)}( max_order, linsolve, nlsolve, precs, κ, tol, - extrapolant, kappa, controller, step_limiter!) + extrapolant, kappa, controller, step_limiter!, AD_choice) end TruncatedStacktraces.@truncate_stacktrace QNDF @@ -470,6 +479,7 @@ struct MEBDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -478,12 +488,13 @@ function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - MEBDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + MEBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc BDF_docstring( @@ -525,6 +536,7 @@ struct FBDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), @@ -536,12 +548,12 @@ function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - FBDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), + FBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(step_limiter!)}( max_order, linsolve, nlsolve, precs, κ, tol, extrapolant, - controller, step_limiter!) + controller, step_limiter!, AD_choice) end TruncatedStacktraces.@truncate_stacktrace FBDF @@ -644,6 +656,7 @@ struct DImplicitEuler{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function DImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -654,10 +667,10 @@ function DImplicitEuler(; AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DImplicitEuler{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + DImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, - nlsolve, precs, extrapolant, controller) + nlsolve, precs, extrapolant, controller, AD_choice) end @doc BDF_docstring("Fully implicit implementation of BDF2.", @@ -686,6 +699,7 @@ struct DABDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT, ST, CJ precs::P extrapolant::Symbol controller::Symbol + autodiff::AD end function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -695,10 +709,10 @@ function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardt AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DABDF2{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + DABDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, - nlsolve, precs, extrapolant, controller) + nlsolve, precs, extrapolant, controller, AD_choice) end #= @@ -748,6 +762,7 @@ struct DFBDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: DAEAlgorithm{CS, AD, FD tol::T extrapolant::Symbol controller::Symbol + autodiff::AD end function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -758,11 +773,11 @@ function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - DFBDF{MO, _unwrap_val(chunk_size), AD_choice, typeof(linsolve), + DFBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol)}(max_order, linsolve, nlsolve, precs, κ, tol, extrapolant, - controller) + controller, AD_choice) end TruncatedStacktraces.@truncate_stacktrace DFBDF diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index d961d88d1a..8a553c6821 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -28,6 +28,7 @@ struct PDIRK44{CS, AD, F, F2, P, FDT, ST, CJ, TO} <: precs::P extrapolant::Symbol threading::TO + autodiff::AD end function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -36,8 +37,8 @@ function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standard AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - PDIRK44{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + PDIRK44{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, nlsolve, precs, - extrapolant, threading) + extrapolant, threading, AD_choice) end From 33b34fd6353e3f4d753c8266079d6f24f4e25fb9 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:23:56 -0500 Subject: [PATCH 097/203] FIRK ADTypes --- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 47 ++++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 367bed94df..706d6f4b84 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -37,6 +37,7 @@ struct RadauIIA3{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: new_W_γdt_cutoff::C2 controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -50,7 +51,7 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA3{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + RadauIIA3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -61,7 +62,8 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), fast_convergence_cutoff, new_W_γdt_cutoff, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc differentiation_rk_docstring( @@ -84,6 +86,7 @@ struct RadauIIA5{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: new_W_γdt_cutoff::C2 controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -97,7 +100,7 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA5{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + RadauIIA5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -109,7 +112,8 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), fast_convergence_cutoff, new_W_γdt_cutoff, controller, - step_limiter!) + step_limiter!, + AD_choice) end @doc differentiation_rk_docstring( @@ -132,6 +136,7 @@ struct RadauIIA9{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: new_W_γdt_cutoff::C2 controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -145,7 +150,7 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - RadauIIA9{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + RadauIIA9{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -157,23 +162,25 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), fast_convergence_cutoff, new_W_γdt_cutoff, controller, - step_limiter!) + step_limiter!, + AD_choice) end struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: OrdinaryDiffEqNewtonAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} - linsolve::F - precs::P - smooth_est::Bool - extrapolant::Symbol - κ::Tol - maxiters::Int - fast_convergence_cutoff::C1 - new_W_γdt_cutoff::C2 - controller::Symbol - step_limiter!::StepLimiter - min_order::Int - max_order::Int + linsolve::F + precs::P + smooth_est::Bool + extrapolant::Symbol + κ::Tol + maxiters::Int + fast_convergence_cutoff::C1 + new_W_γdt_cutoff::C2 + controller::Symbol + step_limiter!::StepLimiter + min_order::Int + max_order::Int + autodiff::AD end function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -187,7 +194,7 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - AdaptiveRadau{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, @@ -199,6 +206,6 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), fast_convergence_cutoff, new_W_γdt_cutoff, controller, - step_limiter!, min_order, max_order) + step_limiter!, min_order, max_order, AD_choice) end From 1d06dbc18c43acd98f9b83064af6686de874dc86 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:26:29 -0500 Subject: [PATCH 098/203] Exrapolation ADTypes --- .../src/algorithms.jl | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index b099c0834b..b7f9645406 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -64,6 +64,7 @@ struct ImplicitEulerExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: init_order::Int threading::TO sequence::Symbol # Name of the subdividing sequence + autodiff::AD end function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -102,12 +103,12 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") :$(sequence) --> :harmonic" sequence = :harmonic end - ImplicitEulerExtrapolation{_unwrap_val(chunk_size), AD_choice, + ImplicitEulerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, max_order, min_order, init_order, - threading, sequence) + threading, sequence, AD_choice) end @doc generic_solver_docstring("Midpoint extrapolation using Barycentric coordinates.", @@ -207,6 +208,7 @@ struct ImplicitDeuflhardExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: max_order::Int # Maximal extrapolation order sequence::Symbol # Name of the subdividing sequence threading::TO + autodiff::AD end function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -248,12 +250,12 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") end # Initialize algorithm - ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), AD_choice, + ImplicitDeuflhardExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, init_order, max_order, - sequence, threading) + sequence, threading, AD_choice) end @doc generic_solver_docstring("Midpoint extrapolation using Barycentric coordinates, @@ -357,6 +359,7 @@ struct ImplicitHairerWannerExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: max_order::Int # Maximal extrapolation order sequence::Symbol # Name of the subdividing sequence threading::TO + autodiff::AD end function ImplicitHairerWannerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -399,12 +402,12 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), AD_choice, + ImplicitHairerWannerExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, precs, min_order, init_order, - max_order, sequence, threading) + max_order, sequence, threading, AD_choice) end @doc differentiation_rk_docstring("Euler extrapolation using Barycentric coordinates, @@ -438,6 +441,7 @@ struct ImplicitEulerBarycentricExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: sequence::Symbol # Name of the subdividing sequence threading::TO sequence_factor::Int + autodiff::AD end function ImplicitEulerBarycentricExtrapolation(; chunk_size = Val{0}(), @@ -481,7 +485,7 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Initialize algorithm - ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), AD_choice, + ImplicitEulerBarycentricExtrapolation{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(threading)}(linsolve, @@ -491,5 +495,6 @@ Initial order: " * lpad(init_order, 2, " ") * " --> " * lpad(init_order, 2, " ") max_order, sequence, threading, - sequence_factor) + sequence_factor, + AD_choice) end From d7f16e3ff01dc96abb77fe13acbd7ca39b557faa Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:28:12 -0500 Subject: [PATCH 099/203] exponentialRK ADTypes --- .../src/algorithms.jl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index 8be1efc709..d0efd71f32 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -32,6 +32,7 @@ for (Alg, Description, Ref) in [ krylov::Bool m::Int iop::Int + autodiff::AD end end @eval function $Alg(; krylov = false, m = 30, iop = 0, autodiff = AutoForwardDiff(), @@ -41,10 +42,11 @@ for (Alg, Description, Ref) in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(krylov, m, - iop) + iop, + AD_choice) end end @@ -75,6 +77,7 @@ for (Alg, Description, Ref) in [ OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD, FDT, ST, CJ} m::Int iop::Int + autodiff::AD end end @eval function $Alg(; m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -83,10 +86,11 @@ for (Alg, Description, Ref) in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(m, - iop) + iop, + AD_choice) end end @@ -135,6 +139,7 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) adaptive_krylov::Bool m::Int iop::Int + autodiff::AD end end @eval function $Alg(; adaptive_krylov = true, m = 30, iop = 0, autodiff = AutoForwardDiff(), @@ -143,10 +148,11 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, diff_type, + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(adaptive_krylov, m, - iop) + iop, + AD_choice) end end From fb872c1dc2cb920be2c14526b2a47e98b90fcfcf Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:29:14 -0500 Subject: [PATCH 100/203] IMEXMultistep ADTypes --- lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index d34343e3ca..0e4e846612 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -26,6 +26,7 @@ struct CNAB2{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -36,12 +37,13 @@ function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNAB2{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end @doc generic_solver_docstring("Crank-Nicholson Leapfrong 2.", @@ -69,6 +71,7 @@ struct CNLF2{CS, AD, F, F2, P, FDT, ST, CJ} <: nlsolve::F2 precs::P extrapolant::Symbol + autodiff::AD end function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, @@ -78,10 +81,11 @@ function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardta AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNLF2{ - _unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}( linsolve, nlsolve, precs, - extrapolant) + extrapolant, + AD_choice) end From 5ee0f09ae7115fb3803d56a8aa540b72f11183d1 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:32:26 -0500 Subject: [PATCH 101/203] stabilizedIRK and Rosenbrock ADTypes --- .../src/algorithms.jl | 20 +++++++++++-------- .../src/algorithms.jl | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index e0174e4bd3..d648ac0a10 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -110,6 +110,7 @@ for Alg in [ precs::P step_limiter!::StepLimiter stage_limiter!::StageLimiter + autodiff::AD end function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -118,11 +119,11 @@ for Alg in [ stage_limiter! = trivial_limiter!) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(step_limiter!), typeof(stage_limiter!)}(linsolve, precs, step_limiter!, - stage_limiter!) + stage_limiter!, AD_choice) end end end @@ -130,6 +131,7 @@ struct GeneralRosenbrock{CS, AD, F, ST, CJ, TabType} <: OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, Val{:forward}, ST, CJ} tableau::TabType factorization::F + autodiff::AD end function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), @@ -139,9 +141,9 @@ function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff() AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) GeneralRosenbrock{ - _unwrap_val(chunk_size), AD_choice, typeof(factorization), + _unwrap_val(chunk_size), typeof(AD_choice), typeof(factorization), _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(tableau)}(tableau, - factorization) + factorization, AD_choice) end @doc rosenbrock_wolfbrandt_docstring( @@ -156,6 +158,7 @@ struct RosenbrockW6S4OS{CS, AD, F, P, FDT, ST, CJ} <: OrdinaryDiffEqRosenbrockAlgorithm{CS, AD, FDT, ST, CJ} linsolve::F precs::P + autodiff::AD end function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -166,9 +169,9 @@ function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RosenbrockW6S4OS{_unwrap_val(chunk_size), - AD_choice, typeof(linsolve), typeof(precs), diff_type, + typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, - precs) + precs, AD_choice) end for Alg in [ @@ -197,6 +200,7 @@ for Alg in [ OrdinaryDiffEqRosenbrockAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} linsolve::F precs::P + autodiff::AD end function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, @@ -204,10 +208,10 @@ for Alg in [ AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - $Alg{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), + $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac)}(linsolve, - precs) + precs, AD_choice) end end end diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index 9be6e769da..edfef4fa47 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -17,6 +17,7 @@ struct IRKC{CS, AD, F, F2, P, FDT, ST, CJ, K, T, E} <: extrapolant::Symbol controller::Symbol eigen_est::E + autodiff::AD end function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), @@ -27,8 +28,8 @@ function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - IRKC{_unwrap_val(chunk_size), AD_choice, typeof(linsolve), typeof(nlsolve), + IRKC{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(tol), typeof(eigen_est)}(linsolve, nlsolve, precs, κ, tol, - extrapolant, controller, eigen_est) + extrapolant, controller, eigen_est, AD_choice) end From da17cc301a9ab808796cc408ff518b1eb67ca3e2 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 14 Nov 2024 11:00:19 -0500 Subject: [PATCH 102/203] missed Kvaerno3 ADTypes --- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 53bca9e138..c10a4dcd11 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -454,6 +454,7 @@ struct Kvaerno3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: extrapolant::Symbol controller::Symbol step_limiter!::StepLimiter + autodiff::AD end function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, From 1b5bd333d8ce8349cb9e1a10dd6f5cea03d1c6e4 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 18 Nov 2024 12:12:59 -0500 Subject: [PATCH 103/203] fix the alg utils --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 16cd5ba005..cb739174be 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -2,16 +2,16 @@ function _alg_autodiff(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have an autodifferentiation option defined.") end -_alg_autodiff(::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} = AD -_alg_autodiff(::DAEAlgorithm{CS, AD}) where {CS, AD} = AD -_alg_autodiff(::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = AD +_alg_autodiff(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff +_alg_autodiff(alg::DAEAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff +_alg_autodiff(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff _alg_autodiff(alg::CompositeAlgorithm) = _alg_autodiff(alg.algs[end]) function _alg_autodiff(::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD} }) where { CS, AD } - AD + alg.autodiff end function alg_autodiff(alg) From eef83f27f15f2f1ca2a15c61508a5eef71e886d9 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 18 Nov 2024 12:22:18 -0500 Subject: [PATCH 104/203] remove cruft --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 5 ----- lib/OrdinaryDiffEqCore/src/algorithms.jl | 1 - lib/OrdinaryDiffEqCore/src/misc_utils.jl | 5 ----- 3 files changed, 11 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 92272b01a9..fb9f9805aa 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -460,8 +460,3 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end print(io, ")") end - - -#function get_chunksize(alg::AutoForwardDiff{CS}) where {CS} -# Val(CS) -#end diff --git a/lib/OrdinaryDiffEqCore/src/algorithms.jl b/lib/OrdinaryDiffEqCore/src/algorithms.jl index 18241648f3..eb1b774849 100644 --- a/lib/OrdinaryDiffEqCore/src/algorithms.jl +++ b/lib/OrdinaryDiffEqCore/src/algorithms.jl @@ -88,7 +88,6 @@ struct CompositeAlgorithm{CS, T, F} <: OrdinaryDiffEqCompositeAlgorithm algs::T choice_function::F function CompositeAlgorithm(algs::T, choice_function::F) where {T, F} - #CS = mapreduce(alg -> has_chunksize(alg) ? get_chunksize_int(alg) : 0, max, algs) CS = mapreduce(alg -> 0, max, algs) new{CS, T, F}(algs, choice_function) end diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index ac022c3462..d9a0c61ece 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -158,8 +158,3 @@ function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) ad_alg end - - -_ADType_to_Bool(::Type{T}) where {T <: AutoForwardDiff} = true - -_ADType_to_Bool(::Type{T}) where {T <: AutoFiniteDiff} = false \ No newline at end of file From 1bde623b01e34828d003ae15dfd90c345535a713 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 18 Nov 2024 15:36:41 -0500 Subject: [PATCH 105/203] typoed --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index cb739174be..8d767433fd 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -6,7 +6,7 @@ _alg_autodiff(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, A _alg_autodiff(alg::DAEAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff _alg_autodiff(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff _alg_autodiff(alg::CompositeAlgorithm) = _alg_autodiff(alg.algs[end]) -function _alg_autodiff(::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, +function _alg_autodiff(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD} }) where { CS, AD From a24771c4cf67b5db3358c6dbed98f92b6e8c4df2 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 19 Nov 2024 09:29:37 -0500 Subject: [PATCH 106/203] fix tag, update import --- lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl | 2 +- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 8d767433fd..76161503c2 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -53,7 +53,7 @@ function DiffEqBase.prepare_alg( if alg_autodiff(alg) isa AutoForwardDiff && ((prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) || (isbitstype(T) && sizeof(T) > 24)) - return remake(alg, autodiff = AutoForwardDiff(chunksize = 1, tag = _get_fwd_tag(alg_autodiff(alg)))) + return remake(alg, autodiff = AutoForwardDiff(chunksize = 1, tag = alg_autodiff(alg).tag)) end # If the autodiff alg is AutoFiniteDiff, prob.f.f isa FunctionWrappersWrapper, diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 57e685d8fd..593f27ee77 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -26,7 +26,7 @@ import SciMLStructures: canonicalize, Tunable, isscimlstructure import OrdinaryDiffEqCore import SciMLOperators: islinear -import OrdinaryDiffEqCore: nlsolve_f, set_new_W!, set_W_γdt!, _ADType_to_Bool +import OrdinaryDiffEqCore: nlsolve_f, set_new_W!, set_W_γdt! @static if isdefined(OrdinaryDiffEqCore, :default_nlsolve) import OrdinaryDiffEqCore: default_nlsolve From c0c3955642bff9e27c290c7ebe92ab5dd55cd603 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 4 Dec 2024 19:30:41 -0700 Subject: [PATCH 107/203] get rid of the type weirdness, add a warning for using chunksize kwarg --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index d9a0c61ece..6c7863bd65 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -140,11 +140,7 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - if diff_type isa Type - return AutoFiniteDiff(fdtype = diff_type()) - else - return AutoFiniteDiff(fdtype = diff_type) - end + return AutoFiniteDiff(fdtype = diff_type()) end # Functions to get ADType type from Bool or ADType object, or ADType type @@ -153,6 +149,7 @@ _process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(Val(ad_ function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) # need a path for if just chunksize is specified in the Algorithm construction if !(chunksize === Val{0}()) + @warn "The `chunksize` keyword is deprecated. Please use an `ADType` specifier. For now defaulting to using `ForwardDiff` with the given `chunksize`." return _bool_to_ADType(Val{true}(), chunksize, diff_type) end From df50b90112660be670c81954257cbce607483c7e Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 9 Dec 2024 11:18:37 -0500 Subject: [PATCH 108/203] change to instance of Val{fdtype} --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 24 ++++---- .../src/algorithms.jl | 6 +- .../src/algorithms.jl | 8 +-- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 8 +-- .../src/algorithms.jl | 4 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 2 +- .../src/algorithms.jl | 4 +- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 60 +++++++++---------- .../src/algorithms.jl | 2 +- 9 files changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 3a9f161903..8bbe3f60e5 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -8,7 +8,7 @@ function BDF_docstring(description::String, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, """ * "\n" * extra_keyword_default @@ -115,7 +115,7 @@ struct ABDF2{CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: autodiff::AD end function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), κ = nothing, tol = nothing, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, @@ -175,7 +175,7 @@ struct SBDF{CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: end function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), - standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}, + standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, ark = false) @@ -197,7 +197,7 @@ end # All keyword form needed for remake function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, @@ -304,7 +304,7 @@ struct QNDF1{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: end function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -37 // 200, controller = :Standard, step_limiter! = trivial_limiter!) @@ -364,7 +364,7 @@ struct QNDF2{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: end function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -1 // 9, controller = :Standard, step_limiter! = trivial_limiter!) @@ -433,7 +433,7 @@ end function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, kappa = ( @@ -482,7 +482,7 @@ struct MEBDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: autodiff::AD end function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant) @@ -541,7 +541,7 @@ end function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) where {MO} @@ -660,7 +660,7 @@ struct DImplicitEuler{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT end function DImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) @@ -702,7 +702,7 @@ struct DABDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT, ST, CJ autodiff::AD end function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) @@ -766,7 +766,7 @@ struct DFBDF{MO, CS, AD, F, F2, P, FDT, ST, CJ, K, T} <: DAEAlgorithm{CS, AD, FD end function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard) where {MO} diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index d0efd71f32..1ed1b25fad 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -38,7 +38,7 @@ for (Alg, Description, Ref) in [ @eval function $Alg(; krylov = false, m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), - diff_type = Val{:forward}) + diff_type = Val{:forward}()) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) @@ -82,7 +82,7 @@ for (Alg, Description, Ref) in [ end @eval function $Alg(; m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), - diff_type = Val{:forward}) + diff_type = Val{:forward}()) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) @@ -144,7 +144,7 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) end @eval function $Alg(; adaptive_krylov = true, m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - chunk_size = Val{0}(), diff_type = Val{:forward}) + chunk_size = Val{0}(), diff_type = Val{:forward}()) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index b7f9645406..82cb923123 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -69,7 +69,7 @@ end function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, linsolve = nothing, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, max_order = 12, min_order = 3, init_order = 5, threading = false, sequence = :harmonic) @@ -213,7 +213,7 @@ end function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), min_order = 1, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) @@ -366,7 +366,7 @@ function ImplicitHairerWannerExtrapolation(; chunk_size = Val{0}(), autodiff = A standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), min_order = 2, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) @@ -449,7 +449,7 @@ function ImplicitEulerBarycentricExtrapolation(; chunk_size = Val{0}(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), min_order = 3, init_order = 5, max_order = 12, sequence = :harmonic, threading = false, sequence_factor = 2) diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 706d6f4b84..c7b534e4fe 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -42,7 +42,7 @@ end function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, extrapolant = :dense, fast_convergence_cutoff = 1 // 5, new_W_γdt_cutoff = 1 // 5, @@ -91,7 +91,7 @@ end function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, extrapolant = :dense, fast_convergence_cutoff = 1 // 5, new_W_γdt_cutoff = 1 // 5, @@ -141,7 +141,7 @@ end function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, extrapolant = :dense, fast_convergence_cutoff = 1 // 5, new_W_γdt_cutoff = 1 // 5, @@ -185,7 +185,7 @@ end function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, min_order = 5, max_order = 13, + diff_type = Val{:forward}(), min_order = 5, max_order = 13, linsolve = nothing, precs = DEFAULT_PRECS, extrapolant = :dense, fast_convergence_cutoff = 1 // 5, new_W_γdt_cutoff = 1 // 5, diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index 0e4e846612..7bbcc0476b 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -30,7 +30,7 @@ struct CNAB2{CS, AD, F, F2, P, FDT, ST, CJ} <: end function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -74,7 +74,7 @@ struct CNLF2{CS, AD, F, F2, P, FDT, ST, CJ} <: autodiff::AD end function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index 8a553c6821..f87c6ce19b 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -31,7 +31,7 @@ struct PDIRK44{CS, AD, F, F2, P, FDT, ST, CJ, TO} <: autodiff::AD end function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, threading = true) diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index d648ac0a10..d88df57dc9 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -114,7 +114,7 @@ for Alg in [ end function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, linsolve = nothing, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, stage_limiter! = trivial_limiter!) @@ -204,7 +204,7 @@ for Alg in [ end function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, linsolve = nothing, precs = DEFAULT_PRECS) + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index c10a4dcd11..f0bdfe3fbb 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -8,7 +8,7 @@ function SDIRK_docstring(description::String, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), @@ -111,7 +111,7 @@ end function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :PI, step_limiter! = trivial_limiter!) @@ -153,7 +153,7 @@ end function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, step_limiter! = trivial_limiter!) @@ -199,7 +199,7 @@ end function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -255,7 +255,7 @@ struct TRBDF2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -305,7 +305,7 @@ struct SDIRK2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -352,7 +352,7 @@ end function SDIRK22(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -409,7 +409,7 @@ end function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :constant, controller = :PI) @@ -458,7 +458,7 @@ struct Kvaerno3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -504,7 +504,7 @@ struct KenCarp3{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -544,7 +544,7 @@ struct CFNLIRK3{CS, AD, F, F2, P, FDT, ST, CJ} <: end function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -594,7 +594,7 @@ struct Cash4{CS, AD, F, F2, P, FDT, ST, CJ} <: autodiff::AD end function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, embedding = 3) @@ -641,7 +641,7 @@ struct SFSDIRK4{CS, AD, F, F2, P, FDT, ST, CJ} <: end function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -684,7 +684,7 @@ end function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -727,7 +727,7 @@ end function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -770,7 +770,7 @@ end function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -813,7 +813,7 @@ end function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) @@ -855,7 +855,7 @@ struct Hairer4{CS, AD, F, F2, P, FDT, ST, CJ} <: end function Hairer4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) @@ -895,7 +895,7 @@ struct Hairer42{CS, AD, F, F2, P, FDT, ST, CJ} <: end function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) @@ -944,7 +944,7 @@ struct Kvaerno4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -993,7 +993,7 @@ struct Kvaerno5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -1039,7 +1039,7 @@ struct KenCarp4{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -1087,7 +1087,7 @@ struct KenCarp47{CS, AD, F, F2, P, FDT, ST, CJ} <: end function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) @@ -1133,7 +1133,7 @@ struct KenCarp5{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: end function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) @@ -1179,7 +1179,7 @@ struct KenCarp58{CS, AD, F, F2, P, FDT, ST, CJ} <: end function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) @@ -1225,7 +1225,7 @@ struct ESDIRK54I8L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: end function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) @@ -1269,7 +1269,7 @@ struct ESDIRK436L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: end function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) @@ -1312,7 +1312,7 @@ struct ESDIRK437L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: end function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) @@ -1356,7 +1356,7 @@ struct ESDIRK547L2SA2{CS, AD, F, F2, P, FDT, ST, CJ} <: end function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) @@ -1402,7 +1402,7 @@ struct ESDIRK659L2SA{CS, AD, F, F2, P, FDT, ST, CJ} <: end function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, + diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index edfef4fa47..c92d88bc22 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -21,7 +21,7 @@ struct IRKC{CS, AD, F, F2, P, FDT, ST, CJ, K, T, E} <: end function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), - concrete_jac = nothing, diff_type = Val{:forward}, + concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, eigen_est = nothing) From 14bb3bc00f9a7d54cd9b502983897a62cdb9a4a6 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 9 Dec 2024 11:23:25 -0500 Subject: [PATCH 109/203] use the given diff_type --- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 6c7863bd65..3c347943e2 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -140,7 +140,7 @@ end function _bool_to_ADType(::Val{false}, chunksize, diff_type) Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - return AutoFiniteDiff(fdtype = diff_type()) + return AutoFiniteDiff(fdtype = diff_type) end # Functions to get ADType type from Bool or ADType object, or ADType type From 0c22789559862409cdb6a159b74d921e3d20aaba Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 9 Dec 2024 11:36:33 -0500 Subject: [PATCH 110/203] update doc strings to reflect ADTypes --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 16 +++++----- lib/OrdinaryDiffEqCore/src/doc_utils.jl | 15 +++++----- .../src/OrdinaryDiffEqRosenbrock.jl | 30 +++++++++---------- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 15 +++++----- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 8bbe3f60e5..9547b2a263 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -8,18 +8,19 @@ function BDF_docstring(description::String, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, """ * "\n" * extra_keyword_default keyword_default_description = """ - - `chunk_size`: The chunk size used with ForwardDiff.jl. Defaults to `Val{0}()` - and thus uses the internal ForwardDiff.jl algorithm for the choice. - - `autodiff`: Specifies whether to use automatic differentiation via + - `autodiff`: Uses [ADTypes.jl](https://sciml.github.io/ADTypes.jl/stable/) + to specify whether to use automatic differentiation via [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) or finite - differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). - Defaults to `Val{true}()` for automatic differentiation. + differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). + Defaults to `AutoForwardDiff()` for automatic differentiation, which by default uses + `chunksize = 0`, and thus uses the internal ForwardDiff.jl algorithm for the choice. + To use `FiniteDiff.jl`, the `AutoFiniteDiff()` ADType can be used, which has a keyword argument + `fdtype` with default value `Val{:forward}()`, and alternatives `Val{:central}()` and `Val{:complex}()`. - `standardtag`: Specifies whether to use package-specific tags instead of the ForwardDiff default function-specific tags. For more information, see [this blog post](https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/). @@ -27,9 +28,6 @@ function BDF_docstring(description::String, - `concrete_jac`: Specifies whether a Jacobian should be constructed. Defaults to `nothing`, which means it will be chosen true/false depending on circumstances of the solver, such as whether a Krylov subspace method is used for `linsolve`. - - `diff_type`: The type of differentiation used in FiniteDiff.jl if `autodiff=false`. - Defaults to `Val{:forward}`, with alternatives of `Val{:central}` and - `Val{:complex}`. - `linsolve`: Any [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl) compatible linear solver. For example, to use [KLU.jl](https://github.com/JuliaSparse/KLU.jl), specify `$name(linsolve = KLUFactorization()`). diff --git a/lib/OrdinaryDiffEqCore/src/doc_utils.jl b/lib/OrdinaryDiffEqCore/src/doc_utils.jl index 0fddff67a5..44872a3585 100644 --- a/lib/OrdinaryDiffEqCore/src/doc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/doc_utils.jl @@ -91,12 +91,14 @@ function differentiation_rk_docstring(description::String, """ * extra_keyword_default keyword_default_description = """ - - `chunk_size`: The chunk size used with ForwardDiff.jl. Defaults to `Val{0}()` - and thus uses the internal ForwardDiff.jl algorithm for the choice. - - `autodiff`: Specifies whether to use automatic differentiation via + - `autodiff`: Uses [ADTypes.jl](https://sciml.github.io/ADTypes.jl/stable/) + to specify whether to use automatic differentiation via [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) or finite - differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). - Defaults to `Val{true}()` for automatic differentiation. + differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). + Defaults to `AutoForwardDiff()` for automatic differentiation, which by default uses + `chunksize = 0`, and thus uses the internal ForwardDiff.jl algorithm for the choice. + To use `FiniteDiff.jl`, the `AutoFiniteDiff()` ADType can be used, which has a keyword argument + `fdtype` with default value `Val{:forward}()`, and alternatives `Val{:central}()` and `Val{:complex}()`. - `standardtag`: Specifies whether to use package-specific tags instead of the ForwardDiff default function-specific tags. For more information, see [this blog post](https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/). @@ -104,9 +106,6 @@ function differentiation_rk_docstring(description::String, - `concrete_jac`: Specifies whether a Jacobian should be constructed. Defaults to `nothing`, which means it will be chosen true/false depending on circumstances of the solver, such as whether a Krylov subspace method is used for `linsolve`. - - `diff_type`: The type of differentiation used in FiniteDiff.jl if `autodiff=false`. - Defaults to `Val{:forward}`, with alternatives of `Val{:central}` and - `Val{:complex}`. - `linsolve`: Any [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl) compatible linear solver. For example, to use [KLU.jl](https://github.com/JuliaSparse/KLU.jl), specify `$name(linsolve = KLUFactorization()`). diff --git a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl index 6ba64ee4ab..bf268b58a4 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/OrdinaryDiffEqRosenbrock.jl @@ -57,22 +57,21 @@ function rosenbrock_wolfbrandt_docstring(description::String, """ * extra_keyword_default keyword_default_description = """ - - `chunk_size`: The chunk size used with ForwardDiff.jl. Defaults to `Val{0}()` - and thus uses the internal ForwardDiff.jl algorithm for the choice. - `standardtag`: Specifies whether to use package-specific tags instead of the ForwardDiff default function-specific tags. For more information, see [this blog post](https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/). Defaults to `Val{true}()`. - - `autodiff`: Specifies whether to use automatic differentiation via + - `autodiff`: Uses [ADTypes.jl](https://sciml.github.io/ADTypes.jl/stable/) + to specify whether to use automatic differentiation via [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) or finite - differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). - Defaults to `Val{true}()` for automatic differentiation. + differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). + Defaults to `AutoForwardDiff()` for automatic differentiation, which by default uses + `chunksize = 0`, and thus uses the internal ForwardDiff.jl algorithm for the choice. + To use `FiniteDiff.jl`, the `AutoFiniteDiff()` ADType can be used, which has a keyword argument + `fdtype` with default value `Val{:forward}()`, and alternatives `Val{:central}()` and `Val{:complex}()`. - `concrete_jac`: Specifies whether a Jacobian should be constructed. Defaults to `nothing`, which means it will be chosen true/false depending on circumstances of the solver, such as whether a Krylov subspace method is used for `linsolve`. - - `diff_type`: The type of differentiation used in FiniteDiff.jl if `autodiff=false`. - Defaults to `Val{:forward}`, with alternatives of `Val{:central}` and - `Val{:complex}`. - `linsolve`: Any [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl) compatible linear solver. For example, to use [KLU.jl](https://github.com/JuliaSparse/KLU.jl), specify `$name(linsolve = KLUFactorization()`). @@ -131,22 +130,21 @@ function rosenbrock_docstring(description::String, extra_keyword_default = "", with_step_limiter = false) keyword_default = """ - - `chunk_size`: The chunk size used with ForwardDiff.jl. Defaults to `Val{0}()` - and thus uses the internal ForwardDiff.jl algorithm for the choice. - `standardtag`: Specifies whether to use package-specific tags instead of the ForwardDiff default function-specific tags. For more information, see [this blog post](https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/). Defaults to `Val{true}()`. - - `autodiff`: Specifies whether to use automatic differentiation via + - `autodiff`: Uses [ADTypes.jl](https://sciml.github.io/ADTypes.jl/stable/) + to specify whether to use automatic differentiation via [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) or finite - differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). - Defaults to `Val{true}()` for automatic differentiation. + differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). + Defaults to `AutoForwardDiff()` for automatic differentiation, which by default uses + `chunksize = 0`, and thus uses the internal ForwardDiff.jl algorithm for the choice. + To use `FiniteDiff.jl`, the `AutoFiniteDiff()` ADType can be used, which has a keyword argument + `fdtype` with default value `Val{:forward}()`, and alternatives `Val{:central}()` and `Val{:complex}()`. - `concrete_jac`: Specifies whether a Jacobian should be constructed. Defaults to `nothing`, which means it will be chosen true/false depending on circumstances of the solver, such as whether a Krylov subspace method is used for `linsolve`. - - `diff_type`: The type of differentiation used in FiniteDiff.jl if `autodiff=false`. - Defaults to `Val{:forward}`, with alternatives of `Val{:central}` and - `Val{:complex}`. - `linsolve`: Any [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl) compatible linear solver. For example, to use [KLU.jl](https://github.com/JuliaSparse/KLU.jl), specify `$name(linsolve = KLUFactorization()`). diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index f0bdfe3fbb..7292ba43a4 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -15,12 +15,14 @@ function SDIRK_docstring(description::String, """ * extra_keyword_default keyword_default_description = """ - - `chunk_size`: The chunk size used with ForwardDiff.jl. Defaults to `Val{0}()` - and thus uses the internal ForwardDiff.jl algorithm for the choice. - - `autodiff`: Specifies whether to use automatic differentiation via + - `autodiff`: Uses [ADTypes.jl](https://sciml.github.io/ADTypes.jl/stable/) + to specify whether to use automatic differentiation via [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) or finite - differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). - Defaults to `Val{true}()` for automatic differentiation. + differencing via [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl). + Defaults to `AutoForwardDiff()` for automatic differentiation, which by default uses + `chunksize = 0`, and thus uses the internal ForwardDiff.jl algorithm for the choice. + To use `FiniteDiff.jl`, the `AutoFiniteDiff()` ADType can be used, which has a keyword argument + `fdtype` with default value `Val{:forward}()`, and alternatives `Val{:central}()` and `Val{:complex}()`. - `standardtag`: Specifies whether to use package-specific tags instead of the ForwardDiff default function-specific tags. For more information, see [this blog post](https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/). @@ -28,9 +30,6 @@ function SDIRK_docstring(description::String, - `concrete_jac`: Specifies whether a Jacobian should be constructed. Defaults to `nothing`, which means it will be chosen true/false depending on circumstances of the solver, such as whether a Krylov subspace method is used for `linsolve`. - - `diff_type`: The type of differentiation used in FiniteDiff.jl if `autodiff=false`. - Defaults to `Val{:forward}`, with alternatives of `Val{:central}` and - `Val{:complex}`. - `linsolve`: Any [LinearSolve.jl](https://github.com/SciML/LinearSolve.jl) compatible linear solver. For example, to use [KLU.jl](https://github.com/JuliaSparse/KLU.jl), specify `$name(linsolve = KLUFactorization()`). From fd0646dc32e955d9ce1e52a33c301831e9da9002 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 25 Oct 2024 11:31:28 -0400 Subject: [PATCH 111/203] alias_u0 implementation --- lib/OrdinaryDiffEqCore/src/solve.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 42fd07a5bf..94f539794d 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -71,6 +71,7 @@ function DiffEqBase.__init( initialize_integrator = true, alias_u0 = false, alias_du0 = false, + alias = ODEAliases(), initializealg = DefaultInit(), kwargs...) where {recompile_flag} if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm @@ -162,8 +163,11 @@ function DiffEqBase.__init( p = prob.p # Get the control variables + if isnothing(alias.alias_u0) + alias = ODEAliases(alias_u0) + end - if alias_u0 + if alias.alias_u0 u = prob.u0 else u = recursivecopy(prob.u0) From 5cf41b06a5a400e6a8155acb57d8735df7ed9aff Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 25 Oct 2024 11:34:00 -0400 Subject: [PATCH 112/203] add comment --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 94f539794d..6bd4595eba 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -163,6 +163,8 @@ function DiffEqBase.__init( p = prob.p # Get the control variables + # If alias kwarg is just default, use alias_u0, which is false by default, or is set by a kwarg to solve + # If alias_u0 is not nothing, use the alias_u0 provided by the user if isnothing(alias.alias_u0) alias = ODEAliases(alias_u0) end From 09515402b14074743a56d40af3868afb09bfd7a5 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 25 Oct 2024 12:51:47 -0400 Subject: [PATCH 113/203] add error for non ODEAliases alias --- lib/OrdinaryDiffEqCore/src/solve.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 6bd4595eba..63d743a8c9 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -120,6 +120,10 @@ function DiffEqBase.__init( @warn("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.") end + if !(alias isa ODEAliases) + error("Keyword argument `alias` must be a `ODEAliases`. ") + end + progress && @logmsg(LogLevel(-1), progress_name, _id=progress_id, progress=0) tType = eltype(prob.tspan) From 9666052ea955df722dae69f2aa8ac48a8d8f5f6f Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 25 Oct 2024 12:55:01 -0400 Subject: [PATCH 114/203] no space --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 63d743a8c9..12f8e51dd6 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -121,7 +121,7 @@ function DiffEqBase.__init( end if !(alias isa ODEAliases) - error("Keyword argument `alias` must be a `ODEAliases`. ") + error("Keyword argument `alias` must be a `ODEAliases`.") end progress && @logmsg(LogLevel(-1), progress_name, _id=progress_id, progress=0) From c5b2b9e56c46c3bf0466d2a30612e9a0dd1350cc Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 28 Oct 2024 15:59:07 -0400 Subject: [PATCH 115/203] use ODEAliasSpecifier --- lib/OrdinaryDiffEqCore/src/solve.jl | 48 ++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 12f8e51dd6..43adda1568 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -69,9 +69,7 @@ function DiffEqBase.__init( userdata = nothing, allow_extrapolation = alg_extrapolates(alg), initialize_integrator = true, - alias_u0 = false, - alias_du0 = false, - alias = ODEAliases(), + alias = ODEAliasSpecifier(), initializealg = DefaultInit(), kwargs...) where {recompile_flag} if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm @@ -120,10 +118,6 @@ function DiffEqBase.__init( @warn("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.") end - if !(alias isa ODEAliases) - error("Keyword argument `alias` must be a `ODEAliases`.") - end - progress && @logmsg(LogLevel(-1), progress_name, _id=progress_id, progress=0) tType = eltype(prob.tspan) @@ -166,21 +160,47 @@ function DiffEqBase.__init( f = prob.f p = prob.p - # Get the control variables - # If alias kwarg is just default, use alias_u0, which is false by default, or is set by a kwarg to solve - # If alias_u0 is not nothing, use the alias_u0 provided by the user - if isnothing(alias.alias_u0) - alias = ODEAliases(alias_u0) + use_old_kwargs = haskey(kwargs,:alias_u0) || haskey(kwargs,:alias_du0) + + if use_old_kwargs + if haskey(kwargs, :alias_u0) + Base.depwarn("alias_u0 keyword argument is deprecated, to set `alias_u0`, + please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))", :alias_u0) + old_alias_u0 = values(kwargs).alias_u0 + else + old_alias_u0 = false + + end + + if haskey(kwargs, :alias_du0) + Base.depwarn("alias_du0 keyword argument is deprecated, to set `alias_du0`, + please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))", :alias_du0) + old_alias_du0 = values(kwargs).alias_du0 + else + old_alias_du0 = false + end + + aliases = ODEAliasSpecifier(alias_u0 = old_alias_u0, alias_du0 = old_alias_du0) + + else + # If alias isa Bool, all fields of ODEAliases set to alias + if alias isa Bool + aliases = ODEAliasSpecifier(alias = alias) + elseif alias isa ODEAliasSpecifier + aliases = alias + else + error("Keyword argument `alias` must be a `Bool` or `ODEAliasSpecifier`.") + end end - if alias.alias_u0 + if aliases.alias_u0 u = prob.u0 else u = recursivecopy(prob.u0) end if _alg isa DAEAlgorithm - if alias_du0 + if aliases.alias_du0 du = prob.du0 else du = recursivecopy(prob.du0) From bb9b54dfeee2fa37ebb97237a3f98a523cbe0e3e Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 29 Oct 2024 14:57:33 -0400 Subject: [PATCH 116/203] fix aliasing --- lib/OrdinaryDiffEqCore/src/solve.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 43adda1568..79a26ce79f 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -163,33 +163,32 @@ function DiffEqBase.__init( use_old_kwargs = haskey(kwargs,:alias_u0) || haskey(kwargs,:alias_du0) if use_old_kwargs + aliases = ODEAliasSpecifier() if haskey(kwargs, :alias_u0) Base.depwarn("alias_u0 keyword argument is deprecated, to set `alias_u0`, please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))", :alias_u0) - old_alias_u0 = values(kwargs).alias_u0 + @reset aliases.alias_u0 = values(kwargs).alias_u0 else - old_alias_u0 = false + @reset aliases.alias_u0 = false end if haskey(kwargs, :alias_du0) Base.depwarn("alias_du0 keyword argument is deprecated, to set `alias_du0`, please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))", :alias_du0) - old_alias_du0 = values(kwargs).alias_du0 + @reset aliases.alias_du0 = values(kwargs).alias_du0 else - old_alias_du0 = false + @reset aliases.alias_du0 = false end - aliases = ODEAliasSpecifier(alias_u0 = old_alias_u0, alias_du0 = old_alias_du0) + aliases else # If alias isa Bool, all fields of ODEAliases set to alias if alias isa Bool aliases = ODEAliasSpecifier(alias = alias) - elseif alias isa ODEAliasSpecifier + elseif alias isa ODEAliasSpecifier || isnothing(alias) aliases = alias - else - error("Keyword argument `alias` must be a `Bool` or `ODEAliasSpecifier`.") end end From 75449c2c36a496457ceeea40ef363e95c1c9df4e Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 30 Oct 2024 11:13:27 -0400 Subject: [PATCH 117/203] change default for ODEAliasSpecifier in init --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 79a26ce79f..333115f919 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -69,7 +69,7 @@ function DiffEqBase.__init( userdata = nothing, allow_extrapolation = alg_extrapolates(alg), initialize_integrator = true, - alias = ODEAliasSpecifier(), + alias = ODEAliasSpecifier(alias_u0 = false, alias_du0 = false), initializealg = DefaultInit(), kwargs...) where {recompile_flag} if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm From 0454f1c65aaa7127a417240cdca31543d2fa04a0 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 10:49:36 -0500 Subject: [PATCH 118/203] add use of alias_f, alias_p kwargs for ODiffEq --- lib/OrdinaryDiffEqCore/src/solve.jl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 333115f919..80c2d4f2f3 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -157,8 +157,18 @@ function DiffEqBase.__init( else _alg = alg end - f = prob.f - p = prob.p + + if aliases.alias_f + f = prob.f + else + f = deepcopy(prob.f) + end + + if aliases.alias_p + p = prob.p + else + p = recursivecopy(prob.p) + end use_old_kwargs = haskey(kwargs,:alias_u0) || haskey(kwargs,:alias_du0) From bdaa14143d449d52b0375867dd68aeb998cec001 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Tue, 12 Nov 2024 11:00:23 -0500 Subject: [PATCH 119/203] fix defaults --- lib/OrdinaryDiffEqCore/src/solve.jl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 80c2d4f2f3..c89893c38b 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -69,7 +69,7 @@ function DiffEqBase.__init( userdata = nothing, allow_extrapolation = alg_extrapolates(alg), initialize_integrator = true, - alias = ODEAliasSpecifier(alias_u0 = false, alias_du0 = false), + alias = ODEAliasSpecifier(alias_u0 = false, alias_du0 = false, alias_p = true, alias_f = true), initializealg = DefaultInit(), kwargs...) where {recompile_flag} if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm @@ -158,18 +158,6 @@ function DiffEqBase.__init( _alg = alg end - if aliases.alias_f - f = prob.f - else - f = deepcopy(prob.f) - end - - if aliases.alias_p - p = prob.p - else - p = recursivecopy(prob.p) - end - use_old_kwargs = haskey(kwargs,:alias_u0) || haskey(kwargs,:alias_du0) if use_old_kwargs @@ -202,6 +190,18 @@ function DiffEqBase.__init( end end + if aliases.alias_f || isnothing(aliases.alias_f) + f = prob.f + else + f = deepcopy(prob.f) + end + + if aliases.alias_p || isnothing(aliases.alias_f) + p = prob.p + else + p = recursivecopy(prob.p) + end + if aliases.alias_u0 u = prob.u0 else From 4780e72933baadd43df9bc68470ded083a234f74 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Wed, 11 Dec 2024 14:42:02 -0500 Subject: [PATCH 120/203] import ODEAliasSpecifier from SciMLBase --- lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl index fbfcd66dd3..008b1e3745 100644 --- a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl +++ b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl @@ -60,7 +60,7 @@ using DiffEqBase: check_error!, @def, _vec, _reshape using FastBroadcast: @.., True, False -using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val +using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val, ODEAliasSpecifier import SciMLBase: AbstractNonlinearProblem, alg_order From 4d8ae15dad0d61da85736f4198fea72033eb5ee8 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 12 Dec 2024 13:15:47 -0500 Subject: [PATCH 121/203] fix f vs p --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index c89893c38b..52d52d5f9a 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -196,7 +196,7 @@ function DiffEqBase.__init( f = deepcopy(prob.f) end - if aliases.alias_p || isnothing(aliases.alias_f) + if aliases.alias_p || isnothing(aliases.alias_p) p = prob.p else p = recursivecopy(prob.p) From cef2d2957b711afae752ff3f445cbfdaf8752187 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 12 Dec 2024 13:15:56 -0500 Subject: [PATCH 122/203] account for defaults --- lib/OrdinaryDiffEqCore/src/solve.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 52d52d5f9a..d6810cad97 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -185,24 +185,24 @@ function DiffEqBase.__init( # If alias isa Bool, all fields of ODEAliases set to alias if alias isa Bool aliases = ODEAliasSpecifier(alias = alias) - elseif alias isa ODEAliasSpecifier || isnothing(alias) + elseif isnothing(alias) || alias isa ODEAliasSpecifier aliases = alias end end - if aliases.alias_f || isnothing(aliases.alias_f) + if isnothing(aliases.alias_f) || aliases.alias_f f = prob.f else f = deepcopy(prob.f) end - if aliases.alias_p || isnothing(aliases.alias_p) + if isnothing(aliases.alias_p) || aliases.alias_p p = prob.p else p = recursivecopy(prob.p) end - if aliases.alias_u0 + if !isnothing(aliases.alias_u0) && aliases.alias_u0 u = prob.u0 else u = recursivecopy(prob.u0) From d2d5f61a9b9162acbb886a57b5038d0cff8ee4c9 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 12 Dec 2024 14:05:05 -0500 Subject: [PATCH 123/203] tstop aliasing --- lib/OrdinaryDiffEqCore/src/solve.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index d6810cad97..a6ad0933a2 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -281,6 +281,12 @@ function DiffEqBase.__init( resType = typeof(res_prototype) end + if isnothing(aliases.alias_tstops) || aliases.alias_tstops + tstops = tstops + else + tstops = deepcopy(tstops) + end + if tstops isa AbstractArray || tstops isa Tuple || tstops isa Number _tstops = nothing else From 5ed41ce579e9a299ecf776c295a5bc3702abc846 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Wed, 4 Dec 2024 00:40:17 +0100 Subject: [PATCH 124/203] Added threading to ABM algorithms using @.. 1. in *_perform_step.jl in functions using @.. in unpacking of the "cache" object add a "thread" variable 2. in *_caches.jl for the cache types affected (determined in 1.) - add parametric type Thread - and a field thread::Thread - in the alg_cache function, add 'alg.thread' as argument to the cache type constructor 3. in *_algorithms.jl, for the alg type affected (determined in 2.) - add parametric type Thread - add field thread::Thread - add outer constructor taking a thread argument with default value False(), that builds the respective algorithm object forwarding the thread parameter to it. --- .../src/adams_bashforth_moulton_caches.jl | 67 ++++--- .../adams_bashforth_moulton_perform_step.jl | 165 +++++++++--------- .../src/algorithms.jl | 93 ++++++++-- 3 files changed, 207 insertions(+), 118 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl index d417f9cdad..283b4b6b18 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_caches.jl @@ -4,7 +4,7 @@ get_fsalfirstlast(cache::ABMMutableCache, u) = (cache.fsalfirst, cache.k) function get_fsalfirstlast(cache::ABMVariableCoefficientMutableCache, u) (cache.fsalfirst, cache.k4) end -@cache mutable struct AB3Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct AB3Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -14,6 +14,7 @@ end k::rateType tmp::uType step::Int + thread::Thread end @cache mutable struct AB3ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -32,7 +33,7 @@ function alg_cache(alg::AB3, u, rate_prototype, ::Type{uEltypeNoUnits}, ralk2 = zero(rate_prototype) k = zero(rate_prototype) tmp = zero(u) - AB3Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, 1) + AB3Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, 1, alg.thread) end function alg_cache(alg::AB3, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -44,7 +45,7 @@ function alg_cache(alg::AB3, u, rate_prototype, ::Type{uEltypeNoUnits}, AB3ConstantCache(k2, k3, 1) end -@cache mutable struct ABM32Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct ABM32Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -54,6 +55,7 @@ end k::rateType tmp::uType step::Int + thread::Thread end @cache mutable struct ABM32ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -72,7 +74,7 @@ function alg_cache(alg::ABM32, u, rate_prototype, ::Type{uEltypeNoUnits}, ralk2 = zero(rate_prototype) k = zero(rate_prototype) tmp = zero(u) - ABM32Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, 1) + ABM32Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, 1, alg.thread) end function alg_cache(alg::ABM32, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -84,7 +86,7 @@ function alg_cache(alg::ABM32, u, rate_prototype, ::Type{uEltypeNoUnits}, ABM32ConstantCache(k2, k3, 1) end -@cache mutable struct AB4Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct AB4Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -98,6 +100,7 @@ end t3::rateType t4::rateType step::Int + thread::Thread end @cache mutable struct AB4ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -121,7 +124,7 @@ function alg_cache(alg::AB4, u, rate_prototype, ::Type{uEltypeNoUnits}, t2 = zero(rate_prototype) t3 = zero(rate_prototype) t4 = zero(rate_prototype) - AB4Cache(u, uprev, fsalfirst, k2, k3, k4, ralk2, k, tmp, t2, t3, t4, 1) + AB4Cache(u, uprev, fsalfirst, k2, k3, k4, ralk2, k, tmp, t2, t3, t4, 1, alg.thread) end function alg_cache(alg::AB4, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -134,7 +137,7 @@ function alg_cache(alg::AB4, u, rate_prototype, ::Type{uEltypeNoUnits}, AB4ConstantCache(k2, k3, k4, 1) end -@cache mutable struct ABM43Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct ABM43Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -151,6 +154,7 @@ end t6::rateType t7::rateType step::Int + thread::Thread end @cache mutable struct ABM43ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -177,7 +181,8 @@ function alg_cache(alg::ABM43, u, rate_prototype, ::Type{uEltypeNoUnits}, t5 = zero(rate_prototype) t6 = zero(rate_prototype) t7 = zero(rate_prototype) - ABM43Cache(u, uprev, fsalfirst, k2, k3, k4, ralk2, k, tmp, t2, t3, t4, t5, t6, t7, 1) + ABM43Cache(u, uprev, fsalfirst, k2, k3, k4, ralk2, k, + tmp, t2, t3, t4, t5, t6, t7, 1, alg.thread) end function alg_cache(alg::ABM43, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -190,7 +195,7 @@ function alg_cache(alg::ABM43, u, rate_prototype, ::Type{uEltypeNoUnits}, ABM43ConstantCache(k2, k3, k4, 1) end -@cache mutable struct AB5Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct AB5Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -204,6 +209,7 @@ end t3::rateType t4::rateType step::Int + thread::Thread end @cache mutable struct AB5ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -228,7 +234,7 @@ function alg_cache(alg::AB5, u, rate_prototype, ::Type{uEltypeNoUnits}, t2 = zero(rate_prototype) t3 = zero(rate_prototype) t4 = zero(rate_prototype) - AB5Cache(u, uprev, fsalfirst, k2, k3, k4, k5, k, tmp, t2, t3, t4, 1) + AB5Cache(u, uprev, fsalfirst, k2, k3, k4, k5, k, tmp, t2, t3, t4, 1, alg.thread) end function alg_cache(alg::AB5, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -242,7 +248,7 @@ function alg_cache(alg::AB5, u, rate_prototype, ::Type{uEltypeNoUnits}, AB5ConstantCache(k2, k3, k4, k5, 1) end -@cache mutable struct ABM54Cache{uType, rateType} <: ABMMutableCache +@cache mutable struct ABM54Cache{uType, rateType, Thread} <: ABMMutableCache u::uType uprev::uType fsalfirst::rateType @@ -260,6 +266,7 @@ end t7::rateType t8::rateType step::Int + thread::Thread end @cache mutable struct ABM54ConstantCache{rateType} <: OrdinaryDiffEqConstantCache @@ -288,7 +295,8 @@ function alg_cache(alg::ABM54, u, rate_prototype, ::Type{uEltypeNoUnits}, t6 = zero(rate_prototype) t7 = zero(rate_prototype) t8 = zero(rate_prototype) - ABM54Cache(u, uprev, fsalfirst, k2, k3, k4, k5, k, tmp, t2, t3, t4, t5, t6, t7, t8, 1) + ABM54Cache(u, uprev, fsalfirst, k2, k3, k4, k5, k, tmp, + t2, t3, t4, t5, t6, t7, t8, 1, alg.thread) end function alg_cache(alg::ABM54, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -317,7 +325,7 @@ end end @cache mutable struct VCAB3Cache{uType, rateType, TabType, bs3Type, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -337,6 +345,7 @@ end utilde::uType tab::TabType step::Int + thread::Thread end function alg_cache(alg::VCAB3, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -395,7 +404,7 @@ function alg_cache(alg::VCAB3, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCAB3Cache(u, uprev, fsalfirst, bs3cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕstar_n, β, - order, atmp, tmp, utilde, tab, 1) + order, atmp, tmp, utilde, tab, 1, alg.thread) end @cache mutable struct VCAB4ConstantCache{rk4constcache, tArrayType, rArrayType, cArrayType, @@ -413,7 +422,7 @@ end end @cache mutable struct VCAB4Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -432,6 +441,7 @@ end tmp::uType utilde::uType step::Int + thread::Thread end function alg_cache(alg::VCAB4, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -489,7 +499,7 @@ function alg_cache(alg::VCAB4, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCAB4Cache(u, uprev, fsalfirst, rk4cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕstar_n, β, - order, atmp, tmp, utilde, 1) + order, atmp, tmp, utilde, 1, alg.thread) end # VCAB5 @@ -509,7 +519,7 @@ end end @cache mutable struct VCAB5Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -528,6 +538,7 @@ end tmp::uType utilde::uType step::Int + thread::Thread end function alg_cache(alg::VCAB5, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -585,7 +596,7 @@ function alg_cache(alg::VCAB5, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCAB5Cache(u, uprev, fsalfirst, rk4cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕstar_n, β, - order, atmp, tmp, utilde, 1) + order, atmp, tmp, utilde, 1, alg.thread) end # VCABM3 @@ -607,7 +618,7 @@ end @cache mutable struct VCABM3Cache{ uType, rateType, TabType, bs3Type, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -628,6 +639,7 @@ end utilde::uType tab::TabType step::Int + thread::Thread end function alg_cache(alg::VCABM3, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -691,7 +703,7 @@ function alg_cache(alg::VCABM3, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCABM3Cache(u, uprev, fsalfirst, bs3cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, - ϕstar_n, β, order, atmp, tmp, utilde, tab, 1) + ϕstar_n, β, order, atmp, tmp, utilde, tab, 1, alg.thread) end # VCABM4 @@ -713,7 +725,7 @@ end end @cache mutable struct VCABM4Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -733,6 +745,7 @@ end tmp::uType utilde::uType step::Int + thread::Thread end function alg_cache(alg::VCABM4, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -796,7 +809,7 @@ function alg_cache(alg::VCABM4, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCABM4Cache(u, uprev, fsalfirst, rk4cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, - ϕstar_n, β, order, atmp, tmp, utilde, 1) + ϕstar_n, β, order, atmp, tmp, utilde, 1, alg.thread) end # VCABM5 @@ -818,7 +831,7 @@ end end @cache mutable struct VCABM5Cache{uType, rateType, rk4cacheType, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -838,6 +851,7 @@ end tmp::uType utilde::uType step::Int + thread::Thread end function alg_cache(alg::VCABM5, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -901,7 +915,7 @@ function alg_cache(alg::VCABM5, u, rate_prototype, ::Type{uEltypeNoUnits}, tmp = zero(u) utilde = zero(u) VCABM5Cache(u, uprev, fsalfirst, rk4cache, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, - ϕstar_n, β, order, atmp, tmp, utilde, 1) + ϕstar_n, β, order, atmp, tmp, utilde, 1, alg.thread) end # VCABM @@ -924,7 +938,7 @@ end end @cache mutable struct VCABMCache{uType, rateType, dtType, tArrayType, cArrayType, - uNoUnitsType, coefType, dtArrayType} <: + uNoUnitsType, coefType, dtArrayType, Thread} <: ABMVariableCoefficientMutableCache u::uType uprev::uType @@ -952,6 +966,7 @@ end atmpm2::uNoUnitsType atmpp1::uNoUnitsType step::Int + thread::Thread end function alg_cache(alg::VCABM, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -1023,5 +1038,5 @@ function alg_cache(alg::VCABM, u, rate_prototype, ::Type{uEltypeNoUnits}, VCABMCache( u, uprev, fsalfirst, k4, ϕstar_nm1, dts, c, g, ϕ_n, ϕ_np1, ϕstar_n, β, order, max_order, atmp, tmp, ξ, ξ0, utilde, utildem1, utildem2, utildep1, atmpm1, - atmpm2, atmpp1, 1) + atmpm2, atmpp1, 1, alg.thread) end diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl index 077fdfb4ec..5e160b2b02 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl @@ -68,7 +68,7 @@ end @muladd function perform_step!(integrator, cache::AB3Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, ralk2, k = cache + @unpack tmp, fsalfirst, k2, k3, ralk2, k, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -77,17 +77,17 @@ end if cache.step <= 2 cache.step += 1 ttmp = t + (2 / 3) * dt - @.. broadcast=false tmp=uprev + (2 / 3) * dt * k1 + @.. broadcast=false thread=thread tmp=uprev + (2 / 3) * dt * k1 f(ralk2, tmp, p, ttmp) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - @.. broadcast=false u=uprev + (dt / 4) * (k1 + 3 * ralk2) #Ralston Method + @.. broadcast=false thread=thread u=uprev + (dt / 4) * (k1 + 3 * ralk2) #Ralston Method if cnt == 1 cache.k3 .= k1 else cache.k2 .= k1 end else - @.. broadcast=false u=uprev + (dt / 12) * (23 * k1 - 16 * k2 + 5 * k3) + @.. broadcast=false thread=thread u=uprev + (dt / 12) * (23 * k1 - 16 * k2 + 5 * k3) cache.k2, cache.k3 = k3, k2 cache.k2 .= k1 end @@ -128,7 +128,7 @@ end @muladd function perform_step!(integrator, cache::ABM32Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, ralk2, k = cache + @unpack tmp, fsalfirst, k2, k3, ralk2, k, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -137,21 +137,21 @@ end if cache.step == 1 cache.step += 1 ttmp = t + (2 / 3) * dt - @.. broadcast=false tmp=uprev + (2 / 3) * dt * k1 + @.. broadcast=false thread=thread tmp=uprev + (2 / 3) * dt * k1 f(ralk2, tmp, p, ttmp) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - @.. broadcast=false u=uprev + (dt / 4) * (k1 + 3 * ralk2) #Ralston Method + @.. broadcast=false thread=thread u=uprev + (dt / 4) * (k1 + 3 * ralk2) #Ralston Method cache.k2 .= k1 else if cnt == 2 perform_step!(integrator, - AB3Cache(u, uprev, fsalfirst, copy(k2), k3, ralk2, k, tmp, cnt)) #Here passing copy of k2, otherwise it will change in AB3() + AB3Cache(u, uprev, fsalfirst, copy(k2), k3, ralk2, k, tmp, cnt, thread)) #Here passing copy of k2, otherwise it will change in AB3() else perform_step!(integrator, - AB3Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, cnt)) + AB3Cache(u, uprev, fsalfirst, k2, k3, ralk2, k, tmp, cnt, thread)) end k = integrator.fsallast - @.. broadcast=false u=uprev + (dt / 12) * (5 * k + 8 * k1 - k2) + @.. broadcast=false thread=thread u=uprev + (dt / 12) * (5 * k + 8 * k1 - k2) cache.k2, cache.k3 = k3, k2 cache.k2 .= k1 end @@ -198,7 +198,7 @@ end @muladd function perform_step!(integrator, cache::AB4Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, k4, ralk2, k, t2, t3, t4 = cache + @unpack tmp, fsalfirst, k2, k3, k4, ralk2, k, t2, t3, t4, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -208,14 +208,14 @@ end cache.step += 1 halfdt = dt / 2 ttmp = t + halfdt - @.. broadcast=false tmp=uprev + halfdt * k1 + @.. broadcast=false thread=thread tmp=uprev + halfdt * k1 f(t2, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + halfdt * t2 + @.. broadcast=false thread=thread tmp=uprev + halfdt * t2 f(t3, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + dt * t3 + @.. broadcast=false thread=thread tmp=uprev + dt * t3 f(t4, tmp, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 3) - @.. broadcast=false u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 + @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 if cnt == 1 cache.k4 .= k1 elseif cnt == 2 @@ -224,7 +224,9 @@ end cache.k2 .= k1 end else - @.. broadcast=false u=uprev + (dt / 24) * (55 * k1 - 59 * k2 + 37 * k3 - 9 * k4) + @.. broadcast=false thread=thread u=uprev + + (dt / 24) * + (55 * k1 - 59 * k2 + 37 * k3 - 9 * k4) cache.k4, cache.k3 = k3, k4 cache.k3 .= k2 cache.k2 .= k1 @@ -272,7 +274,7 @@ end @muladd function perform_step!(integrator, cache::ABM43Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, k4, ralk2, k, t2, t3, t4, t5, t6, t7 = cache + @unpack tmp, fsalfirst, k2, k3, k4, ralk2, k, t2, t3, t4, t5, t6, t7, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -282,14 +284,14 @@ end cache.step += 1 halfdt = dt / 2 ttmp = t + halfdt - @.. broadcast=false tmp=uprev + halfdt * k1 + @.. broadcast=false thread=thread tmp=uprev + halfdt * k1 f(t2, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + halfdt * t2 + @.. broadcast=false thread=thread tmp=uprev + halfdt * t2 f(t3, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + dt * t3 + @.. broadcast=false thread=thread tmp=uprev + dt * t3 f(t4, tmp, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 3) - @.. broadcast=false u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 + @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 if cnt == 1 cache.k3 .= k1 else @@ -301,9 +303,10 @@ end t4 .= k4 perform_step!(integrator, AB4Cache(u, uprev, fsalfirst, t2, t3, t4, ralk2, k, tmp, t5, t6, t7, - cnt)) + cnt,thread)) k = integrator.fsallast - @.. broadcast=false u=uprev + (dt / 24) * (9 * k + 19 * k1 - 5 * k2 + k3) + @.. broadcast=false thread=thread u=uprev + + (dt / 24) * (9 * k + 19 * k1 - 5 * k2 + k3) cache.k4, cache.k3 = k3, k4 cache.k3 .= k2 cache.k2 .= k1 @@ -354,7 +357,7 @@ end @muladd function perform_step!(integrator, cache::AB5Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, k4, k5, k, t2, t3, t4 = cache + @unpack tmp, fsalfirst, k2, k3, k4, k5, k, t2, t3, t4, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -364,14 +367,14 @@ end cache.step += 1 halfdt = dt / 2 ttmp = t + halfdt - @.. broadcast=false tmp=uprev + halfdt * k1 + @.. broadcast=false thread=thread tmp=uprev + halfdt * k1 f(t2, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + halfdt * t2 + @.. broadcast=false thread=thread tmp=uprev + halfdt * t2 f(t3, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + dt * t3 + @.. broadcast=false thread=thread tmp=uprev + dt * t3 f(t4, tmp, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - @.. broadcast=false u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 + @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 if cnt == 1 cache.k5 .= k1 elseif cnt == 2 @@ -382,9 +385,10 @@ end cache.k2 .= k1 end else - @.. broadcast=false u=uprev + - (dt / 720) * - (1901 * k1 - 2774 * k2 + 2616 * k3 - 1274 * k4 + 251 * k5) + @.. broadcast=false thread=thread u=uprev + + (dt / 720) * + (1901 * k1 - 2774 * k2 + 2616 * k3 - 1274 * k4 + + 251 * k5) cache.k5, cache.k4 = k4, k5 cache.k4 .= k3 cache.k3 .= k2 @@ -436,7 +440,7 @@ end @muladd function perform_step!(integrator, cache::ABM54Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack tmp, fsalfirst, k2, k3, k4, k5, k, t2, t3, t4, t5, t6, t7, t8 = cache + @unpack tmp, fsalfirst, k2, k3, k4, k5, k, t2, t3, t4, t5, t6, t7, t8, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -446,13 +450,13 @@ end cache.step += 1 halfdt = dt / 2 ttmp = t + halfdt - @.. broadcast=false tmp=uprev + halfdt * k1 + @.. broadcast=false thread=thread tmp=uprev + halfdt * k1 f(t2, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + halfdt * t2 + @.. broadcast=false thread=thread tmp=uprev + halfdt * t2 f(t3, tmp, p, ttmp) - @.. broadcast=false tmp=uprev + dt * t3 + @.. broadcast=false thread=thread tmp=uprev + dt * t3 f(t4, tmp, p, t + dt) - @.. broadcast=false u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 + @.. broadcast=false thread=thread u=uprev + (dt / 6) * (2 * (t2 + t3) + (k1 + t4)) #RK4 OrdinaryDiffEqCore.increment_nf!(integrator.stats, 3) if cnt == 1 cache.k4 .= k1 @@ -468,11 +472,12 @@ end t5 .= k5 perform_step!(integrator, AB5Cache(u, uprev, fsalfirst, t2, t3, t4, t5, k, tmp, t6, t7, t8, - cnt)) + cnt, thread)) k = integrator.fsallast - @.. broadcast=false u=uprev + - (dt / 720) * - (251 * k + 646 * k1 - 264 * k2 + 106 * k3 - 19 * k4) + @.. broadcast=false thread=thread u=uprev + + (dt / 720) * + (251 * k + 646 * k1 - 264 * k2 + 106 * k3 - + 19 * k4) cache.k5, cache.k4 = k4, k5 cache.k4 .= k3 cache.k3 .= k2 @@ -561,7 +566,7 @@ end @muladd function perform_step!(integrator, cache::VCAB3Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕstar_n, ϕstar_nm1, order, atmp, utilde, bs3cache = cache + @unpack k4, dts, g, ϕstar_n, ϕstar_nm1, order, atmp, utilde, bs3cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -587,12 +592,12 @@ end integrator.fsallast .= k4 else g_coefs!(cache, k) - @.. broadcast=false u=uprev + @.. broadcast=false thread=thread u=uprev for i in 1:k - @.. broadcast=false u+=g[i] * ϕstar_n[i] + @.. broadcast=false thread=thread u+=g[i] * ϕstar_n[i] end if integrator.opts.adaptive - @.. broadcast=false utilde=g[k] * ϕstar_n[k] # Using lower order AB from subset of coefficients + @.. broadcast=false thread=thread utilde=g[k] * ϕstar_n[k] # Using lower order AB from subset of coefficients calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -694,7 +699,7 @@ end @muladd function perform_step!(integrator, cache::VCAB4Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕ_n, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache = cache + @unpack k4, dts, g, ϕ_n, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -726,12 +731,12 @@ end integrator.fsallast .= rk4cache.k else g_coefs!(cache, k) - @.. broadcast=false u=uprev + @.. broadcast=false thread=thread u=uprev for i in 1:k - @.. broadcast=false u+=g[i] * ϕstar_n[i] + @.. broadcast=false thread=thread u+=g[i] * ϕstar_n[i] end if integrator.opts.adaptive - @.. broadcast=false utilde=g[k] * ϕstar_n[k] + @.. broadcast=false thread=thread utilde=g[k] * ϕstar_n[k] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -842,7 +847,7 @@ end @muladd function perform_step!(integrator, cache::VCAB5Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕ_n, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache = cache + @unpack k4, dts, g, ϕ_n, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -881,12 +886,12 @@ end integrator.fsallast .= rk4cache.k else g_coefs!(cache, k) - @.. broadcast=false u=uprev + @.. broadcast=false thread=thread u=uprev for i in 1:k - @.. broadcast=false u+=g[i] * ϕstar_n[i] + @.. broadcast=false thread=thread u+=g[i] * ϕstar_n[i] end if integrator.opts.adaptive - @.. broadcast=false utilde=g[k] * ϕstar_n[k] + @.. broadcast=false thread=thread utilde=g[k] * ϕstar_n[k] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -988,7 +993,7 @@ end @muladd function perform_step!(integrator, cache::VCABM3Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕstar_n, ϕ_np1, ϕstar_nm1, order, atmp, utilde, bs3cache = cache + @unpack k4, dts, g, ϕstar_n, ϕ_np1, ϕstar_nm1, order, atmp, utilde, bs3cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -1014,16 +1019,16 @@ end integrator.fsallast .= k4 else g_coefs!(cache, k + 1) - @.. broadcast=false u=uprev + @.. broadcast=false thread=thread u=uprev for i in 1:(k - 1) - @.. broadcast=false u+=g[i] * ϕstar_n[i] + @.. broadcast=false thread=thread u+=g[i] * ϕstar_n[i] end f(k4, u, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) ϕ_np1!(cache, k4, k + 1) - @.. broadcast=false u+=g[end - 1] * ϕ_np1[end - 1] + @.. broadcast=false thread=thread u+=g[end - 1] * ϕ_np1[end - 1] if integrator.opts.adaptive - @.. broadcast=false utilde=(g[end] - g[end - 1]) * ϕ_np1[end] + @.. broadcast=false thread=thread utilde=(g[end] - g[end - 1]) * ϕ_np1[end] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -1131,7 +1136,7 @@ end @muladd function perform_step!(integrator, cache::VCABM4Cache, repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕstar_n, ϕ_np1, ϕstar_nm1, order, atmp, utilde, rk4cache = cache + @unpack k4, dts, g, ϕstar_n, ϕ_np1, ϕstar_nm1, order, atmp, utilde, rk4cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -1163,16 +1168,16 @@ end integrator.fsallast .= rk4cache.k else g_coefs!(cache, k + 1) - @.. broadcast=false u=uprev + @.. broadcast=false thread=thread u=uprev for i in 1:(k - 1) - @.. broadcast=false u+=g[i] * ϕstar_n[i] + @.. broadcast=false thread=thread u+=g[i] * ϕstar_n[i] end f(k4, u, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) ϕ_np1!(cache, k4, k + 1) - @.. broadcast=false u+=g[end - 1] * ϕ_np1[end - 1] + @.. broadcast=false thread=thread u+=g[end - 1] * ϕ_np1[end - 1] if integrator.opts.adaptive - @.. broadcast=false utilde=(g[end] - g[end - 1]) * ϕ_np1[end] + @.. broadcast=false thread=thread utilde=(g[end] - g[end - 1]) * ϕ_np1[end] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -1288,7 +1293,7 @@ end @muladd function perform_step!(integrator, cache::VCABM5Cache, repeat_step = false) @inbounds begin @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕ_n, ϕ_np1, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache = cache + @unpack k4, dts, g, ϕ_n, ϕ_np1, ϕstar_n, ϕstar_nm1, order, atmp, utilde, rk4cache, thread = cache k1 = integrator.fsalfirst if integrator.u_modified cache.step = 1 @@ -1327,16 +1332,16 @@ end integrator.fsallast .= rk4cache.k else g_coefs!(cache, 6) - @.. broadcast=false u=muladd(g[1], ϕstar_n[1], uprev) - @.. broadcast=false u=muladd(g[2], ϕstar_n[2], u) - @.. broadcast=false u=muladd(g[3], ϕstar_n[3], u) - @.. broadcast=false u=muladd(g[4], ϕstar_n[4], u) + @.. broadcast=false thread=thread u=muladd(g[1], ϕstar_n[1], uprev) + @.. broadcast=false thread=thread u=muladd(g[2], ϕstar_n[2], u) + @.. broadcast=false thread=thread u=muladd(g[3], ϕstar_n[3], u) + @.. broadcast=false thread=thread u=muladd(g[4], ϕstar_n[4], u) f(k4, u, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) ϕ_np1!(cache, k4, 6) - @.. broadcast=false u=muladd(g[6 - 1], ϕ_np1[6 - 1], u) + @.. broadcast=false thread=thread u=muladd(g[6 - 1], ϕ_np1[6 - 1], u) if integrator.opts.adaptive - @.. broadcast=false utilde=(g[6] - g[6 - 1]) * ϕ_np1[end] + @.. broadcast=false thread=thread utilde=(g[6] - g[6 - 1]) * ϕ_np1[end] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) @@ -1464,7 +1469,7 @@ end @muladd function perform_step!(integrator, cache::VCABMCache, repeat_step = false) @inbounds begin @unpack t, dt, uprev, u, f, p = integrator - @unpack k4, dts, g, ϕ_n, ϕ_np1, ϕstar_n, ϕstar_nm1, order, max_order, utilde, utildem2, utildem1, utildep1, atmp, atmpm1, atmpm2, atmpp1 = cache + @unpack k4, dts, g, ϕ_n, ϕ_np1, ϕstar_n, ϕstar_nm1, order, max_order, utilde, utildem2, utildem1, utildep1, atmp, atmpm1, atmpm2, atmpp1, thread = cache k1 = integrator.fsalfirst step = integrator.iter k = order @@ -1476,16 +1481,16 @@ end ϕ_and_ϕstar!(cache, k1, k) g_coefs!(cache, k + 1) # unroll the predictor once - @.. broadcast=false u=muladd(g[1], ϕstar_n[1], uprev) + @.. broadcast=false thread=thread u=muladd(g[1], ϕstar_n[1], uprev) for i in 2:(k - 1) - @.. broadcast=false u=muladd(g[i], ϕstar_n[i], u) + @.. broadcast=false thread=thread u=muladd(g[i], ϕstar_n[i], u) end f(k4, u, p, t + dt) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) ϕ_np1!(cache, k4, k + 1) - @.. broadcast=false u=muladd(g[k], ϕ_np1[k], u) + @.. broadcast=false thread=thread u=muladd(g[k], ϕ_np1[k], u) if integrator.opts.adaptive - @.. broadcast=false utilde=(g[k + 1] - g[k]) * ϕ_np1[k + 1] + @.. broadcast=false thread=thread utilde=(g[k + 1] - g[k]) * ϕ_np1[k + 1] calculate_residuals!(atmp, utilde, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) integrator.EEst = integrator.opts.internalnorm(atmp, t) @@ -1501,13 +1506,15 @@ end if step <= 4 || order < 3 cache.order = min(order + 1, 3) else - # @.. broadcast=false utildem2 = dt * γstar[(k-2)+1] * ϕ_np1[k-1] - @.. broadcast=false utildem2=(g[k - 1] - g[k - 2]) * ϕ_np1[k - 1] - # @.. broadcast=false utildem1 = dt * γstar[(k-1)+1] * ϕ_np1[k] - @.. broadcast=false utildem1=(g[k] - g[k - 1]) * ϕ_np1[k] + # @.. broadcast=false thread=thread utildem2 = dt * γstar[(k-2)+1] * ϕ_np1[k-1] + @.. broadcast=false thread=thread utildem2=(g[k - 1] - g[k - 2]) * + ϕ_np1[k - 1] + # @.. broadcast=false thread=thread utildem1 = dt * γstar[(k-1)+1] * ϕ_np1[k] + @.. broadcast=false thread=thread utildem1=(g[k] - g[k - 1]) * ϕ_np1[k] expand_ϕ_and_ϕstar!(cache, k + 1) ϕ_np1!(cache, k4, k + 2) - @.. broadcast=false utildep1=dt * γstar[(k + 1) + 1] * ϕ_np1[k + 2] + @.. broadcast=false thread=thread utildep1=dt * γstar[(k + 1) + 1] * + ϕ_np1[k + 2] calculate_residuals!(atmpm2, utildem2, uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl index af35c61140..cf3b3613dc 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl @@ -10,7 +10,13 @@ reference = """E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differentia reference, "", "") -struct AB3 <: OrdinaryDiffEqAlgorithm end +struct AB3{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end + +function AB3() + AB3(False()) +end @doc generic_solver_docstring("The 4-step fourth order multistep method. Runge-Kutta method of order 4 is used to calculate starting values.", @@ -19,7 +25,13 @@ struct AB3 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct AB4 <: OrdinaryDiffEqAlgorithm end +struct AB4{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end +function AB4() + AB4(False()) +end + @doc generic_solver_docstring("The 5-step fifth order multistep method. Ralston's 3rd order Runge-Kutta method is used to calculate starting values.", "AB5", @@ -27,7 +39,12 @@ struct AB4 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct AB5 <: OrdinaryDiffEqAlgorithm end +struct AB5{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end +function AB5() + AB5(False()) +end @doc generic_solver_docstring("It is third order method. In ABM32, AB3 works as predictor and Adams Moulton 2-steps method works as Corrector. @@ -37,7 +54,12 @@ struct AB5 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct ABM32 <: OrdinaryDiffEqAlgorithm end +struct ABM32{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end +function ABM32() + ABM32(False()) +end @doc generic_solver_docstring("It is fourth order method. In ABM43, AB4 works as predictor and Adams Moulton 3-steps method works as Corrector. @@ -47,7 +69,12 @@ struct ABM32 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct ABM43 <: OrdinaryDiffEqAlgorithm end +struct ABM43{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end +function ABM43() + ABM43(False()) +end @doc generic_solver_docstring("It is fifth order method. In ABM54, AB5 works as predictor and Adams Moulton 4-steps method works as Corrector. @@ -57,7 +84,12 @@ struct ABM43 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct ABM54 <: OrdinaryDiffEqAlgorithm end +struct ABM54{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread +end +function ABM54() + ABM54(False()) +end # Variable Step Size Adams methods @@ -68,7 +100,12 @@ struct ABM54 <: OrdinaryDiffEqAlgorithm end reference, "", "") -struct VCAB3 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCAB3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCAB3() + VCAB3(False()) +end @doc generic_solver_docstring("The 4th order Adams method. Runge-Kutta 4 is used to calculate starting values.", @@ -77,7 +114,12 @@ struct VCAB3 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCAB4 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCAB4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCAB4() + VCAB4(False()) +end @doc generic_solver_docstring("The 5th order Adams method. Runge-Kutta 4 is used to calculate starting values.", @@ -86,7 +128,12 @@ struct VCAB4 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCAB5 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCAB5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCAB5() + VCAB5(False()) +end @doc generic_solver_docstring("The 3rd order Adams-Moulton method. Bogacki-Shampine 3/2 method is used to calculate starting values.", @@ -95,7 +142,12 @@ struct VCAB5 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCABM3 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCABM3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCABM3() + VCABM3(False()) +end @doc generic_solver_docstring("The 4th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values.", @@ -104,7 +156,12 @@ struct VCABM3 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCABM4 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCABM4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCABM4() + VCABM4(False()) +end @doc generic_solver_docstring("The 5th order Adams-Moulton method. Runge-Kutta 4 is used to calculate starting values.", @@ -113,7 +170,12 @@ struct VCABM4 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCABM5 <: OrdinaryDiffEqAdaptiveAlgorithm end +struct VCABM5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread +end +function VCABM5() + VCABM5(False()) +end # Variable Order and Variable Step Size Adams methods @@ -124,4 +186,9 @@ struct VCABM5 <: OrdinaryDiffEqAdaptiveAlgorithm end reference, "", "") -struct VCABM <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm end +struct VCABM{Thread} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm + thread::Thread +end +function VCABM() + VCABM(False()) +end From c23e54ead503465636d6142e142e476cf704dbb7 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 11:40:53 -0500 Subject: [PATCH 125/203] use recursivecopy, fix the default AliasSpecifier --- lib/OrdinaryDiffEqCore/src/solve.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index a6ad0933a2..bde6ddea77 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -69,7 +69,7 @@ function DiffEqBase.__init( userdata = nothing, allow_extrapolation = alg_extrapolates(alg), initialize_integrator = true, - alias = ODEAliasSpecifier(alias_u0 = false, alias_du0 = false, alias_p = true, alias_f = true), + alias = ODEAliasSpecifier(), initializealg = DefaultInit(), kwargs...) where {recompile_flag} if prob isa DiffEqBase.AbstractDAEProblem && alg isa OrdinaryDiffEqAlgorithm @@ -284,9 +284,9 @@ function DiffEqBase.__init( if isnothing(aliases.alias_tstops) || aliases.alias_tstops tstops = tstops else - tstops = deepcopy(tstops) + tstops = recursivecopy(tstops) end - + if tstops isa AbstractArray || tstops isa Tuple || tstops isa Number _tstops = nothing else From 78b1a9774df765e3aabda83c7e5d47d23a976618 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 11:58:41 -0500 Subject: [PATCH 126/203] fix depwarns --- lib/OrdinaryDiffEqCore/src/solve.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index bde6ddea77..c816f07ed9 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -163,8 +163,10 @@ function DiffEqBase.__init( if use_old_kwargs aliases = ODEAliasSpecifier() if haskey(kwargs, :alias_u0) - Base.depwarn("alias_u0 keyword argument is deprecated, to set `alias_u0`, - please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))", :alias_u0) + message = "`alias_u0` keyword argument is deprecated, to set `alias_u0`, + please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))" + Base.depwarn(message, :init) + Base.depwarn(message, :solve) @reset aliases.alias_u0 = values(kwargs).alias_u0 else @reset aliases.alias_u0 = false @@ -172,8 +174,10 @@ function DiffEqBase.__init( end if haskey(kwargs, :alias_du0) - Base.depwarn("alias_du0 keyword argument is deprecated, to set `alias_du0`, - please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))", :alias_du0) + message = "`alias_du0` keyword argument is deprecated, to set `alias_du0`, + please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))" + Base.depwarn(message, :init) + Base.depwarn(message, :solve) @reset aliases.alias_du0 = values(kwargs).alias_du0 else @reset aliases.alias_du0 = false From b5657e902873c7150cbfab8d2dc2112636b67d52 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 12:21:09 -0500 Subject: [PATCH 127/203] make tests use aliasing API --- .../test/ode_low_storage_rk_tests.jl | 182 +++++++++--------- .../test/ode_ssprk_tests.jl | 20 +- 2 files changed, 101 insertions(+), 101 deletions(-) diff --git a/lib/OrdinaryDiffEqLowStorageRK/test/ode_low_storage_rk_tests.jl b/lib/OrdinaryDiffEqLowStorageRK/test/ode_low_storage_rk_tests.jl index e4c5eece35..5bdc9109b1 100644 --- a/lib/OrdinaryDiffEqLowStorageRK/test/ode_low_storage_rk_tests.jl +++ b/lib/OrdinaryDiffEqLowStorageRK/test/ode_low_storage_rk_tests.jl @@ -101,13 +101,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -116,7 +116,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -146,13 +146,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -161,7 +161,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -191,13 +191,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -206,7 +206,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -236,13 +236,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -251,7 +251,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -281,13 +281,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -296,7 +296,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -326,13 +326,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -341,7 +341,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -371,13 +371,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -386,7 +386,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -416,13 +416,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -431,7 +431,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -461,13 +461,13 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 2 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg2, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -476,7 +476,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -499,7 +499,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -508,7 +508,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -531,7 +531,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -540,7 +540,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -593,7 +593,7 @@ test_problems_nonlinear_BigFloat = [prob_nonlinear_A, prob_nonlinear_B] save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 7 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -602,7 +602,7 @@ test_problems_nonlinear_BigFloat = [prob_nonlinear_A, prob_nonlinear_B] save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -628,7 +628,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 7 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -637,7 +637,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -663,7 +663,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 7 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -672,7 +672,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -698,7 +698,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 7 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -707,7 +707,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -733,7 +733,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 7 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -742,7 +742,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -768,7 +768,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -777,7 +777,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -803,7 +803,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -812,7 +812,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -838,7 +838,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -847,7 +847,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -873,7 +873,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -882,7 +882,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -908,7 +908,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -917,7 +917,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -943,7 +943,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 10 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 9 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -952,7 +952,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -978,7 +978,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 12 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 11 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -987,7 +987,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1013,7 +1013,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 12 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 11 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1022,7 +1022,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1048,7 +1048,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 12 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 11 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1057,7 +1057,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1083,7 +1083,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 12 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 11 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1092,7 +1092,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1118,7 +1118,7 @@ end save_end = false, save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 14 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 13 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1127,7 +1127,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1153,7 +1153,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1162,7 +1162,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1186,7 +1186,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1195,7 +1195,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1219,7 +1219,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1228,7 +1228,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1254,7 +1254,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1263,7 +1263,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1286,7 +1286,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1295,7 +1295,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1319,7 +1319,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1328,7 +1328,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1353,7 +1353,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1362,7 +1362,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1387,7 +1387,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1396,7 +1396,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1422,7 +1422,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1431,7 +1431,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1456,7 +1456,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1465,7 +1465,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1488,7 +1488,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1497,7 +1497,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1521,7 +1521,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1530,7 +1530,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1555,7 +1555,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1564,7 +1564,7 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end @@ -1587,7 +1587,7 @@ end save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 # test whether aliasing u0 is bad new_prob_ode_nonlinear_inplace = ODEProblem(prob_ode_nonlinear_inplace.f, [1.0], @@ -1596,6 +1596,6 @@ end save_start = false) sol_new = solve( new_prob_ode_nonlinear_inplace, alg, dt = 1.e-4, save_everystep = false, - save_start = false, alias_u0 = true) + save_start = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test sol_old[end] ≈ sol_new[end] end diff --git a/lib/OrdinaryDiffEqSSPRK/test/ode_ssprk_tests.jl b/lib/OrdinaryDiffEqSSPRK/test/ode_ssprk_tests.jl index ec0c73f11b..444ec1b7d5 100644 --- a/lib/OrdinaryDiffEqSSPRK/test/ode_ssprk_tests.jl +++ b/lib/OrdinaryDiffEqSSPRK/test/ode_ssprk_tests.jl @@ -80,7 +80,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 println("KYKSSPRK42") @@ -134,7 +134,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 println("SSPRK53") @@ -160,7 +160,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 println("SSPRK53_2N1") @@ -186,7 +186,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 # for SSPRK53_2N2 to be in asymptotic range @@ -214,7 +214,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 3 dts = 1 .// 2 .^ (9:-1:5) @@ -241,7 +241,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 4 #reverting back to original dts @@ -334,7 +334,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 println("SSPRK432") @@ -368,7 +368,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 alg = SSPRKMSVS32() @@ -423,7 +423,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 println("SSPRK54") @@ -470,7 +470,7 @@ integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = fal save_everystep = false) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 6 integ = init(prob_ode_large, alg, dt = 1.e-2, save_start = false, save_end = false, - save_everystep = false, alias_u0 = true) + save_everystep = false, alias = ODEAliasSpecifier(alias_u0 = true)) @test Base.summarysize(integ) ÷ Base.summarysize(u0_large) <= 5 println("KYK2014DGSSPRK_3S2") From ec1e99fe85e99bfaa91a45909f46a284dda3811c Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 14:00:24 -0500 Subject: [PATCH 128/203] add test --- test/interface/aliasing_tests.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/interface/aliasing_tests.jl diff --git a/test/interface/aliasing_tests.jl b/test/interface/aliasing_tests.jl new file mode 100644 index 0000000000..65f2e55950 --- /dev/null +++ b/test/interface/aliasing_tests.jl @@ -0,0 +1,11 @@ +using OrdinaryDiffEq, Test + +import ODEProblemLibrary: prob_ode_2Dlinear +import DAEProblemLibrary: prob_dae_transamp + +# Test that the old keyword works, and that the new AliasSpecier works. +u0_old_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias_u0 = true) +u0_new_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias = ODEAliasSpecifier(alias_u0 = true)) + +@test u0_old_alias_kwarg_sol == u0_new_alias_kwarg_sol + From b3351f008f1497cc17e2944d85cba17fca13401e Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 14:01:08 -0500 Subject: [PATCH 129/203] can't use Accessors because no default inner constructors anymore --- lib/OrdinaryDiffEqCore/src/solve.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index c816f07ed9..532826169c 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -167,10 +167,9 @@ function DiffEqBase.__init( please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_u0 = true))" Base.depwarn(message, :init) Base.depwarn(message, :solve) - @reset aliases.alias_u0 = values(kwargs).alias_u0 + aliases = ODEAliasSpecifier(alias_u0 = values(kwargs).alias_u0) else - @reset aliases.alias_u0 = false - + aliases = ODEAliasSpecifier(alias_u0 = nothing) end if haskey(kwargs, :alias_du0) @@ -178,9 +177,9 @@ function DiffEqBase.__init( please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))" Base.depwarn(message, :init) Base.depwarn(message, :solve) - @reset aliases.alias_du0 = values(kwargs).alias_du0 + aliases = ODEAliasSpecifier(alias_u0 = aliases.alias_u0, alias_du0 = values(kwargs).alias_du0) else - @reset aliases.alias_du0 = false + aliases = ODEAliasSpecifier(alias_u0 = aliases.alias_u0, alias_du0 = nothing) end aliases From 4feb5e3c7f625102428cf44ea1545a072b294f92 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 13 Dec 2024 14:02:03 -0500 Subject: [PATCH 130/203] add to run test --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 55b58486ab..28b3d74199 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -56,6 +56,7 @@ end @time @safetestset "Inplace Interpolation Tests" include("interface/inplace_interpolation.jl") @time @safetestset "Algebraic Interpolation Tests" include("interface/algebraic_interpolation.jl") @time @safetestset "Interpolation and Cache Stripping Tests" include("interface/ode_strip_test.jl") + @time @safetestset "Aliasing Tests" include("interface/aliasing_tests.jl") end if !is_APPVEYOR && (GROUP == "All" || GROUP == "InterfaceII" || GROUP == "Interface") From ba9abe9e40f9ed4f4d7bba7bdeeb50a6204ad500 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 14 Dec 2024 02:47:01 -0100 Subject: [PATCH 131/203] Update Project.toml --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index f5f381c9a0..2b5faad3ba 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -70,7 +70,7 @@ Random = "<0.0.1, 1" RecursiveArrayTools = "2.36, 3" Reexport = "1.0" SafeTestsets = "0.1.0" -SciMLBase = "2.62" +SciMLBase = "2.68" SciMLOperators = "0.3" SciMLStructures = "1" SimpleUnPack = "1" From 532c3ffb6189f4a3bb062f30daabb2596f9d2cc2 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Sat, 14 Dec 2024 10:19:19 -0500 Subject: [PATCH 132/203] fix bool problem for alias_du0 --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 532826169c..25c4c0dffc 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -212,7 +212,7 @@ function DiffEqBase.__init( end if _alg isa DAEAlgorithm - if aliases.alias_du0 + if !isnothing(aliases.alias_du0) && aliases.alias_du0 du = prob.du0 else du = recursivecopy(prob.du0) From a2a2954f5f90f646497d3b7d982315b19e6a86b8 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Sat, 14 Dec 2024 10:59:10 -0500 Subject: [PATCH 133/203] get rid of DAE problem, unused --- test/interface/aliasing_tests.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/interface/aliasing_tests.jl b/test/interface/aliasing_tests.jl index 65f2e55950..b8892e164c 100644 --- a/test/interface/aliasing_tests.jl +++ b/test/interface/aliasing_tests.jl @@ -1,7 +1,6 @@ using OrdinaryDiffEq, Test import ODEProblemLibrary: prob_ode_2Dlinear -import DAEProblemLibrary: prob_dae_transamp # Test that the old keyword works, and that the new AliasSpecier works. u0_old_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias_u0 = true) From affbc1402eff2b08da95995a769333d6d7ef949a Mon Sep 17 00:00:00 2001 From: jClugstor Date: Sat, 14 Dec 2024 11:10:46 -0500 Subject: [PATCH 134/203] nothing checking doesn't make sense here --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 25c4c0dffc..ffaa61ace0 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -188,7 +188,7 @@ function DiffEqBase.__init( # If alias isa Bool, all fields of ODEAliases set to alias if alias isa Bool aliases = ODEAliasSpecifier(alias = alias) - elseif isnothing(alias) || alias isa ODEAliasSpecifier + elseif alias isa ODEAliasSpecifier aliases = alias end end From eacc432f7863a4762c7e898151c2a669c5d2f187 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Sat, 14 Dec 2024 16:13:43 -0500 Subject: [PATCH 135/203] fix test --- test/interface/aliasing_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/interface/aliasing_tests.jl b/test/interface/aliasing_tests.jl index b8892e164c..4e2bfe0bc7 100644 --- a/test/interface/aliasing_tests.jl +++ b/test/interface/aliasing_tests.jl @@ -1,6 +1,6 @@ using OrdinaryDiffEq, Test -import ODEProblemLibrary: prob_ode_2Dlinear +import ODEProblemLibrary: prob_ode_linear # Test that the old keyword works, and that the new AliasSpecier works. u0_old_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias_u0 = true) From 42b98fc9aa8e8e1d92c408bc80dc79e0045c6cba Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Tue, 17 Dec 2024 10:48:49 -0100 Subject: [PATCH 136/203] Refactor & Generalize: System for opting alg into linear interpolation We haven't really needed this much before since most methods had a special interpolation or default Hermite, so we had a bespoke way of opting just a few algorithms out (FunctionMap and the DAE solvers for now). But there are cases which need to be able to opt into saying they only want a linear interpolation as the Hermite would take extra function evaluations or would not satisfy the right properties, and thus for these equations this gives them an overload they can use to opt out on a per-algorithm basis via a trait function. --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 3 +++ lib/OrdinaryDiffEqCore/src/solve.jl | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index d5f89349d6..3f662c98c4 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -444,3 +444,6 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end print(io, ")") end + +# Defaults in the current system: currently opt out DAEAlgorithms until complete +default_linear_interpolation(alg, prob) = alg isa DAEAlgorithm || prob isa DiscreteProblem \ No newline at end of file diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 42fd07a5bf..f8540cfae8 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -26,9 +26,7 @@ function DiffEqBase.__init( saveat isa Number || prob.tspan[1] in saveat, save_end = nothing, callback = nothing, - dense = save_everystep && - !(alg isa DAEAlgorithm) && !(prob isa DiscreteProblem) && - isempty(saveat), + dense = save_everystep && isempty(saveat) && !default_linear_interpolation(prob, alg), calck = (callback !== nothing && callback !== CallbackSet()) || (dense) || !isempty(saveat), # and no dense output dt = isdiscretealg(alg) && isempty(tstops) ? From 23c054b86faeda01d9323f10afac8659b0e75a06 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Wed, 18 Dec 2024 11:55:51 +0100 Subject: [PATCH 137/203] Add regression tests for multithreaded ABM algs --- .../test/regression_test_threading.jl | 27 +++++++++++++++++++ .../test/runtests.jl | 1 + 2 files changed, 28 insertions(+) create mode 100644 lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl new file mode 100644 index 0000000000..bfc0954c57 --- /dev/null +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl @@ -0,0 +1,27 @@ +using OrdinaryDiffEqAdamsBashforthMoulton, ODEProblemLibrary +using Test +using Static + +free_timestep_algorithms = [ VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM] + +fixed_timestep_algorithms = [AB3,AB4, AB5, ABM32, ABM43, ABM54] + +problem = ODEProblemLibrary.prob_ode_linear + +function test_alg(ALG; kwargs...) + sol_thread = solve(problem, ALG(Static.True()); kwargs...) + sol_nothread = solve(problem, ALG(Static.False()); kwargs...) + + @test all(sol_nothread .== sol_thread) +end + + +@testset "Regression test for threading versions vs non threading versions" begin + @testset "$ALG" for ALG in fixed_timestep_algorithms + test_alg(ALG, dt=1//2^9) + end + @testset "$ALG" for ALG in free_timestep_algorithms + test_alg(ALG) + end + +end diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl index a0518e6f70..75b03c8ca4 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl @@ -2,3 +2,4 @@ using SafeTestsets @time @safetestset "ABM Convergence Tests" include("abm_convergence_tests.jl") @time @safetestset "Adams Variable Coefficients Tests" include("adams_tests.jl") +@time @safetestset "Regression test for threading versions vs non threading versions" include("regression_test_threading.jl") From 69b7d167b7f9f82bb460dc683d03df0c2cd977bd Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Wed, 18 Dec 2024 12:04:29 +0100 Subject: [PATCH 138/203] Format ABM subdirectory Run the reformatting command suggested in CONTRIBUTING.md, but keeping only the changes on the ABM directory (which my current PR is affecting) --- .../src/adams_bashforth_moulton_perform_step.jl | 2 +- .../test/regression_test_threading.jl | 14 ++++++-------- .../test/runtests.jl | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl index 5e160b2b02..e22e68c517 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/adams_bashforth_moulton_perform_step.jl @@ -303,7 +303,7 @@ end t4 .= k4 perform_step!(integrator, AB4Cache(u, uprev, fsalfirst, t2, t3, t4, ralk2, k, tmp, t5, t6, t7, - cnt,thread)) + cnt, thread)) k = integrator.fsallast @.. broadcast=false thread=thread u=uprev + (dt / 24) * (9 * k + 19 * k1 - 5 * k2 + k3) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl index bfc0954c57..2a2da48b9c 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl @@ -2,26 +2,24 @@ using OrdinaryDiffEqAdamsBashforthMoulton, ODEProblemLibrary using Test using Static -free_timestep_algorithms = [ VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM] +free_timestep_algorithms = [VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM] -fixed_timestep_algorithms = [AB3,AB4, AB5, ABM32, ABM43, ABM54] +fixed_timestep_algorithms = [AB3, AB4, AB5, ABM32, ABM43, ABM54] problem = ODEProblemLibrary.prob_ode_linear function test_alg(ALG; kwargs...) - sol_thread = solve(problem, ALG(Static.True()); kwargs...) - sol_nothread = solve(problem, ALG(Static.False()); kwargs...) + sol_thread = solve(problem, ALG(Static.True()); kwargs...) + sol_nothread = solve(problem, ALG(Static.False()); kwargs...) - @test all(sol_nothread .== sol_thread) + @test all(sol_nothread .== sol_thread) end - @testset "Regression test for threading versions vs non threading versions" begin @testset "$ALG" for ALG in fixed_timestep_algorithms - test_alg(ALG, dt=1//2^9) + test_alg(ALG, dt = 1 // 2^9) end @testset "$ALG" for ALG in free_timestep_algorithms test_alg(ALG) end - end diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl index 75b03c8ca4..fd3e5ee9a4 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/runtests.jl @@ -2,4 +2,4 @@ using SafeTestsets @time @safetestset "ABM Convergence Tests" include("abm_convergence_tests.jl") @time @safetestset "Adams Variable Coefficients Tests" include("adams_tests.jl") -@time @safetestset "Regression test for threading versions vs non threading versions" include("regression_test_threading.jl") +@time @safetestset "Regression test for threading versions vs non threading versions" include("regression_test_threading.jl") From 102e447efbcf873deb2f25889014bdd1df16ecd0 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Thu, 19 Dec 2024 14:42:43 +0100 Subject: [PATCH 139/203] Add conv tests for a few ABM threaded methods --- .../test/abm_convergence_tests.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/abm_convergence_tests.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/abm_convergence_tests.jl index ccebddd73e..ffe01a7d71 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/abm_convergence_tests.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/abm_convergence_tests.jl @@ -37,3 +37,21 @@ testTol = 0.2 sim106 = test_convergence(dts, prob, VCABM5()) @test sim106.𝒪est[:l2]≈5 atol=testTol end + +@testset "Explicit Solver Convergence Tests ($(["out-of-place", "in-place"][i])) - threaded " for i in 1:2 + prob = (ODEProblemLibrary.prob_ode_linear, + ODEProblemLibrary.prob_ode_2Dlinear)[i] + + sim5 = test_convergence(dts, prob, AB3(true)) + @test sim5.𝒪est[:l2]≈3 atol=testTol + sim7 = test_convergence(dts, prob, AB4(true)) + @test sim7.𝒪est[:l2]≈4 atol=testTol + sim9 = test_convergence(dts, prob, AB5(true)) + @test sim9.𝒪est[:l2]≈5 atol=testTol + sim101 = test_convergence(dts, prob, VCAB3(true)) + @test sim101.𝒪est[:l2]≈3 atol=testTol + sim103 = test_convergence(dts, prob, VCAB5(true)) + @test sim103.𝒪est[:l2]≈5 atol=testTol + sim105 = test_convergence(dts, prob, VCABM4(true)) + @test sim105.𝒪est[:l2]≈4 atol=testTol +end From b92befb19508915a3c1bdc82112015db441cdfbf Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Thu, 19 Dec 2024 15:22:28 +0100 Subject: [PATCH 140/203] ABM algs: refactor regr/thread tests for clarity --- .../test/regression_test_threading.jl | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl index 2a2da48b9c..b70a6b11cb 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/test/regression_test_threading.jl @@ -1,25 +1,22 @@ using OrdinaryDiffEqAdamsBashforthMoulton, ODEProblemLibrary +import OrdinaryDiffEqCore: OrdinaryDiffEqAdaptiveAlgorithm using Test using Static -free_timestep_algorithms = [VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM] - -fixed_timestep_algorithms = [AB3, AB4, AB5, ABM32, ABM43, ABM54] +algorithms = [ + AB3, AB4, AB5, ABM32, ABM43, ABM54, VCAB3, VCAB4, VCAB5, VCABM3, VCABM4, VCABM5, VCABM] problem = ODEProblemLibrary.prob_ode_linear -function test_alg(ALG; kwargs...) - sol_thread = solve(problem, ALG(Static.True()); kwargs...) - sol_nothread = solve(problem, ALG(Static.False()); kwargs...) - - @test all(sol_nothread .== sol_thread) -end - @testset "Regression test for threading versions vs non threading versions" begin - @testset "$ALG" for ALG in fixed_timestep_algorithms - test_alg(ALG, dt = 1 // 2^9) - end - @testset "$ALG" for ALG in free_timestep_algorithms - test_alg(ALG) + @testset "$ALG" for ALG in algorithms + if ALG isa OrdinaryDiffEqAdaptiveAlgorithm + sol_thread = solve(problem, ALG(Static.True())) + sol_nothread = solve(problem, ALG(Static.False())) + else + sol_thread = solve(problem, ALG(Static.True()), dt = 1 // 2^9) + sol_nothread = solve(problem, ALG(Static.False()), dt = 1 // 2^9) + end + @test all(sol_nothread .== sol_thread) end end From c943f020e6988bc45b2423767e3dc9a32acc79f8 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Thu, 19 Dec 2024 15:26:12 +0100 Subject: [PATCH 141/203] ABM algs: use Base.@kwdef for consistency Instead of having a lame external constructor --- .../src/algorithms.jl | 88 ++++++------------- 1 file changed, 26 insertions(+), 62 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl index cf3b3613dc..21a6b105f2 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl @@ -14,8 +14,8 @@ struct AB3{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread end -function AB3() - AB3(False()) +Base.@kwdef struct AB3{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 4-step fourth order multistep method. @@ -25,11 +25,8 @@ end reference, "", "") -struct AB4{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end -function AB4() - AB4(False()) +Base.@kwdef struct AB4{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 5-step fifth order multistep method. @@ -39,11 +36,8 @@ end reference, "", "") -struct AB5{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end -function AB5() - AB5(False()) +Base.@kwdef struct AB5{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("It is third order method. @@ -54,11 +48,8 @@ end reference, "", "") -struct ABM32{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end -function ABM32() - ABM32(False()) +Base.@kwdef struct ABM32{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("It is fourth order method. @@ -69,11 +60,8 @@ end reference, "", "") -struct ABM43{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end -function ABM43() - ABM43(False()) +Base.@kwdef struct ABM43{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("It is fifth order method. @@ -84,11 +72,8 @@ end reference, "", "") -struct ABM54{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end -function ABM54() - ABM54(False()) +Base.@kwdef struct ABM54{Thread} <: OrdinaryDiffEqAlgorithm + thread::Thread = False() end # Variable Step Size Adams methods @@ -100,11 +85,8 @@ end reference, "", "") -struct VCAB3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCAB3() - VCAB3(False()) +Base.@kwdef struct VCAB3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 4th order Adams method. @@ -114,11 +96,8 @@ end reference, "", "") -struct VCAB4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCAB4() - VCAB4(False()) +Base.@kwdef struct VCAB4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 5th order Adams method. @@ -128,11 +107,8 @@ end reference, "", "") -struct VCAB5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCAB5() - VCAB5(False()) +Base.@kwdef struct VCAB5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 3rd order Adams-Moulton method. @@ -142,11 +118,8 @@ end reference, "", "") -struct VCABM3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCABM3() - VCABM3(False()) +Base.@kwdef struct VCABM3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 4th order Adams-Moulton method. @@ -156,11 +129,8 @@ end reference, "", "") -struct VCABM4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCABM4() - VCABM4(False()) +Base.@kwdef struct VCABM4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end @doc generic_solver_docstring("The 5th order Adams-Moulton method. @@ -170,11 +140,8 @@ end reference, "", "") -struct VCABM5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm - thread::Thread -end -function VCABM5() - VCABM5(False()) +Base.@kwdef struct VCABM5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm + thread::Thread = False() end # Variable Order and Variable Step Size Adams methods @@ -186,9 +153,6 @@ end reference, "", "") -struct VCABM{Thread} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm - thread::Thread -end -function VCABM() - VCABM(False()) +Base.@kwdef struct VCABM{Thread} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm + thread::Thread = False() end From c56813f71c7dacad39c19bef733a3d5c624c7d96 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Thu, 19 Dec 2024 15:27:46 +0100 Subject: [PATCH 142/203] ABM algorithms: documentation of thread argument --- .../src/algorithms.jl | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl index 21a6b105f2..8adf8dbd43 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/algorithms.jl @@ -3,17 +3,21 @@ reference = """E. Hairer, S. P. Norsett, G. Wanner, Solving Ordinary Differentia Problems. Computational Mathematics (2nd revised ed.), Springer (1996) doi: https://doi.org/10.1007/978-3-540-78862-1""" +keyword_default_description = """ +- `thread`: determines whether internal broadcasting on appropriate CPU arrays should be serial (`thread = OrdinaryDiffEq.False()`) or use multiple threads (`thread = OrdinaryDiffEq.True()`) when Julia is started with multiple threads. +""" + +keyword_default = """ +thread = OrdinaryDiffEq.False(), +""" + @doc generic_solver_docstring("The 3-step third order multistep method. Ralston's Second Order Method is used to calculate starting values.", "AB3", "Adams-Bashforth Explicit Method", reference, - "", - "") -struct AB3{Thread} <: OrdinaryDiffEqAlgorithm - thread::Thread -end - + keyword_default_description, + keyword_default) Base.@kwdef struct AB3{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -23,8 +27,8 @@ end "AB4", "Adams-Bashforth Explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct AB4{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -34,8 +38,8 @@ end "AB5", "Adams-Bashforth Explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct AB5{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -46,8 +50,8 @@ end "ABM32", "Adams-Bashforth Explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct ABM32{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -58,8 +62,8 @@ end "ABM43", "Adams-Bashforth Explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct ABM43{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -70,8 +74,8 @@ end "ABM54", "Adams-Bashforth Explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct ABM54{Thread} <: OrdinaryDiffEqAlgorithm thread::Thread = False() end @@ -83,8 +87,8 @@ end "VCAB3", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCAB3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -94,8 +98,8 @@ end "VCAB4", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCAB4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -105,8 +109,8 @@ end "VCAB5", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCAB5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -116,8 +120,8 @@ end "VCABM3", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCABM3{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -127,8 +131,8 @@ end "VCABM4", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCABM4{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -138,8 +142,8 @@ end "VCABM5", "Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCABM5{Thread} <: OrdinaryDiffEqAdaptiveAlgorithm thread::Thread = False() end @@ -151,8 +155,8 @@ end "VCABM", "adaptive order Adams explicit Method", reference, - "", - "") + keyword_default_description, + keyword_default) Base.@kwdef struct VCABM{Thread} <: OrdinaryDiffEqAdamsVarOrderVarStepAlgorithm thread::Thread = False() end From e5986e1b201d9f2cdef52865a6c3830356326772 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:06:17 +0100 Subject: [PATCH 143/203] Optimize `VerletLeapfrog` method --- .../src/symplectic_caches.jl | 28 ++++++-- .../src/symplectic_perform_step.jl | 71 ++++++++++++++++--- .../src/symplectic_tableaus.jl | 8 --- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl index dca14b6d28..16c8e4f4e3 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl @@ -57,13 +57,18 @@ function alg_cache(alg::VelocityVerlet, u, rate_prototype, ::Type{uEltypeNoUnits VelocityVerletConstantCache(uEltypeNoUnits(1 // 2)) end -@cache struct Symplectic2Cache{uType, rateType, tableauType} <: HamiltonMutableCache +@cache struct VerletLeapfrogCache{uType, rateType, uEltypeNoUnits} <: + OrdinaryDiffEqMutableCache u::uType uprev::uType tmp::uType k::rateType fsalfirst::rateType - tab::tableauType + half::uEltypeNoUnits +end + +struct VerletLeapfrogConstantCache{uEltypeNoUnits} <: HamiltonConstantCache + half::uEltypeNoUnits end function alg_cache(alg::VerletLeapfrog, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -73,16 +78,24 @@ function alg_cache(alg::VerletLeapfrog, u, rate_prototype, ::Type{uEltypeNoUnits tmp = zero(u) k = zero(rate_prototype) fsalfirst = zero(rate_prototype) - tab = VerletLeapfrogConstantCache(constvalue(uBottomEltypeNoUnits), - constvalue(tTypeNoUnits)) - Symplectic2Cache(u, uprev, k, tmp, fsalfirst, tab) + half = uEltypeNoUnits(1 // 2) + VerletLeapfrogCache(u, uprev, k, tmp, fsalfirst, half) end function alg_cache(alg::VerletLeapfrog, u, rate_prototype, ::Type{uEltypeNoUnits}, ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck, ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - VerletLeapfrogConstantCache(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) + VerletLeapfrogConstantCache(uEltypeNoUnits(1 // 2)) +end + +@cache struct Symplectic2Cache{uType, rateType, tableauType} <: HamiltonMutableCache + u::uType + uprev::uType + tmp::uType + k::rateType + fsalfirst::rateType + tab::tableauType end function alg_cache(alg::PseudoVerletLeapfrog, u, rate_prototype, ::Type{uEltypeNoUnits}, @@ -422,6 +435,7 @@ function alg_cache(alg::SofSpa10, u, rate_prototype, ::Type{uEltypeNoUnits}, end function get_fsalfirstlast( - cache::Union{HamiltonMutableCache, VelocityVerletCache, SymplecticEulerCache}, u) + cache::Union{HamiltonMutableCache, VelocityVerletCache, VerletLeapfrogCache, + SymplecticEulerCache}, u) (cache.fsalfirst, cache.k) end diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index 2e581be283..178aecae84 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -77,8 +77,12 @@ end # f.f2(p, q, pa, t) = p which is the Newton/Lagrange equations # If called with different functions (which are possible in the Hamiltonian case) # an exception is thrown to avoid silently calculate wrong results. -verify_f2(f, p, q, pa, t, ::Any, ::C) where {C <: HamiltonConstantCache} = f(p, q, pa, t) -function verify_f2(f, res, p, q, pa, t, ::Any, ::C) where {C <: HamiltonMutableCache} +function verify_f2(f, p, q, pa, t, ::Any, + ::C) where {C <: Union{HamiltonConstantCache, VerletLeapfrogConstantCache}} + f(p, q, pa, t) +end +function verify_f2(f, res, p, q, pa, t, ::Any, + ::C) where {C <: Union{HamiltonMutableCache, VerletLeapfrogCache}} f(res, p, q, pa, t) end @@ -124,8 +128,8 @@ function store_symp_state!(integrator, ::OrdinaryDiffEqMutableCache, kdu, ku) end function initialize!(integrator, - cache::C) where {C <: - Union{HamiltonMutableCache, VelocityVerletCache}} + cache::C) where {C <: Union{ + HamiltonMutableCache, VelocityVerletCache, VerletLeapfrogCache}} integrator.kshortsize = 2 resize!(integrator.k, integrator.kshortsize) integrator.k[1] = integrator.fsalfirst @@ -140,9 +144,8 @@ function initialize!(integrator, end function initialize!(integrator, - cache::C) where { - C <: - Union{HamiltonConstantCache, VelocityVerletConstantCache}} + cache::C) where {C <: Union{ + HamiltonConstantCache, VelocityVerletConstantCache, VerletLeapfrogConstantCache}} integrator.kshortsize = 2 integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) @@ -171,7 +174,7 @@ end # v(t+Δt) = v(t) + 1/2*(a(t)+a(t+Δt))*Δt du = duprev + dt * (half * ku + half * kdu) - OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) store_symp_state!(integrator, cache, du, u, kdu, du) end @@ -186,13 +189,63 @@ end half = cache.half @.. broadcast=false u=uprev + dt * duprev + dtsq * (half * ku) f.f1(kdu, duprev, u, p, t + dt) - OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) # v(t+Δt) = v(t) + 1/2*(a(t)+a(t+Δt))*Δt @.. broadcast=false du=duprev + dt * (half * ku + half * kdu) store_symp_state!(integrator, cache, kdu, du) end +@muladd function perform_step!(integrator, cache::VerletLeapfrogConstantCache, + repeat_step = false) + @unpack t, dt, f, p = integrator + duprev, uprev, kduprev, kuprev = load_symp_state(integrator) + + # kick-drift-kick scheme of the Verlet Leapfrog method: + # update velocity + half = cache.half + du = duprev + dt * half * kduprev + + # update position + tnew = t + half * dt + ku = f.f2(du, uprev, p, tnew) + u = uprev + dt * ku + + # update velocity + tnew = tnew + half * dt + kdu = f.f1(du, u, p, tnew) + du = du + dt * half * kdu + + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) + integrator.stats.nf2 += 1 + store_symp_state!(integrator, cache, kdu, ku) +end + +@muladd function perform_step!(integrator, cache::VerletLeapfrogCache, repeat_step = false) + @unpack t, dt, f, p = integrator + duprev, uprev, kduprev, kuprev = load_symp_state(integrator) + du, u, kdu, ku = alloc_symp_state(integrator) + + # Kick-Drift-Kick scheme of the Verlet Leapfrog method: + # update velocity + half = cache.half + @.. broadcast=false du=duprev + dt * half * kduprev + + # update position + tnew = t + half * dt + f.f2(ku, du, u, p, tnew) + @.. broadcast=false u=u + dt * ku + + # update velocity + tnew = tnew + half * dt + f.f1(kdu, du, u, p, tnew) + @.. broadcast=false du=du + dt * half * kdu + + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) + integrator.stats.nf2 += 1 + store_symp_state!(integrator, cache, kdu, ku) +end + @muladd function perform_step!(integrator, cache::Symplectic2ConstantCache, repeat_step = false) @unpack t, dt, f, p = integrator diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_tableaus.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_tableaus.jl index fd5acd6e61..61e791c57f 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_tableaus.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_tableaus.jl @@ -21,14 +21,6 @@ function McAte2ConstantCache(T, T2) Symplectic2ConstantCache{T, T2}(a1, a2, b1, b2) end -function VerletLeapfrogConstantCache(T, T2) - a1 = convert(T, 1 // 2) - a2 = convert(T, 1 // 2) - b1 = convert(T, 0) - b2 = convert(T, 1) - Symplectic2ConstantCache{T, T2}(a1, a2, b1, b2) -end - struct Symplectic3ConstantCache{T, T2} <: HamiltonConstantCache a1::T a2::T From c30d98796f299b48f32de1c3f9d0c99409ecc76c Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:18:52 +0100 Subject: [PATCH 144/203] Fix potentially uninitialized variables --- .../src/symplectic_perform_step.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index 178aecae84..1d37b2447d 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -199,9 +199,9 @@ end @muladd function perform_step!(integrator, cache::VerletLeapfrogConstantCache, repeat_step = false) @unpack t, dt, f, p = integrator - duprev, uprev, kduprev, kuprev = load_symp_state(integrator) + duprev, uprev, kduprev, _ = load_symp_state(integrator) - # kick-drift-kick scheme of the Verlet Leapfrog method: + # kick-drift-kick scheme of the Leapfrog method: # update velocity half = cache.half du = duprev + dt * half * kduprev @@ -223,7 +223,7 @@ end @muladd function perform_step!(integrator, cache::VerletLeapfrogCache, repeat_step = false) @unpack t, dt, f, p = integrator - duprev, uprev, kduprev, kuprev = load_symp_state(integrator) + duprev, uprev, kduprev, _ = load_symp_state(integrator) du, u, kdu, ku = alloc_symp_state(integrator) # Kick-Drift-Kick scheme of the Verlet Leapfrog method: @@ -233,8 +233,8 @@ end # update position tnew = t + half * dt - f.f2(ku, du, u, p, tnew) - @.. broadcast=false u=u + dt * ku + f.f2(ku, du, uprev, p, tnew) + @.. broadcast=false u=uprev + dt * ku # update velocity tnew = tnew + half * dt From 79fe875eeb2f2e71f9a62ccf19332a373c1fc9aa Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:47:41 +0100 Subject: [PATCH 145/203] Use linear interpolation by default --- lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl index cdbc53d2e1..596d66ee20 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl @@ -30,6 +30,8 @@ struct VelocityVerlet <: OrdinaryDiffEqPartitionedAlgorithm end verlet1967, "", "") struct VerletLeapfrog <: OrdinaryDiffEqPartitionedAlgorithm end +default_linear_interpolation(alg::VerletLeapfrog, prob) = true + @doc generic_solver_docstring("2nd order explicit symplectic integrator.", "PseudoVerletLeapfrog", "Symplectic Runge-Kutta Methods", From 3c7197bf3926ca23ca81ef7389f2ef0f0f345dd0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 19 Dec 2024 10:56:26 -0100 Subject: [PATCH 146/203] Update lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl --- lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl index 596d66ee20..c4cfce8af2 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl @@ -30,7 +30,7 @@ struct VelocityVerlet <: OrdinaryDiffEqPartitionedAlgorithm end verlet1967, "", "") struct VerletLeapfrog <: OrdinaryDiffEqPartitionedAlgorithm end -default_linear_interpolation(alg::VerletLeapfrog, prob) = true +OrdinaryDiffEqCore.default_linear_interpolation(alg::VerletLeapfrog, prob) = true @doc generic_solver_docstring("2nd order explicit symplectic integrator.", "PseudoVerletLeapfrog", From ac32012fe721beb2a12b92f080f06101456dfb74 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Fri, 20 Dec 2024 15:37:05 -0500 Subject: [PATCH 147/203] require SciMLBase versions with AliasSpecifiers --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bd6935f76f..d4d3a68cc8 100644 --- a/Project.toml +++ b/Project.toml @@ -133,7 +133,7 @@ PrecompileTools = "1" Preferences = "1.3" RecursiveArrayTools = "2.36, 3" Reexport = "1.0" -SciMLBase = "2.53.2" +SciMLBase = "2.69" SciMLOperators = "0.3" SciMLStructures = "1" SimpleNonlinearSolve = "1, 2" From 0bd7013007a464a33ad13ad3ea360052aee15785 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 21 Dec 2024 01:59:58 -0100 Subject: [PATCH 148/203] Update lib/OrdinaryDiffEqBDF/Project.toml --- lib/OrdinaryDiffEqBDF/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqBDF/Project.toml b/lib/OrdinaryDiffEqBDF/Project.toml index 78bd532385..41b60ad4fc 100644 --- a/lib/OrdinaryDiffEqBDF/Project.toml +++ b/lib/OrdinaryDiffEqBDF/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqBDF" uuid = "6ad6398a-0878-4a85-9266-38940aa047c8" authors = ["ParamThakkar123 "] -version = "1.2" +version = "1.2.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From ba3ced4f11f245f6739ed40c446c4705a4624c92 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Sat, 21 Dec 2024 02:12:21 -0100 Subject: [PATCH 149/203] Setup ADTypes release --- lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml | 2 -- .../src/OrdinaryDiffEqAdamsBashforthMoulton.jl | 1 - lib/OrdinaryDiffEqBDF/Project.toml | 3 ++- lib/OrdinaryDiffEqCore/Project.toml | 2 +- lib/OrdinaryDiffEqDefault/Project.toml | 3 ++- lib/OrdinaryDiffEqDifferentiation/Project.toml | 6 +++--- lib/OrdinaryDiffEqExponentialRK/Project.toml | 3 ++- lib/OrdinaryDiffEqExtrapolation/Project.toml | 3 ++- lib/OrdinaryDiffEqFIRK/Project.toml | 5 +++-- lib/OrdinaryDiffEqIMEXMultistep/Project.toml | 3 ++- lib/OrdinaryDiffEqPDIRK/Project.toml | 3 ++- lib/OrdinaryDiffEqRosenbrock/Project.toml | 6 +++--- lib/OrdinaryDiffEqSDIRK/Project.toml | 3 ++- lib/OrdinaryDiffEqStabilizedIRK/Project.toml | 3 ++- 14 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml index 1c1e832dab..5041384fed 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml @@ -4,7 +4,6 @@ authors = ["ParamThakkar123 "] version = "1.1.0" [deps] -ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" @@ -16,7 +15,6 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" [compat] -ADTypes = "1.7.1" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl index 1c26aac834..7350b58543 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/src/OrdinaryDiffEqAdamsBashforthMoulton.jl @@ -15,7 +15,6 @@ import OrdinaryDiffEqLowOrderRK: BS3ConstantCache, BS3Cache, RK4ConstantCache, R import RecursiveArrayTools: recursivefill! using MuladdMacro, FastBroadcast import Static: False -import ADTypes: AutoForwardDiff, AbstractADType import OrdinaryDiffEqCore using Reexport diff --git a/lib/OrdinaryDiffEqBDF/Project.toml b/lib/OrdinaryDiffEqBDF/Project.toml index 41b60ad4fc..f02261db32 100644 --- a/lib/OrdinaryDiffEqBDF/Project.toml +++ b/lib/OrdinaryDiffEqBDF/Project.toml @@ -23,6 +23,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77" [compat] +ADTypes = "1.11" ArrayInterface = "7.15.0" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" @@ -32,7 +33,7 @@ LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5.13" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" OrdinaryDiffEqSDIRK = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index 2b5faad3ba..fbbb0a903e 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.13.0" +version = "1.14.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/lib/OrdinaryDiffEqDefault/Project.toml b/lib/OrdinaryDiffEqDefault/Project.toml index 32759422cb..fe52df48ac 100644 --- a/lib/OrdinaryDiffEqDefault/Project.toml +++ b/lib/OrdinaryDiffEqDefault/Project.toml @@ -19,13 +19,14 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" EnumX = "1.0.4" LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" OrdinaryDiffEqBDF = "<0.0.1, 1" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqRosenbrock = "<0.0.1, 1" OrdinaryDiffEqTsit5 = "<0.0.1, 1" OrdinaryDiffEqVerner = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqDifferentiation/Project.toml b/lib/OrdinaryDiffEqDifferentiation/Project.toml index 11d8b4cfb0..720ed0fff0 100644 --- a/lib/OrdinaryDiffEqDifferentiation/Project.toml +++ b/lib/OrdinaryDiffEqDifferentiation/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqDifferentiation" uuid = "4302a76b-040a-498a-8c04-15b101fed76b" authors = ["Chris Rackauckas ", "Yingbo Ma "] -version = "1.2.0" +version = "1.3.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -21,7 +21,7 @@ StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] -ADTypes = "1" +ADTypes = "1.11" ArrayInterface = "7" DiffEqBase = "6" DiffEqDevTools = "2.44.4" @@ -31,7 +31,7 @@ ForwardDiff = "0.10" FunctionWrappersWrappers = "0.1" LinearAlgebra = "1.10" LinearSolve = "2" -OrdinaryDiffEqCore = "1.1" +OrdinaryDiffEqCore = "1.14" Random = "<0.0.1, 1" SafeTestsets = "0.1.0" SciMLBase = "2" diff --git a/lib/OrdinaryDiffEqExponentialRK/Project.toml b/lib/OrdinaryDiffEqExponentialRK/Project.toml index 34763c0607..d4c97e0ac0 100644 --- a/lib/OrdinaryDiffEqExponentialRK/Project.toml +++ b/lib/OrdinaryDiffEqExponentialRK/Project.toml @@ -19,6 +19,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" ExponentialUtilities = "1.26.1" @@ -26,7 +27,7 @@ FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.13" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqSDIRK = "<0.0.1, 1" OrdinaryDiffEqTsit5 = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqExtrapolation/Project.toml b/lib/OrdinaryDiffEqExtrapolation/Project.toml index f8d5829c70..8409e19cdd 100644 --- a/lib/OrdinaryDiffEqExtrapolation/Project.toml +++ b/lib/OrdinaryDiffEqExtrapolation/Project.toml @@ -17,13 +17,14 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" FastPower = "1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.13" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" Polyester = "0.7.16" Random = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqFIRK/Project.toml b/lib/OrdinaryDiffEqFIRK/Project.toml index 72ba71b59b..2fdc29edff 100644 --- a/lib/OrdinaryDiffEqFIRK/Project.toml +++ b/lib/OrdinaryDiffEqFIRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqFIRK" uuid = "5960d6e9-dd7a-4743-88e7-cf307b64f125" authors = ["ParamThakkar123 "] -version = "1.5.0" +version = "1.6.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -21,6 +21,7 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" @@ -30,7 +31,7 @@ LinearAlgebra = "<0.0.1, 1" LinearSolve = "2.32.0" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml index a207a3e0e2..afc8763088 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/Project.toml +++ b/lib/OrdinaryDiffEqIMEXMultistep/Project.toml @@ -13,10 +13,11 @@ OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqPDIRK/Project.toml b/lib/OrdinaryDiffEqPDIRK/Project.toml index 1357830781..25e7e58663 100644 --- a/lib/OrdinaryDiffEqPDIRK/Project.toml +++ b/lib/OrdinaryDiffEqPDIRK/Project.toml @@ -16,11 +16,12 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Polyester = "0.7.16" diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index 3ffa130076..d13bd3d5b0 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqRosenbrock" uuid = "43230ef6-c299-4910-a778-202eb28ce4ce" authors = ["ParamThakkar123 "] -version = "1.3.1" +version = "1.4.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -23,7 +23,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" [compat] -ADTypes = "1.7.1" +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" @@ -34,7 +34,7 @@ LinearSolve = "2.32.0" MacroTools = "0.5.13" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" Polyester = "0.7.16" PrecompileTools = "1.2.1" diff --git a/lib/OrdinaryDiffEqSDIRK/Project.toml b/lib/OrdinaryDiffEqSDIRK/Project.toml index 3800d52a50..46947d958b 100644 --- a/lib/OrdinaryDiffEqSDIRK/Project.toml +++ b/lib/OrdinaryDiffEqSDIRK/Project.toml @@ -19,13 +19,14 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5.13" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" diff --git a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml index c3916cc528..660cbb9961 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/Project.toml +++ b/lib/OrdinaryDiffEqStabilizedIRK/Project.toml @@ -16,12 +16,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [compat] +ADTypes = "1.11" DiffEqBase = "6.152.2" DiffEqDevTools = "2.44.4" FastBroadcast = "0.3.5" LinearAlgebra = "<0.0.1, 1" MuladdMacro = "0.2.4" -OrdinaryDiffEqCore = "1.11" +OrdinaryDiffEqCore = "1.14" OrdinaryDiffEqDifferentiation = "<0.0.1, 1.2" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" Random = "<0.0.1, 1" From c16dd2480634bdc2a0a327af40b2f9a1d24ec86c Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Sat, 21 Dec 2024 02:43:52 -0100 Subject: [PATCH 150/203] hotfix autodiff remaker --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- lib/OrdinaryDiffEqCore/src/algorithms.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index fbbb0a903e..544ad011fd 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.14.0" +version = "1.14.1" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/lib/OrdinaryDiffEqCore/src/algorithms.jl b/lib/OrdinaryDiffEqCore/src/algorithms.jl index eb1b774849..1b2a535467 100644 --- a/lib/OrdinaryDiffEqCore/src/algorithms.jl +++ b/lib/OrdinaryDiffEqCore/src/algorithms.jl @@ -61,7 +61,7 @@ function DiffEqBase.remake( kwargs...) where {CS, AD, FDT, ST, CJ} T = SciMLBase.remaker_of(thing) T(; SciMLBase.struct_as_namedtuple(thing)..., - chunk_size = Val{CS}(), autodiff = AD, standardtag = Val{ST}(), + chunk_size = Val{CS}(), autodiff = thing.autodiff, standardtag = Val{ST}(), concrete_jac = CJ === nothing ? CJ : Val{CJ}(), kwargs...) end From 87ff9ea6d44e5b58b6a93f31ddd7fc1e3d5d110c Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:19:51 +0100 Subject: [PATCH 151/203] Fix tests --- lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index 1d37b2447d..91fb8fc338 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -218,7 +218,7 @@ end OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) integrator.stats.nf2 += 1 - store_symp_state!(integrator, cache, kdu, ku) + store_symp_state!(integrator, cache, du, u, kdu, ku) end @muladd function perform_step!(integrator, cache::VerletLeapfrogCache, repeat_step = false) From c089d7f0b203418db288c59b933e5cc7727f879c Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 23 Dec 2024 10:40:55 +0100 Subject: [PATCH 152/203] Swap `isdefined` for `applicable` --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 1c887bc719..0f3716606f 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -50,7 +50,8 @@ function _initialize_dae!(integrator, prob::ODEProblem, if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) + elseif !applicable(_initialize_dae!, integrator, prob, + BrownFullBasicInit(integrator.opts.abstol), x) error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") else _initialize_dae!(integrator, prob, @@ -63,7 +64,9 @@ function _initialize_dae!(integrator, prob::DAEProblem, if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif !isdefined(Main, :OrdinaryDiffEqNonlinearSolve) + elseif !applicable(_initialize_dae!, integrator, prob, + BrownFullBasicInit(), x) && !applicable(_initialize_dae!, + integrator, prob, ShampineCollocationInit(), x) error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") elseif prob.differential_vars === nothing _initialize_dae!(integrator, prob, From 6ae5b607a651ce6857038a72383c87589fb7cc7f Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Thu, 2 Jan 2025 19:08:24 +0100 Subject: [PATCH 153/203] Implement drift-kick-drift form of the Leapfrog method --- docs/src/dynamicalodeexplicit/SymplecticRK.md | 1 + .../src/OrdinaryDiffEqSymplecticRK.jl | 4 +- .../src/alg_utils.jl | 1 + .../src/algorithms.jl | 28 ++++++- .../src/symplectic_caches.jl | 34 +++++++- .../src/symplectic_perform_step.jl | 81 +++++++++++++++++-- .../test/symplectic_convergence.jl | 31 +++++++ .../test/symplectic_tests.jl | 1 + src/OrdinaryDiffEq.jl | 4 +- 9 files changed, 171 insertions(+), 14 deletions(-) diff --git a/docs/src/dynamicalodeexplicit/SymplecticRK.md b/docs/src/dynamicalodeexplicit/SymplecticRK.md index cd35b08e1b..7ff5ad1c02 100644 --- a/docs/src/dynamicalodeexplicit/SymplecticRK.md +++ b/docs/src/dynamicalodeexplicit/SymplecticRK.md @@ -47,6 +47,7 @@ sol = solve(prob, KahanLi8(), dt = 1 / 10) SymplecticEuler VelocityVerlet VerletLeapfrog +LeapfrogDriftKickDrift PseudoVerletLeapfrog McAte2 Ruth3 diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/OrdinaryDiffEqSymplecticRK.jl b/lib/OrdinaryDiffEqSymplecticRK/src/OrdinaryDiffEqSymplecticRK.jl index c100a75215..f3700520ea 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/OrdinaryDiffEqSymplecticRK.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/OrdinaryDiffEqSymplecticRK.jl @@ -25,8 +25,8 @@ include("symplectic_caches.jl") include("symplectic_tableaus.jl") include("symplectic_perform_step.jl") -export SymplecticEuler, VelocityVerlet, VerletLeapfrog, PseudoVerletLeapfrog, - McAte2, Ruth3, McAte3, CandyRoz4, McAte4, McAte42, McAte5, +export SymplecticEuler, VelocityVerlet, VerletLeapfrog, LeapfrogDriftKickDrift, + PseudoVerletLeapfrog, McAte2, Ruth3, McAte3, CandyRoz4, McAte4, McAte42, McAte5, CalvoSanz4, Yoshida6, KahanLi6, McAte8, KahanLi8, SofSpa10 end diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/alg_utils.jl b/lib/OrdinaryDiffEqSymplecticRK/src/alg_utils.jl index e6d418bb8a..e39a4d34f0 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/alg_utils.jl @@ -1,6 +1,7 @@ alg_order(alg::SymplecticEuler) = 1 alg_order(alg::VelocityVerlet) = 2 alg_order(alg::VerletLeapfrog) = 2 +alg_order(alg::LeapfrogDriftKickDrift) = 2 alg_order(alg::PseudoVerletLeapfrog) = 2 alg_order(alg::McAte2) = 2 alg_order(alg::Ruth3) = 3 diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl index c4cfce8af2..3d4965ac98 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/algorithms.jl @@ -24,14 +24,38 @@ publisher={APS} verlet1967, "", "") struct VelocityVerlet <: OrdinaryDiffEqPartitionedAlgorithm end -@doc generic_solver_docstring("2nd order explicit symplectic integrator.", +monaghan2005 = """ +@article{monaghan2005, + title = {Smoothed particle hydrodynamics}, + author = {Monaghan, Joseph J.}, + year = {2005}, + journal = {Reports on Progress in Physics}, + volume = {68}, + number = {8}, + pages = {1703--1759}, + doi = {10.1088/0034-4885/68/8/R01}, +} +""" + +@doc generic_solver_docstring( + "2nd order explicit symplectic integrator. Kick-drift-kick form. Requires only one evaluation of `f1` per step.", "VerletLeapfrog", "Symplectic Runge-Kutta Methods", - verlet1967, "", "") + monaghan2005, "", "") struct VerletLeapfrog <: OrdinaryDiffEqPartitionedAlgorithm end OrdinaryDiffEqCore.default_linear_interpolation(alg::VerletLeapfrog, prob) = true +@doc generic_solver_docstring( + "2nd order explicit symplectic integrator. Drift-kick-drift form of `VerletLeapfrog` +designed to work when `f1` depends on `v`. Requires two evaluation of `f1` per step.", + "LeapfrogDriftKickDrift", + "Symplectic Runge-Kutta Methods", + monaghan2005, "", "") +struct LeapfrogDriftKickDrift <: OrdinaryDiffEqPartitionedAlgorithm end + +OrdinaryDiffEqCore.default_linear_interpolation(alg::LeapfrogDriftKickDrift, prob) = true + @doc generic_solver_docstring("2nd order explicit symplectic integrator.", "PseudoVerletLeapfrog", "Symplectic Runge-Kutta Methods", diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl index 16c8e4f4e3..e9b0ca838c 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl @@ -57,6 +57,38 @@ function alg_cache(alg::VelocityVerlet, u, rate_prototype, ::Type{uEltypeNoUnits VelocityVerletConstantCache(uEltypeNoUnits(1 // 2)) end +@cache struct LeapfrogDriftKickDriftCache{uType, rateType, uEltypeNoUnits} <: + OrdinaryDiffEqMutableCache + u::uType + uprev::uType + tmp::uType + k::rateType + fsalfirst::rateType + half::uEltypeNoUnits +end + +struct LeapfrogDriftKickDriftConstantCache{uEltypeNoUnits} <: HamiltonConstantCache + half::uEltypeNoUnits +end + +function alg_cache(alg::LeapfrogDriftKickDrift, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + tmp = zero(rate_prototype) + k = zero(rate_prototype) + fsalfirst = zero(rate_prototype) + half = uEltypeNoUnits(1 // 2) + LeapfrogDriftKickDriftCache(u, uprev, k, tmp, fsalfirst, half) +end + +function alg_cache(alg::LeapfrogDriftKickDrift, u, rate_prototype, ::Type{uEltypeNoUnits}, + ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, + dt, reltol, p, calck, + ::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} + LeapfrogDriftKickDriftConstantCache(uEltypeNoUnits(1 // 2)) +end + @cache struct VerletLeapfrogCache{uType, rateType, uEltypeNoUnits} <: OrdinaryDiffEqMutableCache u::uType @@ -436,6 +468,6 @@ end function get_fsalfirstlast( cache::Union{HamiltonMutableCache, VelocityVerletCache, VerletLeapfrogCache, - SymplecticEulerCache}, u) + SymplecticEulerCache, LeapfrogDriftKickDriftCache}, u) (cache.fsalfirst, cache.k) end diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index 91fb8fc338..c8e8d5b3d9 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -78,11 +78,13 @@ end # If called with different functions (which are possible in the Hamiltonian case) # an exception is thrown to avoid silently calculate wrong results. function verify_f2(f, p, q, pa, t, ::Any, - ::C) where {C <: Union{HamiltonConstantCache, VerletLeapfrogConstantCache}} + ::C) where {C <: Union{HamiltonConstantCache, VerletLeapfrogConstantCache, + LeapfrogDriftKickDriftConstantCache}} f(p, q, pa, t) end function verify_f2(f, res, p, q, pa, t, ::Any, - ::C) where {C <: Union{HamiltonMutableCache, VerletLeapfrogCache}} + ::C) where {C <: Union{HamiltonMutableCache, VerletLeapfrogCache, + LeapfrogDriftKickDriftCache}} f(res, p, q, pa, t) end @@ -128,8 +130,8 @@ function store_symp_state!(integrator, ::OrdinaryDiffEqMutableCache, kdu, ku) end function initialize!(integrator, - cache::C) where {C <: Union{ - HamiltonMutableCache, VelocityVerletCache, VerletLeapfrogCache}} + cache::C) where {C <: Union{HamiltonMutableCache, VelocityVerletCache, + VerletLeapfrogCache, LeapfrogDriftKickDriftCache}} integrator.kshortsize = 2 resize!(integrator.k, integrator.kshortsize) integrator.k[1] = integrator.fsalfirst @@ -144,8 +146,8 @@ function initialize!(integrator, end function initialize!(integrator, - cache::C) where {C <: Union{ - HamiltonConstantCache, VelocityVerletConstantCache, VerletLeapfrogConstantCache}} + cache::C) where {C <: Union{HamiltonConstantCache, VelocityVerletConstantCache, + VerletLeapfrogConstantCache, LeapfrogDriftKickDriftConstantCache}} integrator.kshortsize = 2 integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) @@ -226,7 +228,7 @@ end duprev, uprev, kduprev, _ = load_symp_state(integrator) du, u, kdu, ku = alloc_symp_state(integrator) - # Kick-Drift-Kick scheme of the Verlet Leapfrog method: + # kick-drift-kick scheme of the Leapfrog method: # update velocity half = cache.half @.. broadcast=false du=duprev + dt * half * kduprev @@ -246,6 +248,71 @@ end store_symp_state!(integrator, cache, kdu, ku) end +@muladd function perform_step!(integrator, cache::LeapfrogDriftKickDriftConstantCache, + repeat_step = false) + @unpack t, dt, f, p = integrator + duprev, uprev, _, _ = load_symp_state(integrator) + + # drift-kick-drift scheme of the Leapfrog method, allowing for f1 to depend on v: + # update position half step + half = cache.half + ku = f.f2(duprev, uprev, p, t) + u = uprev + dt * half * ku + + # update velocity half step + kdu = f.f1(duprev, u, p, t) + du = duprev + dt * half * kdu + + # full step + tnew = t + half * dt + + # update velocity (add to previous full step velocity) + # note that this extra step is only necessary if f1 depends on v/du (or t) + kdu = f.f1(du, u, p, tnew) + du = duprev + dt * kdu + + # update position (add to half step position) + ku = f.f2(du, u, p, tnew) + u = u + dt * half * ku + + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) + integrator.stats.nf2 += 2 + store_symp_state!(integrator, cache, du, u, kdu, ku) +end + +@muladd function perform_step!(integrator, cache::LeapfrogDriftKickDriftCache, + repeat_step = false) + @unpack t, dt, f, p = integrator + duprev, uprev, _, _ = load_symp_state(integrator) + du, u, kdu, ku = alloc_symp_state(integrator) + + # drift-kick-drift scheme of the Leapfrog method, allowing for f1 to depend on v: + # update position half step + half = cache.half + f.f2(ku, duprev, uprev, p, t) + @.. broadcast=false u=uprev + dt * half * ku + + # update velocity half step + f.f1(kdu, duprev, u, p, t) + @.. broadcast=false du=duprev + dt * half * kdu + + # full step + tnew = t + half * dt + + # update velocity (add to previous full step velocity) + # note that this extra step is only necessary if f1 depends on v/du (or t) + f.f1(kdu, du, u, p, tnew) + @.. broadcast=false du=duprev + dt * kdu + + # update position (add to half step position) + f.f2(ku, du, u, p, tnew) + @.. broadcast=false u=u + dt * half * ku + + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) + integrator.stats.nf2 += 2 + store_symp_state!(integrator, cache, kdu, ku) +end + @muladd function perform_step!(integrator, cache::Symplectic2ConstantCache, repeat_step = false) @unpack t, dt, f, p = integrator diff --git a/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_convergence.jl b/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_convergence.jl index 0939c97897..c303ee0799 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_convergence.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_convergence.jl @@ -62,6 +62,9 @@ position_error = :final => [mean(sim[i].u[2].x[1] - sim[i].u_analytic[2].x[1]) sim = test_convergence(dts, prob, VerletLeapfrog(), dense_errors = true) @test sim.𝒪est[:l2]≈2 rtol=1e-1 @test sim.𝒪est[:L2]≈2 rtol=1e-1 +sim = test_convergence(dts, prob, LeapfrogDriftKickDrift(), dense_errors = true) +@test sim.𝒪est[:l2]≈2 rtol=1e-1 +@test sim.𝒪est[:L2]≈2 rtol=1e-1 sim = test_convergence(dts, prob, PseudoVerletLeapfrog(), dense_errors = true) @test sim.𝒪est[:l2]≈2 rtol=1e-1 @test sim.𝒪est[:L2]≈2 rtol=1e-1 @@ -151,6 +154,9 @@ position_error = :final => [mean(sim[i].u[2].x[1] - sim[i].u_analytic[2].x[1]) sim = test_convergence(dts, prob, VerletLeapfrog(), dense_errors = true) @test sim.𝒪est[:l2]≈2 rtol=1e-1 @test sim.𝒪est[:L2]≈2 rtol=1e-1 +sim = test_convergence(dts, prob, LeapfrogDriftKickDrift(), dense_errors = true) +@test sim.𝒪est[:l2]≈2 rtol=1e-1 +@test sim.𝒪est[:L2]≈2 rtol=1e-1 sim = test_convergence(dts, prob, PseudoVerletLeapfrog(), dense_errors = true) @test sim.𝒪est[:l2]≈2 rtol=1e-1 @test sim.𝒪est[:L2]≈2 rtol=1e-1 @@ -202,3 +208,28 @@ dts = 1.0 ./ 2.0 .^ (2:-1:-2) sim = test_convergence(dts, prob, SofSpa10(), dense_errors = true) @test sim.𝒪est[:l2]≈10 rtol=1e-1 @test sim.𝒪est[:L2]≈4 rtol=1e-1 + +################# f1 dependent on v + +println("f1 dependent on v") + +u0 = fill(0.0, 2) +v0 = ones(2) +function f1_v(dv, v, u, p, t) + dv .= v +end +function f2_v(du, v, u, p, t) + du .= v +end +function f_v_analytic(y0, p, x) + v0, u0 = y0.x + ArrayPartition(v0 * exp(x), v0 * exp(x) - v0 + u0) +end +ff_v = DynamicalODEFunction(f1_v, f2_v; analytic = f_v_analytic) +prob = DynamicalODEProblem(ff_v, v0, u0, (0.0, 5.0)) + +dts = 1 .// 2 .^ (6:-1:3) +# LeapfrogDriftKickDrift +sim = test_convergence(dts, prob, LeapfrogDriftKickDrift(), dense_errors = true) +@test sim.𝒪est[:l2]≈2 rtol=1e-1 +@test sim.𝒪est[:L2]≈2 rtol=1e-1 diff --git a/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl b/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl index e1771678b2..32b2a8f52a 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl @@ -7,6 +7,7 @@ using OrdinaryDiffEqRKN const ALGOS = ((SymplecticEuler, true, 1), (VelocityVerlet, false, 2), (VerletLeapfrog, true, 2), + (LeapfrogDriftKickDrift, true, 2), (PseudoVerletLeapfrog, true, 2), (McAte2, true, 2), (Ruth3, true, 3), diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index f6578c3bde..9dac13762a 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -113,8 +113,8 @@ using OrdinaryDiffEqFeagin export Feagin10, Feagin12, Feagin14 using OrdinaryDiffEqSymplecticRK -export SymplecticEuler, VelocityVerlet, VerletLeapfrog, PseudoVerletLeapfrog, - McAte2, Ruth3, McAte3, CandyRoz4, McAte4, McAte42, McAte5, +export SymplecticEuler, VelocityVerlet, VerletLeapfrog, LeapfrogDriftKickDrift, + PseudoVerletLeapfrog, McAte2, Ruth3, McAte3, CandyRoz4, McAte4, McAte42, McAte5, CalvoSanz4, Yoshida6, KahanLi6, McAte8, KahanLi8, SofSpa10 using OrdinaryDiffEqRKN From fc416268680fb7f0c9f6c3700af203170dd51119 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Fri, 3 Jan 2025 09:37:49 +0100 Subject: [PATCH 154/203] Fix velocity half step --- lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index c8e8d5b3d9..169d13bad2 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -260,7 +260,7 @@ end u = uprev + dt * half * ku # update velocity half step - kdu = f.f1(duprev, u, p, t) + kdu = f.f1(duprev, uprev, p, t) du = duprev + dt * half * kdu # full step @@ -293,7 +293,7 @@ end @.. broadcast=false u=uprev + dt * half * ku # update velocity half step - f.f1(kdu, duprev, u, p, t) + f.f1(kdu, duprev, uprev, p, t) @.. broadcast=false du=duprev + dt * half * kdu # full step From f39236786b7e8cee5c3e3eaf4a3424dc3d769e6d Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Fri, 3 Jan 2025 09:48:23 +0100 Subject: [PATCH 155/203] Fix time dependence --- .../src/symplectic_perform_step.jl | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl index 169d13bad2..fcbf00b2f1 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl +++ b/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_perform_step.jl @@ -209,13 +209,11 @@ end du = duprev + dt * half * kduprev # update position - tnew = t + half * dt - ku = f.f2(du, uprev, p, tnew) + ku = f.f2(du, uprev, p, t + half * dt) u = uprev + dt * ku # update velocity - tnew = tnew + half * dt - kdu = f.f1(du, u, p, tnew) + kdu = f.f1(du, u, p, t + dt) du = du + dt * half * kdu OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) @@ -234,13 +232,11 @@ end @.. broadcast=false du=duprev + dt * half * kduprev # update position - tnew = t + half * dt - f.f2(ku, du, uprev, p, tnew) + f.f2(ku, du, uprev, p, t + half * dt) @.. broadcast=false u=uprev + dt * ku # update velocity - tnew = tnew + half * dt - f.f1(kdu, du, u, p, tnew) + f.f1(kdu, du, u, p, t + dt) @.. broadcast=false du=du + dt * half * kdu OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) @@ -263,16 +259,13 @@ end kdu = f.f1(duprev, uprev, p, t) du = duprev + dt * half * kdu - # full step - tnew = t + half * dt - # update velocity (add to previous full step velocity) # note that this extra step is only necessary if f1 depends on v/du (or t) - kdu = f.f1(du, u, p, tnew) + kdu = f.f1(du, u, p, t + half * dt) du = duprev + dt * kdu # update position (add to half step position) - ku = f.f2(du, u, p, tnew) + ku = f.f2(du, u, p, t + dt) u = u + dt * half * ku OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) @@ -296,16 +289,13 @@ end f.f1(kdu, duprev, uprev, p, t) @.. broadcast=false du=duprev + dt * half * kdu - # full step - tnew = t + half * dt - # update velocity (add to previous full step velocity) # note that this extra step is only necessary if f1 depends on v/du (or t) - f.f1(kdu, du, u, p, tnew) + f.f1(kdu, du, u, p, t + half * dt) @.. broadcast=false du=duprev + dt * kdu # update position (add to half step position) - f.f2(ku, du, u, p, tnew) + f.f2(ku, du, u, p, t + dt) @.. broadcast=false u=u + dt * half * ku OrdinaryDiffEqCore.increment_nf!(integrator.stats, 2) From bb946eeae816cc4a08106f34da0fbceaf9938a0b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 3 Jan 2025 12:12:58 -0100 Subject: [PATCH 156/203] Update Project.toml --- lib/OrdinaryDiffEqSymplecticRK/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/Project.toml b/lib/OrdinaryDiffEqSymplecticRK/Project.toml index 9c32d09c76..ef28c39fce 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/Project.toml +++ b/lib/OrdinaryDiffEqSymplecticRK/Project.toml @@ -26,7 +26,7 @@ Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" Reexport = "1.2.2" SafeTestsets = "0.1.0" -Statistics = "1.11.1" +Statistics = "<0.0.1, 1" Test = "<0.0.1, 1" julia = "1.10" From 4ae256cd435263fb9b7bd83d8d3b5a26e07594a4 Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Sat, 4 Jan 2025 08:10:13 +0000 Subject: [PATCH 157/203] CompatHelper: bump compat for Zygote to 0.7 for package downstream, (keep existing compat) --- test/downstream/Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/downstream/Project.toml b/test/downstream/Project.toml index 6f934b345f..7dd1b77444 100644 --- a/test/downstream/Project.toml +++ b/test/downstream/Project.toml @@ -2,7 +2,7 @@ DDEProblemLibrary = "f42792ee-6ffc-4e2a-ae83-8ee2f22de800" DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb" Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" -OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" @@ -16,4 +16,4 @@ OrdinaryDiffEq = "6" SciMLSensitivity = "7.30" StaticArrays = "1" StochasticDiffEq = "6.60.1" -Zygote = "0.6.61" +Zygote = "0.6.61, 0.7" From 1e3cb2a4996c7204fcf116f4868b4446febe654c Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Sat, 4 Jan 2025 08:18:24 +0000 Subject: [PATCH 158/203] CompatHelper: bump compat for Zygote to 0.7 for package downstream, (keep existing compat) --- test/downstream/Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/downstream/Project.toml b/test/downstream/Project.toml index 6f934b345f..7dd1b77444 100644 --- a/test/downstream/Project.toml +++ b/test/downstream/Project.toml @@ -2,7 +2,7 @@ DDEProblemLibrary = "f42792ee-6ffc-4e2a-ae83-8ee2f22de800" DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb" Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" -OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" @@ -16,4 +16,4 @@ OrdinaryDiffEq = "6" SciMLSensitivity = "7.30" StaticArrays = "1" StochasticDiffEq = "6.60.1" -Zygote = "0.6.61" +Zygote = "0.6.61, 0.7" From b851921909e356529827d0340cb18e399852bbab Mon Sep 17 00:00:00 2001 From: Collin Wittenstein Date: Thu, 9 Jan 2025 13:07:01 +0100 Subject: [PATCH 159/203] added AdaptiveRadau and RadauIIA9 to step_limiter_test.jl --- test/integrators/step_limiter_test.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integrators/step_limiter_test.jl b/test/integrators/step_limiter_test.jl index 566d5da527..98ffe37126 100644 --- a/test/integrators/step_limiter_test.jl +++ b/test/integrators/step_limiter_test.jl @@ -26,8 +26,8 @@ end SDIRK2, SDIRK22, ABDF2, Feagin10, Feagin12, Feagin14, KenCarp3, KenCarp4, KenCarp5, Kvaerno3, Kvaerno4, Kvaerno5, Rosenbrock23, Rosenbrock32, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, - Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, - RadauIIA5, RadauIIA3, SIR54, Alshina2, Alshina3, Heun, Ralston, Midpoint, RK4, + Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, + AdaptiveRadau, RadauIIA9, RadauIIA5, RadauIIA3, SIR54, Alshina2, Alshina3, Heun, Ralston, Midpoint, RK4, OwrenZen3, OwrenZen4, OwrenZen5, BS3, DP5, Tsit5, DP8, TanYam7, TsitPap8, FRK65, PFRK87, BS5, Vern6, Vern7, Vern8, Vern9, QPRK98, SSPRKMSVS43, SSPRKMSVS32, SSPRK432, SSPRK43, From aec394a071daef7ffab0db762c0cad17d31b0c9e Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Fri, 10 Jan 2025 16:02:19 +0100 Subject: [PATCH 160/203] Re-add accidentally disabled tests to gitlab CI --- .github/workflows/CI.yml | 1 + lib/OrdinaryDiffEqNonlinearSolve/Project.toml | 5 ++++- lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl | 2 ++ lib/OrdinaryDiffEqNonlinearSolve/test/runtests.jl | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 296ae17352..a3cc456f4e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -41,6 +41,7 @@ jobs: - OrdinaryDiffEqLinear - OrdinaryDiffEqLowOrderRK - OrdinaryDiffEqLowStorageRK + - OrdinaryDiffEqNonlinearSolve - OrdinaryDiffEqNordsieck - OrdinaryDiffEqPDIRK - OrdinaryDiffEqPRK diff --git a/lib/OrdinaryDiffEqNonlinearSolve/Project.toml b/lib/OrdinaryDiffEqNonlinearSolve/Project.toml index 27bbe7ff3d..e93d789ca7 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/Project.toml +++ b/lib/OrdinaryDiffEqNonlinearSolve/Project.toml @@ -52,9 +52,12 @@ julia = "1.10" [extras] DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d" +LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" +ODEProblemLibrary = "fdc4e326-1af4-4b90-96e7-779fcce2daa5" +OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test"] +test = ["DiffEqDevTools", "LineSearches", "ODEProblemLibrary", "OrdinaryDiffEqSDIRK", "Random", "SafeTestsets", "Test"] diff --git a/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl b/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl index bbb78122c8..efac009927 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl @@ -1,4 +1,6 @@ +using OrdinaryDiffEqNonlinearSolve: NLNewton using OrdinaryDiffEqCore +using OrdinaryDiffEqSDIRK using DiffEqDevTools using DiffEqBase using LineSearches diff --git a/lib/OrdinaryDiffEqNonlinearSolve/test/runtests.jl b/lib/OrdinaryDiffEqNonlinearSolve/test/runtests.jl index 37192c8dbf..8f1738e67a 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/test/runtests.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/test/runtests.jl @@ -1,3 +1,3 @@ using SafeTestsets -@time @safetestset "Newton Tests" include("interface/newton_tests.jl") +@time @safetestset "Newton Tests" include("newton_tests.jl") From 1a540844d902f8c02d4edf4edc3498ab1b7a9174 Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Sat, 11 Jan 2025 22:24:38 +0100 Subject: [PATCH 161/203] Fix test in OrdinaryDiffEqNonlinearSolve: loosen assertion tolerance --- lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl b/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl index efac009927..05c62cedbd 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl @@ -14,5 +14,5 @@ for prob in (prob_ode_lorenz, prob_ode_orego) sol2 = solve(prob, Trapezoid(nlsolve = NLNewton(relax = BackTracking())), reltol = 1e-12, abstol = 1e-12) @test sol2.retcode == DiffEqBase.ReturnCode.Success - @test sol2.stats.nf <= sol1.stats.nf + @test abs(sol2.stats.nf - sol1.stats.nf) <= 20 end From decbeb2084524097b1ad83662f9d4b01fe1d5d0a Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Thu, 16 Jan 2025 13:37:26 +0530 Subject: [PATCH 162/203] feat: support initialization of `DiscreteProblem` --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 0034e55d9a..2d33ba0472 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -94,6 +94,14 @@ function _initialize_dae!(integrator, prob::DAEProblem, end end +function _initialize_dae!(integrator, prob::DiscreteProblem, + alg::DefaultInit, x::Union{Val{true}, Val{false}}) + if SciMLBase.has_initializeprob(prob.f) + # integrator.opts.abstol is `false` for `DiscreteProblem`. + _initialize_dae!(integrator, prob, OverrideInit(one(eltype(prob.u0)) * 1e-6), x) + end +end + ## Nonlinear Solver Defaulting ## If an alg is given use it From ced85cbcf0f9ddb7e3c4830f693816e6bf73ef32 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 16 Jan 2025 14:33:26 +0100 Subject: [PATCH 163/203] Update Downstream.yml --- .github/workflows/Downstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 9ebbc15439..9938044eb7 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -74,5 +74,5 @@ jobs: - uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - file: lcov.info + files: lcov.info fail_ci_if_error: false From 5f6ee4b03bd287a7673866ee0574d246d346f4f8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 17 Jan 2025 10:58:10 +0100 Subject: [PATCH 164/203] Update lib/OrdinaryDiffEqCore/src/initialize_dae.jl --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 2d33ba0472..15f22fab7a 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -98,7 +98,7 @@ function _initialize_dae!(integrator, prob::DiscreteProblem, alg::DefaultInit, x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) # integrator.opts.abstol is `false` for `DiscreteProblem`. - _initialize_dae!(integrator, prob, OverrideInit(one(eltype(prob.u0)) * 1e-6), x) + _initialize_dae!(integrator, prob, OverrideInit(one(eltype(prob.u0)) * 1e-12), x) end end From 5868c5bb9ee4a9a41846adac85e075e71ab3faeb Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 17 Jan 2025 16:40:59 +0530 Subject: [PATCH 165/203] build: bump `OrdinaryDiffEqCore` minor version --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index 544ad011fd..36955ac298 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.14.1" +version = "1.15.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From 0d9631e2e7b1eb35b93c5e6aaff7bc58b5aa3ab2 Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Tue, 21 Jan 2025 20:24:01 +0100 Subject: [PATCH 166/203] Removed --threads=auto flag from testing step to avoid bug in JuliaLang#56458 --- .buildkite/pipeline.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 200127f7ef..9ea8c42ef9 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -49,7 +49,6 @@ steps: ' - JuliaCI/julia-test#v1: coverage: false - julia_args: "--threads=auto" agents: os: "linux" queue: "juliaecosystem" From b3fec9d1e018af7998fd53b98c111c9e57812373 Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Tue, 21 Jan 2025 23:22:32 +0100 Subject: [PATCH 167/203] Re-implement multithreading at outer scope for CI. --- .buildkite/pipeline.yml | 1 + test/multithreading/ode_extrapolation_tests.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 9ea8c42ef9..54acf46f22 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -49,6 +49,7 @@ steps: ' - JuliaCI/julia-test#v1: coverage: false + command: 'export JULIA_NUM_THREADS=2' agents: os: "linux" queue: "juliaecosystem" diff --git a/test/multithreading/ode_extrapolation_tests.jl b/test/multithreading/ode_extrapolation_tests.jl index 765471eb9e..ae157b0222 100644 --- a/test/multithreading/ode_extrapolation_tests.jl +++ b/test/multithreading/ode_extrapolation_tests.jl @@ -1,6 +1,8 @@ # Import packages using OrdinaryDiffEqExtrapolation, DiffEqDevTools, Test, Random +println("Running on $(Threads.nthreads()) thread(s).") + # Define test problems # Note that the time span in ODEProblemLibrary is given by # Float64 numbers From 6efeb3b2cae206caf1a5b1fe892c397b1dd5a3e4 Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Tue, 21 Jan 2025 23:51:25 +0100 Subject: [PATCH 168/203] CI: Set JULIA_NUM_THREADS in env section of pipeline.yml --- .buildkite/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 54acf46f22..77516da6f1 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -38,6 +38,7 @@ steps: env: BUILDKITE_PLUGIN_JULIA_VERSION: "{{matrix.version}}" GROUP: "{{matrix.group}}" + JULIA_NUM_THREADS: 2 plugins: - JuliaCI/julia#v1 - staticfloat/metahook: @@ -49,7 +50,6 @@ steps: ' - JuliaCI/julia-test#v1: coverage: false - command: 'export JULIA_NUM_THREADS=2' agents: os: "linux" queue: "juliaecosystem" From 1a8e123f456a1bd7d031d38e6cc0d6b2c9ed5eda Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Fri, 24 Jan 2025 09:08:09 -0500 Subject: [PATCH 169/203] threading --- lib/OrdinaryDiffEqFIRK/Project.toml | 2 + .../src/OrdinaryDiffEqFIRK.jl | 6 +-- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 9 ++-- .../src/firk_perform_step.jl | 48 +++++++++++++++---- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/Project.toml b/lib/OrdinaryDiffEqFIRK/Project.toml index 62fc014d3c..037bbd5baa 100644 --- a/lib/OrdinaryDiffEqFIRK/Project.toml +++ b/lib/OrdinaryDiffEqFIRK/Project.toml @@ -14,6 +14,7 @@ MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221" OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" OrdinaryDiffEqDifferentiation = "4302a76b-040a-498a-8c04-15b101fed76b" OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8" +Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" @@ -32,6 +33,7 @@ ODEProblemLibrary = "0.1.8" OrdinaryDiffEqCore = "1.1" OrdinaryDiffEqDifferentiation = "<0.0.1, 1" OrdinaryDiffEqNonlinearSolve = "<0.0.1, 1" +Polyester = "0.7.16" Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" Reexport = "1.2.2" diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 5817abd9b7..dd10be9004 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -6,8 +6,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqNewtonAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, OrdinaryDiffEqAdaptiveAlgorithm, CompiledFloats, uses_uprev, - alg_cache, _vec, _reshape, @cache, isfsal, full_cache, - constvalue, _unwrap_val, + alg_cache, _vec, _reshape, @cache, @threaded, isthreaded, PolyesterThreads, + isfsal, full_cache, constvalue, _unwrap_val, differentiation_rk_docstring, trivial_limiter!, _ode_interpolant!, _ode_addsteps!, AbstractController, qmax_default, alg_adaptive_order, DEFAULT_PRECS, @@ -17,7 +17,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, fac_default_gamma, get_current_adaptive_order, get_fsalfirstlast, isfirk, generic_solver_docstring -using MuladdMacro, DiffEqBase, RecursiveArrayTools +using MuladdMacro, DiffEqBase, RecursiveArrayTools, Polyester using SciMLOperators: AbstractSciMLOperator using LinearAlgebra: I, UniformScaling, mul!, lu import LinearSolve diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index e98389ec7c..6daa64487a 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -151,7 +151,7 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = Val{true}(), step_limiter!) end -struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: +struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter, TO} <: OrdinaryDiffEqNewtonAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} linsolve::F precs::P @@ -165,11 +165,12 @@ struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter} <: step_limiter!::StepLimiter min_order::Int max_order::Int + threading::TO end function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = Val{true}(), standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, min_order = 5, max_order = 13, + diff_type = Val{:forward}, min_order = 5, max_order = 13, threading = false, linsolve = nothing, precs = DEFAULT_PRECS, extrapolant = :dense, fast_convergence_cutoff = 1 // 5, new_W_γdt_cutoff = 1 // 5, @@ -178,7 +179,7 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = Val{true}(), AdaptiveRadau{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), - typeof(new_W_γdt_cutoff), typeof(step_limiter!)}(linsolve, + typeof(new_W_γdt_cutoff), typeof(step_limiter!), typeof(threading)}(linsolve, precs, smooth_est, extrapolant, @@ -187,6 +188,6 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = Val{true}(), fast_convergence_cutoff, new_W_γdt_cutoff, controller, - step_limiter!, min_order, max_order) + step_limiter!, min_order, max_order, threading) end diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl index a85b63fb00..d72daf3508 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl @@ -1619,8 +1619,21 @@ end if (new_W = do_newW(integrator, alg, new_jac, cache.W_γdt)) @inbounds for II in CartesianIndices(J) W1[II] = -γdt * mass_matrix[Tuple(II)...] + J[II] - for i in 1 : (num_stages - 1) ÷ 2 - W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + J[II] + end + if !isthreaded(alg.threading) + @inbounds for II in CartesianIndices(J) + for i in 1 : (num_stages - 1) ÷ 2 + W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + J[II] + end + end + else + let W1 = W1, W2 = W2, γdt = γdt, αdt = αdt, βdt = βdt, mass_matrix = mass_matrix, + num_stages = num_stages, J = J + @inbounds @threaded alg.threading for i in 1 : (num_stages - 1) ÷ 2 + for II in CartesianIndices(J) + W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + J[II] + end + end end end integrator.stats.nw += 1 @@ -1706,16 +1719,30 @@ end cache.linsolve1 = dolinsolve(integrator, linsolve1; A = nothing, b = _vec(ubuff), linu = _vec(dw1)).cache end - for i in 1 :(num_stages - 1) ÷ 2 - @.. cubuff[i]=complex( - fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) - if needfactor - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache - else - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + if !isthreaded(alg.threading) + for i in 1 :(num_stages - 1) ÷ 2 + @.. cubuff[i]=complex(fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) + if needfactor + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + else + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + end + end + else + let integrator = integrator, linsolve2 = linsolve2, fw = fw, αdt = αdt, βdt = βdt, Mw = Mw, W1 = W1, W2 = W2, + cubuff = cubuff, dw2 = dw2, needfactor = needfactor + @threaded alg.threading for i in 1:(num_stages - 1) ÷ 2 + #@show i == Threads.threadid() + @.. cubuff[i]=complex(fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) + if needfactor + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + else + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + end + end end end - + integrator.stats.nsolve += (num_stages + 1) / 2 for i in 1 : (num_stages - 1) ÷ 2 @@ -1850,3 +1877,4 @@ end integrator.stats.nf += 1 return end + From 0bc767760ea4293a8550d7871076a32d75fa362b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 25 Jan 2025 05:36:04 -0500 Subject: [PATCH 170/203] Hotfix for ADTypes change --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 261a33354d..73295ef3ea 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -179,7 +179,7 @@ _get_fwd_chunksize_int(AD) = 0 _get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T _get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 -_get_fdtype(::Type{AutoFiniteDiff{T1,T2,T3}}) where {T1, T2, T3} = T1 +_get_fdtype(::Type{<:AutoFiniteDiff{T1,T2,T3}}) where {T1, T2, T3} = T1 function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, @@ -462,4 +462,4 @@ function Base.show(io::IO, ::MIME"text/plain", alg::OrdinaryDiffEqAlgorithm) end # Defaults in the current system: currently opt out DAEAlgorithms until complete -default_linear_interpolation(alg, prob) = alg isa DAEAlgorithm || prob isa DiscreteProblem \ No newline at end of file +default_linear_interpolation(alg, prob) = alg isa DAEAlgorithm || prob isa DiscreteProblem From fd82b8716c487fda10782c7de6f6c7c770ca898e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 25 Jan 2025 06:00:38 -0500 Subject: [PATCH 171/203] Update Project.toml --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index 36955ac298..e4137f1c28 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.15.0" +version = "1.15.1" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From b8ba9407c0b87f170678e59a7933ce3b68aa78f5 Mon Sep 17 00:00:00 2001 From: Hossein Pourbozorg Date: Sat, 25 Jan 2025 16:46:48 +0330 Subject: [PATCH 172/203] remove extra type parameters --- lib/OrdinaryDiffEqCore/src/alg_utils.jl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 261a33354d..f69a82d1af 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -172,15 +172,14 @@ function get_chunksize(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have a chunk size defined.") end -_get_fwd_chunksize(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = Val(CS) -_get_fwd_chunksize_int(::Type{AutoForwardDiff{CS, T}}) where {CS, T} = CS +_get_fwd_chunksize(::Type{<:AutoForwardDiff{CS}}) where {CS} = Val(CS) +_get_fwd_chunksize_int(::Type{<:AutoForwardDiff{CS}}) where {CS} = CS _get_fwd_chunksize(AD) = Val(0) _get_fwd_chunksize_int(AD) = 0 -_get_fwd_tag(::AutoForwardDiff{CS,T}) where {CS,T} = T - -_get_fdtype(::AutoFiniteDiff{T1, T2, T3}) where {T1, T2, T3} = T1 -_get_fdtype(::Type{AutoFiniteDiff{T1,T2,T3}}) where {T1, T2, T3} = T1 +_get_fwd_tag(::AutoForwardDiff{CS, T}) where {CS, T} = T +_get_fdtype(::AutoFiniteDiff{T1}) where {T1} = T1 +_get_fdtype(::Type{<:AutoFiniteDiff{T1}}) where {T1} = T1 function get_chunksize(alg::Union{OrdinaryDiffEqExponentialAlgorithm{CS, AD}, OrdinaryDiffEqAdaptiveExponentialAlgorithm{CS, AD}, @@ -237,8 +236,6 @@ function get_current_alg_autodiff(alg::CompositeAlgorithm, cache) _eval_index(alg_autodiff, alg.algs, cache.current)::Bool end - - function alg_difftype(alg::Union{ OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD, FDT, ST, CJ }, From 4d22d3d2c7bf4dbb9d2a2f52c4a22dffa554c1b4 Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Mon, 27 Jan 2025 17:32:22 -0500 Subject: [PATCH 173/203] fixes --- lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl | 4 ++-- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 5a29d39c10..6902e3088f 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -16,10 +16,10 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, PredictiveController, alg_can_repeat_jac, NewtonAlgorithm, fac_default_gamma, get_current_adaptive_order, get_fsalfirstlast, - isfirk, generic_solver_docstring -using MuladdMacro, DiffEqBase, RecursiveArrayTools, Polyester isfirk, generic_solver_docstring, _bool_to_ADType, _process_AD_choice +using MuladdMacro, DiffEqBase, RecursiveArrayTools, Polyester + isfirk, generic_solver_docstring using SciMLOperators: AbstractSciMLOperator using LinearAlgebra: I, UniformScaling, mul!, lu import LinearSolve diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 6752e58214..4975c3aad3 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -198,7 +198,7 @@ function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), typeof(κ), typeof(fast_convergence_cutoff), - typeof(new_W_γdt_cutoff), typeof(step_limiter!), typeof(threading), typeof(AD_choice)}(linsolve, + typeof(new_W_γdt_cutoff), typeof(step_limiter!), typeof(threading)}(linsolve, precs, smooth_est, extrapolant, From 02a5616a5c3db9fee5f6411eaca17edf935d299e Mon Sep 17 00:00:00 2001 From: Shreyas Ekanathan Date: Tue, 28 Jan 2025 17:37:14 -0500 Subject: [PATCH 174/203] add tests --- lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl index c8effacce4..29753d5e12 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl @@ -19,11 +19,19 @@ using GenericSchur prob_ode_linear_big = remake(prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), tspan = big.(prob_ode_2Dlinear.tspan)) +#non-threaded tests for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] dts = 1 ./ 2 .^ (4.25:-1:0.25) local sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i)) @test sim21.𝒪est[:final]≈ i atol=testTol end +#threaded tests +using OrdinaryDiffEqCore +for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] + dts = 1 ./ 2 .^ (4.25:-1:0.25) + local sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i, threading = OrdinaryDiffEqCore.PolyesterThreads())) + @test sim21.𝒪est[:final]≈ i atol=testTol +end # test adaptivity for iip in (true, false) @@ -68,4 +76,4 @@ for iip in (true, false) @test sol.stats.njacs < sol.stats.nw # W reuse end @test length(sol) < 5000 # the error estimate is not very good -end +end \ No newline at end of file From d005d06567d9f577cc3893884756bff9f122ff2a Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 5 Feb 2025 10:17:51 -0500 Subject: [PATCH 175/203] cleanup `step!` and make it return whether the step was sucessful As pointed out by https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581, there isn't currently a good way to check whether `step!` succeeds. This makes it return a bool for whether it worked, and also removes a bunch of `@inbounds` statements that don't do anything since `@inbounds` doesn't traverse function boundaries. --- .../src/iterator_interface.jl | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/iterator_interface.jl b/lib/OrdinaryDiffEqCore/src/iterator_interface.jl index 09828e042b..81d8256e3f 100644 --- a/lib/OrdinaryDiffEqCore/src/iterator_interface.jl +++ b/lib/OrdinaryDiffEqCore/src/iterator_interface.jl @@ -1,25 +1,26 @@ -@inline function step!(integrator::ODEIntegrator) +function step!(integrator::ODEIntegrator) if integrator.opts.advance_to_tstop - @inbounds while integrator.tdir * integrator.t < first(integrator.opts.tstops) + while integrator.tdir * integrator.t < first(integrator.opts.tstops) loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return + return false perform_step!(integrator, integrator.cache) loopfooter!(integrator) end else - @inbounds loopheader!(integrator) + loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return - @inbounds perform_step!(integrator, integrator.cache) - @inbounds loopfooter!(integrator) - @inbounds while !integrator.accept_step + return false + perform_step!(integrator, integrator.cache) + loopfooter!(integrator) + while !integrator.accept_step loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return + return false perform_step!(integrator, integrator.cache) loopfooter!(integrator) end end - @inbounds handle_tstop!(integrator) + handle_tstop!(integrator) + return true end From 86f84a796ac57a8f4f7338b62206b35c3afb1e4e Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 5 Feb 2025 12:50:08 -0500 Subject: [PATCH 176/203] return retcode rather than bool --- lib/OrdinaryDiffEqCore/src/iterator_interface.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/iterator_interface.jl b/lib/OrdinaryDiffEqCore/src/iterator_interface.jl index 81d8256e3f..66bdd67fb0 100644 --- a/lib/OrdinaryDiffEqCore/src/iterator_interface.jl +++ b/lib/OrdinaryDiffEqCore/src/iterator_interface.jl @@ -3,24 +3,24 @@ function step!(integrator::ODEIntegrator) while integrator.tdir * integrator.t < first(integrator.opts.tstops) loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return false + return integrator.sol.retcode perform_step!(integrator, integrator.cache) loopfooter!(integrator) end else loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return false + return integrator.sol.retcode perform_step!(integrator, integrator.cache) loopfooter!(integrator) while !integrator.accept_step loopheader!(integrator) (integrator.do_error_check && check_error!(integrator) != ReturnCode.Success) && - return false + return integrator.sol.retcode perform_step!(integrator, integrator.cache) loopfooter!(integrator) end end handle_tstop!(integrator) - return true + return integrator.sol.retcode end From 60b7d00f42b90abce015de7c9f37a21a7c6f1ddb Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Thu, 6 Feb 2025 01:35:56 +0000 Subject: [PATCH 177/203] CompatHelper: bump compat for LinearSolve to 3, (keep existing compat) --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d4d3a68cc8..ac33719bd4 100644 --- a/Project.toml +++ b/Project.toml @@ -92,7 +92,7 @@ FunctionWrappersWrappers = "0.1" InteractiveUtils = "1.9" LineSearches = "7" LinearAlgebra = "1.9" -LinearSolve = "2" +LinearSolve = "2, 3" Logging = "1.9" MacroTools = "0.5" MuladdMacro = "0.2.1" From de64d0905e8af9b0a4c49c54f2d0c7994ea750d0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Thu, 6 Feb 2025 04:48:31 -0800 Subject: [PATCH 178/203] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ac33719bd4..247b35fcaf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEq" uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" authors = ["Chris Rackauckas ", "Yingbo Ma "] -version = "6.90.1" +version = "6.91.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From c638ab9230bd1fec52927c295e2b02a3200c8ed0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 9 Feb 2025 08:24:30 -0800 Subject: [PATCH 179/203] Create unitfulvalue for compatibility with ForwardDiff removal --- lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl index e92e309c5c..bcfbfcb48c 100644 --- a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl +++ b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl @@ -115,6 +115,12 @@ const TryAgain = SlowConvergence DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothing isdiscretecache(cache) = false +@static if isdefined(DiffEqBase, :unitfulvalue) + unitfulvalue(x) = DiffEqBase.unitfulvalue(x) +else + unitfulvalue(x) = DiffEqBase.ForwardDiff.value(x) +end + include("doc_utils.jl") include("misc_utils.jl") From a434d9ca8afbdbca81faf50e69856bf40bbbc0c7 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 9 Feb 2025 08:25:14 -0800 Subject: [PATCH 180/203] Update solve.jl --- lib/OrdinaryDiffEqCore/src/solve.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index d1f8a689b1..6dbd14e4f7 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -232,11 +232,11 @@ function DiffEqBase.__init( abstol_internal = false elseif abstol === nothing if uBottomEltypeNoUnits == uBottomEltype - abstol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype, + abstol_internal = unitfulvalue(real(convert(uBottomEltype, oneunit(uBottomEltype) * 1 // 10^6))) else - abstol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^6)) + abstol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^6)) end else abstol_internal = real.(abstol) @@ -246,10 +246,10 @@ function DiffEqBase.__init( reltol_internal = false elseif reltol === nothing if uBottomEltypeNoUnits == uBottomEltype - reltol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype, + reltol_internal = unitfulvalue(real(convert(uBottomEltype, oneunit(uBottomEltype) * 1 // 10^3))) else - reltol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^3)) + reltol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^3)) end else reltol_internal = real.(reltol) From 1926905b32d589fead92fb2f8e41398206410026 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sun, 9 Feb 2025 11:09:00 -0800 Subject: [PATCH 181/203] Update Project.toml --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index e4137f1c28..a85372cf63 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.15.1" +version = "1.16.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From b290abf898b7bc2adbfe232ab01704e092d97ca4 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 10 Feb 2025 21:00:54 -0800 Subject: [PATCH 182/203] fallback for non-isbits bottom eltype This can be required in weird TupleVec stuff. --- lib/OrdinaryDiffEqCore/src/solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index 6dbd14e4f7..b07961f2fc 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -517,7 +517,7 @@ function DiffEqBase.__init( do_error_check = true event_last_time = 0 vector_event_last_time = 1 - last_event_error = prob isa DiscreteProblem ? false : zero(uBottomEltypeNoUnits) + last_event_error = prob isa DiscreteProblem ? false : (Base.isbitstype(uBottomEltypeNoUnits) ? zero(uBottomEltypeNoUnits) : 0.0) dtchangeable = isdtchangeable(_alg) q11 = QT(1) success_iter = 0 From 6ac008506e89133562b4eb0cf3b7b4359f2743af Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 10 Feb 2025 21:06:36 -0800 Subject: [PATCH 183/203] Update Project.toml --- lib/OrdinaryDiffEqDifferentiation/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/Project.toml b/lib/OrdinaryDiffEqDifferentiation/Project.toml index 720ed0fff0..cfec3fbe00 100644 --- a/lib/OrdinaryDiffEqDifferentiation/Project.toml +++ b/lib/OrdinaryDiffEqDifferentiation/Project.toml @@ -30,7 +30,7 @@ FiniteDiff = "2" ForwardDiff = "0.10" FunctionWrappersWrappers = "0.1" LinearAlgebra = "1.10" -LinearSolve = "2" +LinearSolve = "2, 3" OrdinaryDiffEqCore = "1.14" Random = "<0.0.1, 1" SafeTestsets = "0.1.0" From 9caba7dfa5068587861471e590a6ca55bf4c2a40 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 10 Feb 2025 21:06:57 -0800 Subject: [PATCH 184/203] Update Project.toml --- lib/OrdinaryDiffEqNonlinearSolve/Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/Project.toml b/lib/OrdinaryDiffEqNonlinearSolve/Project.toml index e93d789ca7..585a399d94 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/Project.toml +++ b/lib/OrdinaryDiffEqNonlinearSolve/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqNonlinearSolve" uuid = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8" authors = ["Chris Rackauckas ", "Yingbo Ma "] -version = "1.3.1" +version = "1.4.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -33,7 +33,7 @@ FastBroadcast = "0.3.5" FastClosures = "0.3.2" ForwardDiff = "0.10.36" LinearAlgebra = "<0.0.1, 1" -LinearSolve = "2.32.0" +LinearSolve = "2.32.0, 3" MuladdMacro = "0.2.4" NonlinearSolve = "3.14.0, 4" OrdinaryDiffEqCore = "1.13" From 9586ce61c8c6712324bcecd848fd07b370c28750 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 10 Feb 2025 21:07:09 -0800 Subject: [PATCH 185/203] Update Project.toml --- lib/OrdinaryDiffEqDifferentiation/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDifferentiation/Project.toml b/lib/OrdinaryDiffEqDifferentiation/Project.toml index cfec3fbe00..f32ee0d56a 100644 --- a/lib/OrdinaryDiffEqDifferentiation/Project.toml +++ b/lib/OrdinaryDiffEqDifferentiation/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqDifferentiation" uuid = "4302a76b-040a-498a-8c04-15b101fed76b" authors = ["Chris Rackauckas ", "Yingbo Ma "] -version = "1.3.0" +version = "1.4.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From dab0b155cf4f24dfca28065876bff01dee052785 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 11 Feb 2025 15:06:44 +0100 Subject: [PATCH 186/203] Make the name `OrdinaryDiffEqCore` available --- src/OrdinaryDiffEq.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrdinaryDiffEq.jl b/src/OrdinaryDiffEq.jl index 9dac13762a..e689440fbf 100644 --- a/src/OrdinaryDiffEq.jl +++ b/src/OrdinaryDiffEq.jl @@ -6,7 +6,8 @@ module OrdinaryDiffEq using Reexport @reexport using DiffEqBase -import OrdinaryDiffEqCore: trivial_limiter!, CompositeAlgorithm, alg_order, +import OrdinaryDiffEqCore: OrdinaryDiffEqCore, + trivial_limiter!, CompositeAlgorithm, alg_order, ShampineCollocationInit, BrownFullBasicInit, NoInit, set_new_W!, set_W_γdt!, get_W, isfirstcall, isfirststage, isJcurrent, get_new_W_γdt_cutoff, From fe943409b11edeeff218fd162e6221e57fc924b6 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 11 Feb 2025 06:09:22 -0800 Subject: [PATCH 187/203] Update Project.toml --- lib/OrdinaryDiffEqSymplecticRK/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqSymplecticRK/Project.toml b/lib/OrdinaryDiffEqSymplecticRK/Project.toml index ef28c39fce..a7d31a18ec 100644 --- a/lib/OrdinaryDiffEqSymplecticRK/Project.toml +++ b/lib/OrdinaryDiffEqSymplecticRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqSymplecticRK" uuid = "fa646aed-7ef9-47eb-84c4-9443fc8cbfa8" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" From 0ea61dc630ea0d6159e70aa134bbb674ae13fa25 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 11 Feb 2025 06:10:18 -0800 Subject: [PATCH 188/203] Update Project.toml --- lib/OrdinaryDiffEqCore/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index a85372cf63..4a83585c3b 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "1.16.0" +version = "1.17.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" From 5b0319d0079480770ddbd3750f1ebc3795e5587a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 11 Feb 2025 22:57:26 -0800 Subject: [PATCH 189/203] test master --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7d5268ac48..2af90c5a93 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ ordinary differential equation solvers and utilities. While completely independe and usable on its own, users interested in using this functionality should check out [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl). - ## Installation Assuming that you already have Julia correctly installed, it suffices to import From 398d799c5fea43d23107ecd43a08f0ddbed50f49 Mon Sep 17 00:00:00 2001 From: Michele Mesiti Date: Wed, 12 Feb 2025 10:28:32 +0100 Subject: [PATCH 190/203] Bump ABM subpackage version --- lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml index 5041384fed..6ada6d599b 100644 --- a/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml +++ b/lib/OrdinaryDiffEqAdamsBashforthMoulton/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqAdamsBashforthMoulton" uuid = "89bda076-bce5-4f1c-845f-551c83cdda9a" authors = ["ParamThakkar123 "] -version = "1.1.0" +version = "1.2.0" [deps] DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" From 18cf4c1772a0c0b1ef32bbc8dc94220a05c7ef80 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 05:48:20 -0800 Subject: [PATCH 191/203] format --- lib/OrdinaryDiffEqBDF/src/algorithms.jl | 29 +- .../test/bdf_regression_tests.jl | 24 +- .../ext/OrdinaryDiffEqCoreEnzymeCoreExt.jl | 15 +- .../src/OrdinaryDiffEqCore.jl | 10 +- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 15 +- .../src/integrators/controllers.jl | 10 +- .../src/integrators/integrator_interface.jl | 7 +- lib/OrdinaryDiffEqCore/src/misc_utils.jl | 18 +- lib/OrdinaryDiffEqCore/src/solve.jl | 27 +- lib/OrdinaryDiffEqDefault/src/default_alg.jl | 6 +- .../src/OrdinaryDiffEqDifferentiation.jl | 3 +- .../src/alg_utils.jl | 19 +- .../src/derivative_wrappers.jl | 6 +- .../src/algorithms.jl | 9 +- .../src/algorithms.jl | 8 +- .../src/controllers.jl | 6 +- .../src/OrdinaryDiffEqFIRK.jl | 5 +- lib/OrdinaryDiffEqFIRK/src/algorithms.jl | 77 +++-- lib/OrdinaryDiffEqFIRK/src/controllers.jl | 21 +- lib/OrdinaryDiffEqFIRK/src/firk_caches.jl | 37 +-- .../src/firk_perform_step.jl | 280 ++++++++++-------- lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl | 37 +-- .../src/integrator_interface.jl | 3 +- lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl | 17 +- lib/OrdinaryDiffEqFIRK/test/runtests.jl | 2 +- .../src/algorithms.jl | 8 +- lib/OrdinaryDiffEqLinear/src/linear_caches.jl | 9 +- .../src/OrdinaryDiffEqNonlinearSolve.jl | 3 +- .../src/newton.jl | 5 +- lib/OrdinaryDiffEqPDIRK/src/algorithms.jl | 4 +- .../src/algorithms.jl | 4 - .../src/rosenbrock_caches.jl | 11 +- .../src/rosenbrock_interpolants.jl | 108 ++++--- .../src/rosenbrock_perform_step.jl | 79 ++--- .../src/rosenbrock_tableaus.jl | 125 ++++---- .../src/stiff_addsteps.jl | 3 +- lib/OrdinaryDiffEqSDIRK/src/algorithms.jl | 39 +-- .../src/algorithms.jl | 4 +- test/downstream/autodiff_events.jl | 2 +- test/downstream/delaydiffeq.jl | 2 +- test/gpu/linear_exp.jl | 6 +- test/integrators/check_error.jl | 2 +- test/integrators/ode_cache_tests.jl | 6 +- test/integrators/step_limiter_test.jl | 5 +- test/interface/ad_tests.jl | 10 +- test/interface/aliasing_tests.jl | 4 +- test/interface/autodiff_error_tests.jl | 2 +- test/interface/composite_algorithm_test.jl | 6 +- test/interface/nojac.jl | 3 +- test/interface/ode_initdt_tests.jl | 4 +- test/interface/ode_strip_test.jl | 1 - test/interface/precision_mixing.jl | 7 +- test/interface/static_array_tests.jl | 30 +- test/interface/stats_tests.jl | 10 +- test/interface/utility_tests.jl | 2 +- 55 files changed, 630 insertions(+), 565 deletions(-) diff --git a/lib/OrdinaryDiffEqBDF/src/algorithms.jl b/lib/OrdinaryDiffEqBDF/src/algorithms.jl index 9547b2a263..14ce9c75e1 100644 --- a/lib/OrdinaryDiffEqBDF/src/algorithms.jl +++ b/lib/OrdinaryDiffEqBDF/src/algorithms.jl @@ -112,13 +112,13 @@ struct ABDF2{CS, AD, F, F2, P, FDT, ST, CJ, K, T, StepLimiter} <: step_limiter!::StepLimiter autodiff::AD end -function ABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function ABDF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), κ = nothing, tol = nothing, linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ABDF2{ @@ -177,7 +177,6 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, ark = false) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), @@ -194,13 +193,13 @@ function SBDF(order; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), end # All keyword form needed for remake -function SBDF(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function SBDF(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, order, ark = false) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SBDF{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), @@ -301,12 +300,12 @@ struct QNDF1{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: autodiff::AD end -function QNDF1(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function QNDF1(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -37 // 200, controller = :Standard, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF1{ @@ -361,12 +360,12 @@ struct QNDF2{CS, AD, F, F2, P, FDT, ST, CJ, κType, StepLimiter} <: autodiff::AD end -function QNDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function QNDF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, kappa = -1 // 9, controller = :Standard, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF2{ @@ -437,7 +436,6 @@ function QNDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), extrapolant = :linear, kappa = ( -37 // 200, -1 // 9, -823 // 10000, -83 // 2000, 0 // 1), controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) QNDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -479,11 +477,11 @@ struct MEBDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol autodiff::AD end -function MEBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function MEBDF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) MEBDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -543,7 +541,6 @@ function FBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, step_limiter! = trivial_limiter!) where {MO} - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) FBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -662,7 +659,6 @@ function DImplicitEuler(; linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) DImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -699,12 +695,12 @@ struct DABDF2{CS, AD, F, F2, P, FDT, ST, CJ} <: DAEAlgorithm{CS, AD, FDT, ST, CJ controller::Symbol autodiff::AD end -function DABDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function DABDF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :Standard) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) DABDF2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -768,7 +764,6 @@ function DFBDF(; max_order::Val{MO} = Val{5}(), chunk_size = Val{0}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard) where {MO} - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) DFBDF{MO, _unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqBDF/test/bdf_regression_tests.jl b/lib/OrdinaryDiffEqBDF/test/bdf_regression_tests.jl index 9369d189e5..293abccf4d 100644 --- a/lib/OrdinaryDiffEqBDF/test/bdf_regression_tests.jl +++ b/lib/OrdinaryDiffEqBDF/test/bdf_regression_tests.jl @@ -1,20 +1,20 @@ using OrdinaryDiffEqBDF, Test -foop = (u,p,t)->u +foop = (u, p, t) -> u proboop = ODEProblem(foop, ones(2), (0.0, 1000.0)) -fiip = (du,u,p,t)->du.=u +fiip = (du, u, p, t) -> du .= u probiip = ODEProblem(fiip, ones(2), (0.0, 1000.0)) @testset "FBDF reinit" begin -for prob in [proboop, probiip] - integ = init(prob, FBDF(), verbose=false) #suppress warning to clean up CI - solve!(integ) - @test integ.sol.retcode != ReturnCode.Success - @test integ.sol.t[end] >= 700 - reinit!(integ, prob.u0) - solve!(integ) - @test integ.sol.retcode != ReturnCode.Success - @test integ.sol.t[end] >= 700 -end + for prob in [proboop, probiip] + integ = init(prob, FBDF(), verbose = false) #suppress warning to clean up CI + solve!(integ) + @test integ.sol.retcode != ReturnCode.Success + @test integ.sol.t[end] >= 700 + reinit!(integ, prob.u0) + solve!(integ) + @test integ.sol.retcode != ReturnCode.Success + @test integ.sol.t[end] >= 700 + end end diff --git a/lib/OrdinaryDiffEqCore/ext/OrdinaryDiffEqCoreEnzymeCoreExt.jl b/lib/OrdinaryDiffEqCore/ext/OrdinaryDiffEqCoreEnzymeCoreExt.jl index 888c54bb27..908d5cb8e1 100644 --- a/lib/OrdinaryDiffEqCore/ext/OrdinaryDiffEqCoreEnzymeCoreExt.jl +++ b/lib/OrdinaryDiffEqCore/ext/OrdinaryDiffEqCoreEnzymeCoreExt.jl @@ -1,7 +1,10 @@ module OrdinaryDiffEqCoreEnzymeCoreExt import OrdinaryDiffEqCore, EnzymeCore -EnzymeCore.EnzymeRules.inactive_noinl(::typeof(OrdinaryDiffEqCore.increment_nf!), args...) = true +function EnzymeCore.EnzymeRules.inactive_noinl( + ::typeof(OrdinaryDiffEqCore.increment_nf!), args...) + true +end function EnzymeCore.EnzymeRules.inactive_noinl( ::typeof(OrdinaryDiffEqCore.fixed_t_for_floatingpoint_error!), args...) true @@ -14,7 +17,13 @@ function EnzymeCore.EnzymeRules.inactive_noinl( ::typeof(OrdinaryDiffEqCore.increment_reject!), args...) true end -EnzymeCore.EnzymeRules.inactive_noinl(::typeof(OrdinaryDiffEqCore.check_error!), args...) = true -EnzymeCore.EnzymeRules.inactive_noinl(::typeof(OrdinaryDiffEqCore.log_step!), args...) = true +function EnzymeCore.EnzymeRules.inactive_noinl( + ::typeof(OrdinaryDiffEqCore.check_error!), args...) + true +end +function EnzymeCore.EnzymeRules.inactive_noinl( + ::typeof(OrdinaryDiffEqCore.log_step!), args...) + true +end end diff --git a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl index bcfbfcb48c..fd049c064a 100644 --- a/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl +++ b/lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl @@ -60,7 +60,8 @@ using DiffEqBase: check_error!, @def, _vec, _reshape using FastBroadcast: @.., True, False -using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val, ODEAliasSpecifier +using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val, + ODEAliasSpecifier import SciMLBase: AbstractNonlinearProblem, alg_order @@ -76,7 +77,8 @@ import Accessors: @reset using SciMLStructures: canonicalize, Tunable, isscimlstructure -using SymbolicIndexingInterface: state_values, parameter_values, is_variable, variable_index, +using SymbolicIndexingInterface: state_values, parameter_values, is_variable, + variable_index, symbolic_type, NotSymbolic const CompiledFloats = Union{Float32, Float64} @@ -116,9 +118,9 @@ DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothi isdiscretecache(cache) = false @static if isdefined(DiffEqBase, :unitfulvalue) - unitfulvalue(x) = DiffEqBase.unitfulvalue(x) + unitfulvalue(x) = DiffEqBase.unitfulvalue(x) else - unitfulvalue(x) = DiffEqBase.ForwardDiff.value(x) + unitfulvalue(x) = DiffEqBase.ForwardDiff.value(x) end include("doc_utils.jl") diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 378f808f64..f4a28df105 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -44,7 +44,6 @@ end ## Default algorithms - function _initialize_dae!(integrator, prob::ODEProblem, alg::DefaultInit, x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) @@ -64,8 +63,9 @@ function _initialize_dae!(integrator, prob::DAEProblem, if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif !applicable(_initialize_dae!, integrator, prob, - BrownFullBasicInit(), x) && !applicable(_initialize_dae!, + elseif !applicable(_initialize_dae!, integrator, prob, + BrownFullBasicInit(), x) && + !applicable(_initialize_dae!, integrator, prob, ShampineCollocationInit(), x) error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") elseif prob.differential_vars === nothing @@ -78,7 +78,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, end function _initialize_dae!(integrator, prob::DiscreteProblem, - alg::DefaultInit, x::Union{Val{true}, Val{false}}) + alg::DefaultInit, x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) # integrator.opts.abstol is `false` for `DiscreteProblem`. _initialize_dae!(integrator, prob, OverrideInit(one(eltype(prob.u0)) * 1e-12), x) @@ -148,7 +148,9 @@ function _initialize_dae!(integrator, prob::AbstractDEProblem, nlsolve_alg = default_nlsolve(alg.nlsolve, isinplace, iu0, initializeprob, isAD) - u0, p, success = SciMLBase.get_initial_values(prob, integrator, prob.f, alg, isinplace; nlsolve_alg, abstol = integrator.opts.abstol, reltol = integrator.opts.reltol) + u0, p, success = SciMLBase.get_initial_values( + prob, integrator, prob.f, alg, isinplace; nlsolve_alg, + abstol = integrator.opts.abstol, reltol = integrator.opts.reltol) if isinplace === Val{true}() integrator.u .= u0 @@ -171,5 +173,6 @@ end ## CheckInit function _initialize_dae!(integrator, prob::AbstractDEProblem, alg::CheckInit, isinplace::Union{Val{true}, Val{false}}) - SciMLBase.get_initial_values(prob, integrator, prob.f, alg, isinplace; abstol = integrator.opts.abstol) + SciMLBase.get_initial_values( + prob, integrator, prob.f, alg, isinplace; abstol = integrator.opts.abstol) end diff --git a/lib/OrdinaryDiffEqCore/src/integrators/controllers.jl b/lib/OrdinaryDiffEqCore/src/integrators/controllers.jl index a38ce1566a..9e28020851 100644 --- a/lib/OrdinaryDiffEqCore/src/integrators/controllers.jl +++ b/lib/OrdinaryDiffEqCore/src/integrators/controllers.jl @@ -141,8 +141,8 @@ end if iszero(EEst) q = inv(qmax) else - q11 = FastPower.fastpower(EEst, convert(typeof(EEst),beta1)) - q = q11 / FastPower.fastpower(qold, convert(typeof(EEst),beta2)) + q11 = FastPower.fastpower(EEst, convert(typeof(EEst), beta1)) + q = q11 / FastPower.fastpower(qold, convert(typeof(EEst), beta2)) integrator.q11 = q11 @fastmath q = max(inv(qmax), min(inv(qmin), q / gamma)) end @@ -428,7 +428,7 @@ end function step_accept_controller!(integrator, controller::PredictiveController, alg, q) @unpack qmin, qmax, gamma, qsteady_min, qsteady_max = integrator.opts - + EEst = DiffEqBase.value(integrator.EEst) if integrator.success_iter > 0 @@ -445,11 +445,11 @@ function step_accept_controller!(integrator, controller::PredictiveController, a end integrator.dtacc = integrator.dt integrator.erracc = max(1e-2, EEst) - + return integrator.dt / qacc end function step_reject_controller!(integrator, controller::PredictiveController, alg) @unpack dt, success_iter, qold = integrator integrator.dt = success_iter == 0 ? 0.1 * dt : dt / qold -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl b/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl index e64e03dc39..91e6631962 100644 --- a/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl +++ b/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl @@ -3,7 +3,7 @@ # Hence, we need to have two separate functions. function _change_t_via_interpolation!(integrator, t, - modify_save_endpoint::Type{Val{T}}, reinitialize_alg=nothing) where {T} + modify_save_endpoint::Type{Val{T}}, reinitialize_alg = nothing) where {T} # Can get rid of an allocation here with a function # get_tmp_arr(integrator.cache) which gives a pointer to some # cache array which can be modified. @@ -17,7 +17,8 @@ function _change_t_via_interpolation!(integrator, t, end integrator.t = t integrator.dt = integrator.t - integrator.tprev - DiffEqBase.reeval_internals_due_to_modification!(integrator; callback_initializealg=reinitialize_alg) + DiffEqBase.reeval_internals_due_to_modification!( + integrator; callback_initializealg = reinitialize_alg) if T solution_endpoint_match_cur_integrator!(integrator) end @@ -28,7 +29,7 @@ function DiffEqBase.change_t_via_interpolation!(integrator::ODEIntegrator, t, modify_save_endpoint::Type{Val{T}} = Val{ false, - }, reinitialize_alg=nothing) where { + }, reinitialize_alg = nothing) where { T, } _change_t_via_interpolation!(integrator, t, modify_save_endpoint, reinitialize_alg) diff --git a/lib/OrdinaryDiffEqCore/src/misc_utils.jl b/lib/OrdinaryDiffEqCore/src/misc_utils.jl index 3c347943e2..b39e7ab54d 100644 --- a/lib/OrdinaryDiffEqCore/src/misc_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/misc_utils.jl @@ -131,22 +131,28 @@ end isnewton(::Any) = false - function _bool_to_ADType(::Val{true}, chunksize, diff_type) - Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) - chunksize = SciMLBase._unwrap_val(chunksize) == 0 ? nothing : SciMLBase._unwrap_val(chunksize) + Base.depwarn( + "Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", + :_bool_to_ADType) + chunksize = SciMLBase._unwrap_val(chunksize) == 0 ? nothing : + SciMLBase._unwrap_val(chunksize) AutoForwardDiff(chunksize = chunksize) end function _bool_to_ADType(::Val{false}, chunksize, diff_type) - Base.depwarn("Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", :_bool_to_ADType) + Base.depwarn( + "Using a `Bool` for keyword argument `autodiff` is deprecated. Please use an `ADType` specifier.", + :_bool_to_ADType) return AutoFiniteDiff(fdtype = diff_type) end # Functions to get ADType type from Bool or ADType object, or ADType type -_process_AD_choice(ad_alg::Bool, chunksize, diff_type) = _bool_to_ADType(Val(ad_alg), chunksize, diff_type) +function _process_AD_choice(ad_alg::Bool, chunksize, diff_type) + _bool_to_ADType(Val(ad_alg), chunksize, diff_type) +end -function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) +function _process_AD_choice(ad_alg::AbstractADType, chunksize, diff_type) # need a path for if just chunksize is specified in the Algorithm construction if !(chunksize === Val{0}()) @warn "The `chunksize` keyword is deprecated. Please use an `ADType` specifier. For now defaulting to using `ForwardDiff` with the given `chunksize`." diff --git a/lib/OrdinaryDiffEqCore/src/solve.jl b/lib/OrdinaryDiffEqCore/src/solve.jl index b07961f2fc..6cbd4742e2 100644 --- a/lib/OrdinaryDiffEqCore/src/solve.jl +++ b/lib/OrdinaryDiffEqCore/src/solve.jl @@ -26,7 +26,8 @@ function DiffEqBase.__init( saveat isa Number || prob.tspan[1] in saveat, save_end = nothing, callback = nothing, - dense = save_everystep && isempty(saveat) && !default_linear_interpolation(prob, alg), + dense = save_everystep && isempty(saveat) && + !default_linear_interpolation(prob, alg), calck = (callback !== nothing && callback !== CallbackSet()) || (dense) || !isempty(saveat), # and no dense output dt = isdiscretealg(alg) && isempty(tstops) ? @@ -156,7 +157,7 @@ function DiffEqBase.__init( _alg = alg end - use_old_kwargs = haskey(kwargs,:alias_u0) || haskey(kwargs,:alias_du0) + use_old_kwargs = haskey(kwargs, :alias_u0) || haskey(kwargs, :alias_du0) if use_old_kwargs aliases = ODEAliasSpecifier() @@ -175,29 +176,30 @@ function DiffEqBase.__init( please use an ODEAliasSpecifier, e.g. `solve(prob, alias = ODEAliasSpecifier(alias_du0 = true))" Base.depwarn(message, :init) Base.depwarn(message, :solve) - aliases = ODEAliasSpecifier(alias_u0 = aliases.alias_u0, alias_du0 = values(kwargs).alias_du0) + aliases = ODEAliasSpecifier( + alias_u0 = aliases.alias_u0, alias_du0 = values(kwargs).alias_du0) else aliases = ODEAliasSpecifier(alias_u0 = aliases.alias_u0, alias_du0 = nothing) end - - aliases + + aliases else - # If alias isa Bool, all fields of ODEAliases set to alias + # If alias isa Bool, all fields of ODEAliases set to alias if alias isa Bool aliases = ODEAliasSpecifier(alias = alias) - elseif alias isa ODEAliasSpecifier + elseif alias isa ODEAliasSpecifier aliases = alias end end - if isnothing(aliases.alias_f) || aliases.alias_f + if isnothing(aliases.alias_f) || aliases.alias_f f = prob.f else f = deepcopy(prob.f) end - if isnothing(aliases.alias_p) || aliases.alias_p + if isnothing(aliases.alias_p) || aliases.alias_p p = prob.p else p = recursivecopy(prob.p) @@ -316,7 +318,8 @@ function DiffEqBase.__init( end ### Algorithm-specific defaults ### - save_idxs, saved_subsystem = SciMLBase.get_save_idxs_and_saved_subsystem(prob, save_idxs) + save_idxs, saved_subsystem = SciMLBase.get_save_idxs_and_saved_subsystem( + prob, save_idxs) if save_idxs === nothing ksEltype = Vector{rateType} @@ -517,7 +520,9 @@ function DiffEqBase.__init( do_error_check = true event_last_time = 0 vector_event_last_time = 1 - last_event_error = prob isa DiscreteProblem ? false : (Base.isbitstype(uBottomEltypeNoUnits) ? zero(uBottomEltypeNoUnits) : 0.0) + last_event_error = prob isa DiscreteProblem ? false : + (Base.isbitstype(uBottomEltypeNoUnits) ? zero(uBottomEltypeNoUnits) : + 0.0) dtchangeable = isdtchangeable(_alg) q11 = QT(1) success_iter = 0 diff --git a/lib/OrdinaryDiffEqDefault/src/default_alg.jl b/lib/OrdinaryDiffEqDefault/src/default_alg.jl index 156fdc26f2..9ec64e3fed 100644 --- a/lib/OrdinaryDiffEqDefault/src/default_alg.jl +++ b/lib/OrdinaryDiffEqDefault/src/default_alg.jl @@ -41,11 +41,13 @@ end function DiffEqBase.__init(prob::ODEProblem, ::Nothing, args...; kwargs...) DiffEqBase.init( - prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), args...; wrap = Val(false), kwargs...) + prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), + args...; wrap = Val(false), kwargs...) end function DiffEqBase.__solve(prob::ODEProblem, ::Nothing, args...; kwargs...) DiffEqBase.solve( - prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), args...; wrap = Val(false), kwargs...) + prob, DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), + args...; wrap = Val(false), kwargs...) end function is_stiff(integrator, alg, ntol, stol, is_stiffalg, current) diff --git a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl index c3613a2233..25a696c778 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/OrdinaryDiffEqDifferentiation.jl @@ -44,7 +44,8 @@ using OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, OrdinaryDiffEqAdaptiveImplici FastConvergence, Convergence, SlowConvergence, VerySlowConvergence, Divergence, NLStatus, MethodType, constvalue -import OrdinaryDiffEqCore: get_chunksize, resize_J_W!, resize_nlsolver!, alg_autodiff, _get_fwd_tag +import OrdinaryDiffEqCore: get_chunksize, resize_J_W!, resize_nlsolver!, alg_autodiff, + _get_fwd_tag using FastBroadcast: @.. diff --git a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl index 76161503c2..354bbcb463 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl @@ -2,7 +2,9 @@ function _alg_autodiff(alg::OrdinaryDiffEqAlgorithm) error("This algorithm does not have an autodifferentiation option defined.") end -_alg_autodiff(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff +function _alg_autodiff(alg::OrdinaryDiffEqAdaptiveImplicitAlgorithm{CS, AD}) where {CS, AD} + alg.autodiff +end _alg_autodiff(alg::DAEAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff _alg_autodiff(alg::OrdinaryDiffEqImplicitAlgorithm{CS, AD}) where {CS, AD} = alg.autodiff _alg_autodiff(alg::CompositeAlgorithm) = _alg_autodiff(alg.algs[end]) @@ -16,12 +18,12 @@ end function alg_autodiff(alg) autodiff = _alg_autodiff(alg) - + if autodiff == Val(true) return AutoForwardDiff() elseif autodiff == Val(false) return AutoFiniteDiff() - else + else return autodiff end end @@ -52,14 +54,17 @@ function DiffEqBase.prepare_alg( # If prob.f.f is a FunctionWrappersWrappers from ODEFunction, need to set chunksize to 1 if alg_autodiff(alg) isa AutoForwardDiff && ((prob.f isa ODEFunction && - prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) || (isbitstype(T) && sizeof(T) > 24)) - return remake(alg, autodiff = AutoForwardDiff(chunksize = 1, tag = alg_autodiff(alg).tag)) + prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) || + (isbitstype(T) && sizeof(T) > 24)) + return remake( + alg, autodiff = AutoForwardDiff(chunksize = 1, tag = alg_autodiff(alg).tag)) end # If the autodiff alg is AutoFiniteDiff, prob.f.f isa FunctionWrappersWrapper, # and fdtype is complex, fdtype needs to change to something not complex - if alg_autodiff(alg) isa AutoFiniteDiff - if alg_difftype(alg) == Val{:complex} && (prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) + if alg_autodiff(alg) isa AutoFiniteDiff + if alg_difftype(alg) == Val{:complex} && (prob.f isa ODEFunction && + prob.f.f isa FunctionWrappersWrappers.FunctionWrappersWrapper) @warn "AutoFiniteDiff fdtype complex is not compatible with this function" return remake(alg, autodiff = AutoFiniteDiff(fdtype = Val{:forward}())) end diff --git a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl index 0f9178a0ce..3ef9cf3c4f 100644 --- a/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl +++ b/lib/OrdinaryDiffEqDifferentiation/src/derivative_wrappers.jl @@ -80,7 +80,7 @@ function derivative!(df::AbstractArray{<:Number}, f, integrator, grad_config) alg = unwrap_alg(integrator, true) tmp = length(x) # We calculate derivative for all elements in gradient - autodiff_alg = alg_autodiff(alg) + autodiff_alg = alg_autodiff(alg) if autodiff_alg isa AutoForwardDiff T = if standardtag(alg) typeof(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(df))) @@ -125,7 +125,7 @@ function derivative(f, x::Union{Number, AbstractArray{<:Number}}, local d tmp = length(x) # We calculate derivative for all elements in gradient alg = unwrap_alg(integrator, true) - if alg_autodiff(alg) isa AutoForwardDiff + if alg_autodiff(alg) isa AutoForwardDiff OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) if integrator.iter == 1 try @@ -287,7 +287,7 @@ function build_jac_config(alg, f::F1, uf::F2, du1, uprev, u, tmp, du2) where {F1 else typeof(ForwardDiff.Tag(uf, eltype(u))) end - + if _chunksize === Val{nothing}() _chunksize = nothing end diff --git a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl index 1ed1b25fad..e2f8a13af4 100644 --- a/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExponentialRK/src/algorithms.jl @@ -39,7 +39,6 @@ for (Alg, Description, Ref) in [ standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}()) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) $Alg{_unwrap_val(chunk_size), typeof(AD_choice), @@ -80,10 +79,10 @@ for (Alg, Description, Ref) in [ autodiff::AD end end - @eval function $Alg(; m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), + @eval function $Alg(; + m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}()) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) $Alg{_unwrap_val(chunk_size), typeof(AD_choice), @@ -142,10 +141,10 @@ for (Alg, Description, Ref) in [(:Exp4, "4th order EPIRK scheme.", REF3) autodiff::AD end end - @eval function $Alg(; adaptive_krylov = true, m = 30, iop = 0, autodiff = AutoForwardDiff(), + @eval function $Alg(; + adaptive_krylov = true, m = 30, iop = 0, autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, chunk_size = Val{0}(), diff_type = Val{:forward}()) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) $Alg{_unwrap_val(chunk_size), typeof(AD_choice), diff_type, diff --git a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl index 82cb923123..cc53871818 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/algorithms.jl @@ -73,7 +73,6 @@ function ImplicitEulerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForw precs = DEFAULT_PRECS, max_order = 12, min_order = 3, init_order = 5, threading = false, sequence = :harmonic) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) linsolve = (linsolve === nothing && @@ -210,13 +209,13 @@ struct ImplicitDeuflhardExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: threading::TO autodiff::AD end -function ImplicitDeuflhardExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), +function ImplicitDeuflhardExtrapolation(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, diff_type = Val{:forward}(), min_order = 1, init_order = 5, max_order = 10, sequence = :harmonic, threading = false) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) # Enforce 1 <= min_order <= init_order <= max_order: @@ -362,7 +361,8 @@ struct ImplicitHairerWannerExtrapolation{CS, AD, F, P, FDT, ST, CJ, TO} <: autodiff::AD end -function ImplicitHairerWannerExtrapolation(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), +function ImplicitHairerWannerExtrapolation(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, linsolve = nothing, precs = DEFAULT_PRECS, diff --git a/lib/OrdinaryDiffEqExtrapolation/src/controllers.jl b/lib/OrdinaryDiffEqExtrapolation/src/controllers.jl index a6ae7ea315..c50fddc82e 100644 --- a/lib/OrdinaryDiffEqExtrapolation/src/controllers.jl +++ b/lib/OrdinaryDiffEqExtrapolation/src/controllers.jl @@ -34,7 +34,8 @@ function stepsize_controller_internal!(integrator, integrator.opts.gamma = FastPower.fastpower(typeof(integrator.opts.gamma)(1 // 4), controller.beta1) # Compute new stepsize scaling - qtmp = FastPower.fastpower(integrator.EEst, controller.beta1) / integrator.opts.gamma + qtmp = FastPower.fastpower(integrator.EEst, controller.beta1) / + integrator.opts.gamma @fastmath q = max(inv(integrator.opts.qmax), min(inv(integrator.opts.qmin), qtmp)) end integrator.cache.Q[integrator.cache.n_curr - alg.min_order + 1] = q @@ -60,7 +61,8 @@ function stepsize_predictor!(integrator, integrator.opts.gamma = FastPower.fastpower(typeof(integrator.opts.gamma)(1 // 4), controller.beta1) # Compute new stepsize scaling - qtmp = EEst * FastPower.fastpower(FastPower.fastpower(tol, (1.0 - s_curr / s_new)), + qtmp = EEst * + FastPower.fastpower(FastPower.fastpower(tol, (1.0 - s_curr / s_new)), controller.beta1) / integrator.opts.gamma @fastmath q = max(inv(integrator.opts.qmax), min(inv(integrator.opts.qmin), qtmp)) end diff --git a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl index 6902e3088f..c4c9501109 100644 --- a/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl +++ b/lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl @@ -6,7 +6,8 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, OrdinaryDiffEqAlgorithm, OrdinaryDiffEqNewtonAdaptiveAlgorithm, OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache, OrdinaryDiffEqAdaptiveAlgorithm, CompiledFloats, uses_uprev, - alg_cache, _vec, _reshape, @cache, @threaded, isthreaded, PolyesterThreads, + alg_cache, _vec, _reshape, @cache, @threaded, isthreaded, + PolyesterThreads, isfsal, full_cache, constvalue, _unwrap_val, differentiation_rk_docstring, trivial_limiter!, _ode_interpolant!, _ode_addsteps!, AbstractController, @@ -19,7 +20,7 @@ import OrdinaryDiffEqCore: alg_order, calculate_residuals!, isfirk, generic_solver_docstring, _bool_to_ADType, _process_AD_choice using MuladdMacro, DiffEqBase, RecursiveArrayTools, Polyester - isfirk, generic_solver_docstring +isfirk, generic_solver_docstring using SciMLOperators: AbstractSciMLOperator using LinearAlgebra: I, UniformScaling, mul!, lu import LinearSolve diff --git a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl index 4975c3aad3..0fbca63150 100644 --- a/lib/OrdinaryDiffEqFIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqFIRK/src/algorithms.jl @@ -48,7 +48,6 @@ function RadauIIA3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RadauIIA3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -97,7 +96,6 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RadauIIA5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -147,7 +145,6 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), new_W_γdt_cutoff = 1 // 5, controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RadauIIA9{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -167,47 +164,45 @@ function RadauIIA9(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), end struct AdaptiveRadau{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2, StepLimiter, TO} <: - OrdinaryDiffEqNewtonAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} - linsolve::F - precs::P - smooth_est::Bool - extrapolant::Symbol - κ::Tol - maxiters::Int - fast_convergence_cutoff::C1 - new_W_γdt_cutoff::C2 - controller::Symbol - step_limiter!::StepLimiter - min_order::Int - max_order::Int - threading::TO - autodiff::AD + OrdinaryDiffEqNewtonAdaptiveAlgorithm{CS, AD, FDT, ST, CJ} + linsolve::F + precs::P + smooth_est::Bool + extrapolant::Symbol + κ::Tol + maxiters::Int + fast_convergence_cutoff::C1 + new_W_γdt_cutoff::C2 + controller::Symbol + step_limiter!::StepLimiter + min_order::Int + max_order::Int + threading::TO + autodiff::AD end function AdaptiveRadau(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), - standardtag = Val{true}(), concrete_jac = nothing, - diff_type = Val{:forward}, min_order = 5, max_order = 13, threading = false, - linsolve = nothing, precs = DEFAULT_PRECS, - extrapolant = :dense, fast_convergence_cutoff = 1 // 5, - new_W_γdt_cutoff = 1 // 5, - controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, - step_limiter! = trivial_limiter!) - + standardtag = Val{true}(), concrete_jac = nothing, + diff_type = Val{:forward}, min_order = 5, max_order = 13, threading = false, + linsolve = nothing, precs = DEFAULT_PRECS, + extrapolant = :dense, fast_convergence_cutoff = 1 // 5, + new_W_γdt_cutoff = 1 // 5, + controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true, + step_limiter! = trivial_limiter!) AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) - AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), - typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), - typeof(κ), typeof(fast_convergence_cutoff), - typeof(new_W_γdt_cutoff), typeof(step_limiter!), typeof(threading)}(linsolve, - precs, - smooth_est, - extrapolant, - κ, - maxiters, - fast_convergence_cutoff, - new_W_γdt_cutoff, - controller, - step_limiter!, min_order, max_order, threading, - AD_choice) + AdaptiveRadau{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), + typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac), + typeof(κ), typeof(fast_convergence_cutoff), + typeof(new_W_γdt_cutoff), typeof(step_limiter!), typeof(threading)}(linsolve, + precs, + smooth_est, + extrapolant, + κ, + maxiters, + fast_convergence_cutoff, + new_W_γdt_cutoff, + controller, + step_limiter!, min_order, max_order, threading, + AD_choice) end - diff --git a/lib/OrdinaryDiffEqFIRK/src/controllers.jl b/lib/OrdinaryDiffEqFIRK/src/controllers.jl index cf38a16c48..637dba9dda 100644 --- a/lib/OrdinaryDiffEqFIRK/src/controllers.jl +++ b/lib/OrdinaryDiffEqFIRK/src/controllers.jl @@ -1,8 +1,9 @@ -function step_accept_controller!(integrator, controller::PredictiveController, alg::AdaptiveRadau, q) +function step_accept_controller!( + integrator, controller::PredictiveController, alg::AdaptiveRadau, q) @unpack qmin, qmax, gamma, qsteady_min, qsteady_max = integrator.opts @unpack cache = integrator @unpack num_stages, step, iter, hist_iter, index = cache - + EEst = DiffEqBase.value(integrator.EEst) if integrator.success_iter > 0 @@ -30,8 +31,9 @@ function step_accept_controller!(integrator, controller::PredictiveController, a cache.index += 1 cache.step = 1 cache.hist_iter = iter - elseif ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages > min_stages) - cache.num_stages -= 2 + elseif ((hist_iter > 8 || cache.status == VerySlowConvergence || + cache.status == Divergence) && num_stages > min_stages) + cache.num_stages -= 2 cache.index -= 1 cache.step = 1 cache.hist_iter = iter @@ -40,9 +42,10 @@ function step_accept_controller!(integrator, controller::PredictiveController, a return integrator.dt / qacc end -function step_reject_controller!(integrator, controller::PredictiveController, alg::AdaptiveRadau) +function step_reject_controller!( + integrator, controller::PredictiveController, alg::AdaptiveRadau) @unpack dt, success_iter, qold = integrator - @unpack cache = integrator + @unpack cache = integrator @unpack num_stages, step, iter, hist_iter = cache integrator.dt = success_iter == 0 ? 0.1 * dt : dt / qold cache.step = step + 1 @@ -50,12 +53,12 @@ function step_reject_controller!(integrator, controller::PredictiveController, a cache.hist_iter = hist_iter min_stages = (alg.min_order - 1) ÷ 4 * 2 + 1 if (step > 10) - if ((hist_iter > 8 || cache.status == VerySlowConvergence || cache.status == Divergence) && num_stages > min_stages) - cache.num_stages -= 2 + if ((hist_iter > 8 || cache.status == VerySlowConvergence || + cache.status == Divergence) && num_stages > min_stages) + cache.num_stages -= 2 cache.index -= 1 cache.step = 1 cache.hist_iter = iter end end end - diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl index f9da99a448..db425773df 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_caches.jl @@ -483,7 +483,7 @@ function alg_cache(alg::RadauIIA9, u, rate_prototype, ::Type{uEltypeNoUnits}, end mutable struct AdaptiveRadauConstantCache{F, Tab, Tol, Dt, U, JType} <: - OrdinaryDiffEqConstantCache + OrdinaryDiffEqConstantCache uf::F tabs::Vector{Tab} κ::Tol @@ -518,7 +518,8 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} end num_stages = min_stages - tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) for i in min_stages:2:max_stages] + tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) + for i in min_stages:2:max_stages] cont = Vector{typeof(u)}(undef, max_stages) for i in 1:max_stages cont[i] = zero(u) @@ -532,7 +533,8 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} Convergence, J, num_stages, 1, 0.0, index) end -mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type, +mutable struct AdaptiveRadauCache{ + uType, cuType, tType, uNoUnitsType, rateType, JType, W1Type, W2Type, UF, JC, F1, F2, Tab, Tol, Dt, rTol, aTol, StepLimiter} <: FIRKMutableCache u::uType @@ -548,7 +550,7 @@ mutable struct AdaptiveRadauCache{uType, cuType, tType, uNoUnitsType, rateType, cubuff::Vector{cuType} dw::Vector{uType} cont::Vector{uType} - derivatives:: Matrix{uType} + derivatives::Matrix{uType} du1::rateType fsalfirst::rateType ks::Vector{rateType} @@ -597,7 +599,8 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} end num_stages = min_stages - tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) for i in min_stages:2:max_stages] + tabs = [RadauIIATableau(uToltype, constvalue(tTypeNoUnits), i) + for i in min_stages:2:max_stages] index = 1 @@ -605,7 +608,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} z = Vector{typeof(u)}(undef, max_stages) w = Vector{typeof(u)}(undef, max_stages) - for i in 1 : max_stages + for i in 1:max_stages z[i] = zero(u) w[i] = zero(u) end @@ -613,28 +616,28 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} αdt = [zero(t) for i in 1:max_stages] βdt = [zero(t) for i in 1:max_stages] c_prime = Vector{typeof(t)}(undef, max_stages) #time stepping - for i in 1 : max_stages + for i in 1:max_stages c_prime[i] = zero(t) end dw1 = zero(u) ubuff = zero(u) - dw2 = [similar(u, Complex{eltype(u)}) for _ in 1 : (max_stages - 1) ÷ 2] + dw2 = [similar(u, Complex{eltype(u)}) for _ in 1:((max_stages - 1) ÷ 2)] recursivefill!.(dw2, false) - cubuff = [similar(u, Complex{eltype(u)}) for _ in 1 : (max_stages - 1) ÷ 2] + cubuff = [similar(u, Complex{eltype(u)}) for _ in 1:((max_stages - 1) ÷ 2)] recursivefill!.(cubuff, false) dw = [zero(u) for i in 1:max_stages] cont = [zero(u) for i in 1:max_stages] derivatives = Matrix{typeof(u)}(undef, max_stages, max_stages) - for i in 1 : max_stages, j in 1 : max_stages + for i in 1:max_stages, j in 1:max_stages derivatives[i, j] = zero(u) end fsalfirst = zero(rate_prototype) - fw = [zero(rate_prototype) for i in 1 : max_stages] - ks = [zero(rate_prototype) for i in 1 : max_stages] + fw = [zero(rate_prototype) for i in 1:max_stages] + ks = [zero(rate_prototype) for i in 1:max_stages] k = ks[1] @@ -643,7 +646,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} error("Non-concrete Jacobian not yet supported by AdaptiveRadau.") end - W2 = [similar(J, Complex{eltype(W1)}) for _ in 1 : (max_stages - 1) ÷ 2] + W2 = [similar(J, Complex{eltype(W1)}) for _ in 1:((max_stages - 1) ÷ 2)] recursivefill!.(W2, false) du1 = zero(rate_prototype) @@ -659,9 +662,10 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} linsolve1 = init(linprob, alg.linsolve, alias_A = true, alias_b = true, assumptions = LinearSolve.OperatorAssumptions(true)) - linsolve2 = [ - init(LinearProblem(W2[i], _vec(cubuff[i]); u0 = _vec(dw2[i])), alg.linsolve, alias_A = true, alias_b = true, - assumptions = LinearSolve.OperatorAssumptions(true)) for i in 1 : (max_stages - 1) ÷ 2] + linsolve2 = [init(LinearProblem(W2[i], _vec(cubuff[i]); u0 = _vec(dw2[i])), + alg.linsolve, alias_A = true, alias_b = true, + assumptions = LinearSolve.OperatorAssumptions(true)) + for i in 1:((max_stages - 1) ÷ 2)] rtol = reltol isa Number ? reltol : zero(reltol) atol = reltol isa Number ? reltol : zero(reltol) @@ -675,4 +679,3 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} linsolve1, linsolve2, rtol, atol, dt, dt, Convergence, alg.step_limiter!, num_stages, 1, 0.0, index) end - diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl index d72daf3508..5bfaafb2ef 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl @@ -26,7 +26,9 @@ function do_newW(integrator, nlsolver, new_jac, W_dt)::Bool # for FIRK return !smallstepchange end -function initialize!(integrator, cache::Union{RadauIIA3ConstantCache, RadauIIA5ConstantCache, RadauIIA9ConstantCache,AdaptiveRadauConstantCache}) +function initialize!(integrator, + cache::Union{RadauIIA3ConstantCache, RadauIIA5ConstantCache, + RadauIIA9ConstantCache, AdaptiveRadauConstantCache}) integrator.kshortsize = 2 integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) integrator.fsalfirst = integrator.f(integrator.uprev, integrator.p, integrator.t) # Pre-start fsal @@ -110,7 +112,6 @@ function initialize!(integrator, cache::AdaptiveRadauCache) nothing end - @muladd function perform_step!(integrator, cache::RadauIIA3ConstantCache) @unpack t, dt, uprev, u, f, p = integrator @unpack T11, T12, T21, T22, TI11, TI12, TI21, TI22 = cache.tab @@ -838,24 +839,24 @@ end c3′ = c3 * c5′ c4′ = c4 * c5′ z1 = @.. c1′ * (cont1 + - (c1′-c4m1) * (cont2 + - (c1′ - c3m1) * (cont3 + - (c1′ - c2m1) * (cont4 + (c1′ - c1m1) * cont5)))) + (c1′ - c4m1) * (cont2 + + (c1′ - c3m1) * (cont3 + + (c1′ - c2m1) * (cont4 + (c1′ - c1m1) * cont5)))) z2 = @.. c2′ * (cont1 + - (c2′-c4m1) * (cont2 + - (c2′ - c3m1) * (cont3 + - (c2′ - c2m1) * (cont4 + (c2′ - c1m1) * cont5)))) + (c2′ - c4m1) * (cont2 + + (c2′ - c3m1) * (cont3 + + (c2′ - c2m1) * (cont4 + (c2′ - c1m1) * cont5)))) z3 = @.. c3′ * (cont1 + - (c3′-c4m1) * (cont2 + - (c3′ - c3m1) * (cont3 + - (c3′ - c2m1) * (cont4 + (c3′ - c1m1) * cont5)))) + (c3′ - c4m1) * (cont2 + + (c3′ - c3m1) * (cont3 + + (c3′ - c2m1) * (cont4 + (c3′ - c1m1) * cont5)))) z4 = @.. c4′ * (cont1 + - (c4′-c4m1) * (cont2 + - (c4′ - c3m1) * (cont3 + - (c4′ - c2m1) * (cont4 + (c4′ - c1m1) * cont5)))) + (c4′ - c4m1) * (cont2 + + (c4′ - c3m1) * (cont3 + + (c4′ - c2m1) * (cont4 + (c4′ - c1m1) * cont5)))) z5 = @.. c5′ * (cont1 + - (c5′-c4m1) * (cont2 + - (c5′ - c3m1) * (cont3 + (c5′ - c2m1) * (cont4 + (c5′ - c1m1) * cont5)))) + (c5′ - c4m1) * (cont2 + + (c5′ - c3m1) * (cont3 + (c5′ - c2m1) * (cont4 + (c5′ - c1m1) * cont5)))) w1 = @.. broadcast=false TI11*z1+TI12*z2+TI13*z3+TI14*z4+TI15*z5 w2 = @.. broadcast=false TI21*z1+TI22*z2+TI23*z3+TI24*z4+TI25*z5 w3 = @.. broadcast=false TI31*z1+TI32*z2+TI33*z3+TI34*z4+TI35*z5 @@ -1088,29 +1089,29 @@ end c3′ = c3 * c5′ c4′ = c4 * c5′ @.. z1 = c1′ * (cont1 + - (c1′-c4m1) * (cont2 + - (c1′ - c3m1) * (cont3 + - (c1′ - c2m1) * (cont4 + (c1′ - c1m1) * cont5)))) + (c1′ - c4m1) * (cont2 + + (c1′ - c3m1) * (cont3 + + (c1′ - c2m1) * (cont4 + (c1′ - c1m1) * cont5)))) @.. z2 = c2′ * (cont1 + - (c2′-c4m1) * (cont2 + - (c2′ - c3m1) * (cont3 + - (c2′ - c2m1) * (cont4 + (c2′ - c1m1) * cont5)))) + (c2′ - c4m1) * (cont2 + + (c2′ - c3m1) * (cont3 + + (c2′ - c2m1) * (cont4 + (c2′ - c1m1) * cont5)))) @.. z3 = c3′ * (cont1 + - (c3′-c4m1) * (cont2 + - (c3′ - c3m1) * (cont3 + - (c3′ - c2m1) * (cont4 + (c3′ - c1m1) * cont5)))) + (c3′ - c4m1) * (cont2 + + (c3′ - c3m1) * (cont3 + + (c3′ - c2m1) * (cont4 + (c3′ - c1m1) * cont5)))) @.. z4 = c4′ * (cont1 + - (c4′-c4m1) * (cont2 + - (c4′ - c3m1) * (cont3 + - (c4′ - c2m1) * (cont4 + (c4′ - c1m1) * cont5)))) + (c4′ - c4m1) * (cont2 + + (c4′ - c3m1) * (cont3 + + (c4′ - c2m1) * (cont4 + (c4′ - c1m1) * cont5)))) @.. z5 = c5′ * (cont1 + - (c5′-c4m1) * (cont2 + - (c5′ - c3m1) * (cont3 + (c5′ - c2m1) * (cont4 + (c5′ - c1m1) * cont5)))) - @.. w1 = TI11*z1+TI12*z2+TI13*z3+TI14*z4+TI15*z5 - @.. w2 = TI21*z1+TI22*z2+TI23*z3+TI24*z4+TI25*z5 - @.. w3 = TI31*z1+TI32*z2+TI33*z3+TI34*z4+TI35*z5 - @.. w4 = TI41*z1+TI42*z2+TI43*z3+TI44*z4+TI45*z5 - @.. w5 = TI51*z1+TI52*z2+TI53*z3+TI54*z4+TI55*z5 + (c5′ - c4m1) * (cont2 + + (c5′ - c3m1) * (cont3 + (c5′ - c2m1) * (cont4 + (c5′ - c1m1) * cont5)))) + @.. w1 = TI11 * z1 + TI12 * z2 + TI13 * z3 + TI14 * z4 + TI15 * z5 + @.. w2 = TI21 * z1 + TI22 * z2 + TI23 * z3 + TI24 * z4 + TI25 * z5 + @.. w3 = TI31 * z1 + TI32 * z2 + TI33 * z3 + TI34 * z4 + TI35 * z5 + @.. w4 = TI41 * z1 + TI42 * z2 + TI43 * z3 + TI44 * z4 + TI45 * z5 + @.. w5 = TI51 * z1 + TI52 * z2 + TI53 * z3 + TI54 * z4 + TI55 * z5 end # Newton iteration @@ -1182,9 +1183,11 @@ end linsolve1 = cache.linsolve1 if needfactor - linres1 = dolinsolve(integrator, linsolve1; A = W1, b = _vec(ubuff), linu = _vec(dw1)) + linres1 = dolinsolve( + integrator, linsolve1; A = W1, b = _vec(ubuff), linu = _vec(dw1)) else - linres1 = dolinsolve(integrator, linsolve1; A = nothing, b = _vec(ubuff), linu = _vec(dw1)) + linres1 = dolinsolve( + integrator, linsolve1; A = nothing, b = _vec(ubuff), linu = _vec(dw1)) end cache.linsolve1 = linres1.cache @@ -1195,9 +1198,11 @@ end linsolve2 = cache.linsolve2 if needfactor - linres2 = dolinsolve(integrator, linsolve2; A = W2, b = _vec(cubuff1), linu = _vec(dw23)) + linres2 = dolinsolve( + integrator, linsolve2; A = W2, b = _vec(cubuff1), linu = _vec(dw23)) else - linres2 = dolinsolve(integrator, linsolve2; A = nothing, b = _vec(cubuff1), linu = _vec(dw23)) + linres2 = dolinsolve( + integrator, linsolve2; A = nothing, b = _vec(cubuff1), linu = _vec(dw23)) end cache.linsolve2 = linres2.cache @@ -1208,9 +1213,11 @@ end linsolve3 = cache.linsolve3 if needfactor - linres3 = dolinsolve(integrator, linsolve3; A = W3, b = _vec(cubuff2), linu = _vec(dw45)) + linres3 = dolinsolve( + integrator, linsolve3; A = W3, b = _vec(cubuff2), linu = _vec(dw45)) else - linres3 = dolinsolve(integrator, linsolve3; A = nothing, b = _vec(cubuff2), linu = _vec(dw45)) + linres3 = dolinsolve( + integrator, linsolve3; A = nothing, b = _vec(cubuff2), linu = _vec(dw45)) end cache.linsolve3 = linres3.cache @@ -1352,7 +1359,7 @@ end end @muladd function perform_step!(integrator, cache::AdaptiveRadauConstantCache, - repeat_step = false) + repeat_step = false) @unpack t, dt, uprev, u, f, p = integrator @unpack tabs, num_stages, index = cache tab = tabs[index] @@ -1377,14 +1384,14 @@ end LU1 = lu(-γdt * mass_matrix + J) tmp = lu(-(αdt[1] + βdt[1] * im) * mass_matrix + J) end - LU2 = Vector{typeof(tmp)}(undef, (num_stages - 1) ÷ 2) + LU2 = Vector{typeof(tmp)}(undef, (num_stages - 1) ÷ 2) LU2[1] = tmp if u isa Number - for i in 2 : (num_stages - 1) ÷ 2 + for i in 2:((num_stages - 1) ÷ 2) LU2[i] = -(αdt[i] + βdt[i] * im) * mass_matrix + J end else - for i in 2 : (num_stages - 1) ÷ 2 + for i in 2:((num_stages - 1) ÷ 2) LU2[i] = lu(-(αdt[i] + βdt[i] * im) * mass_matrix + J) end end @@ -1394,7 +1401,7 @@ end w = Vector{typeof(u)}(undef, num_stages) if integrator.iter == 1 || integrator.u_modified || alg.extrapolant == :constant cache.dtprev = one(cache.dtprev) - for i in 1 : num_stages + for i in 1:num_stages z[i] = @.. map(zero, u) w[i] = @.. map(zero, u) cache.cont[i] = @.. map(zero, u) @@ -1402,10 +1409,10 @@ end else c_prime = Vector{typeof(dt)}(undef, num_stages) #time stepping c_prime[num_stages] = dt / cache.dtprev - for i in 1 : num_stages - 1 + for i in 1:(num_stages - 1) c_prime[i] = c[i] * c_prime[num_stages] end - for i in 1 : num_stages # collocation polynomial + for i in 1:num_stages # collocation polynomial z[i] = @.. cont[num_stages - 1] + cont[num_stages] * (c_prime[i] - c[1] + 1) j = num_stages - 2 while j > 0 @@ -1418,7 +1425,7 @@ end for i in 1:num_stages w[i] = @.. zero(u) for j in 1:num_stages - w[i] = @.. w[i] + TI[i,j] * z[j] + w[i] = @.. w[i] + TI[i, j] * z[j] end end end @@ -1434,23 +1441,23 @@ end # evaluate function #ff = Vector{typeof(u)}(undef, num_stages) - for i in 1 : num_stages + for i in 1:num_stages z[i] = f(uprev + z[i], p, t + c[i] * dt) end OrdinaryDiffEqCore.increment_nf!(integrator.stats, num_stages) #fw = TI * ff fw = Vector{typeof(u)}(undef, num_stages) - for i in 1 : num_stages + for i in 1:num_stages fw[i] = @.. zero(u) for j in 1:num_stages - fw[i] = @.. fw[i] + TI[i,j] * z[j] + fw[i] = @.. fw[i] + TI[i, j] * z[j] end end #Mw = Vector{typeof(u)}(undef, num_stages) if mass_matrix isa UniformScaling # `UniformScaling` doesn't play nicely with broadcast - for i in 1 : num_stages + for i in 1:num_stages z[i] = @.. mass_matrix.λ * w[i] #scaling by eigenvalue end else @@ -1468,18 +1475,20 @@ end #dw = Vector{typeof(u)}(undef, num_stages) z[1] = _reshape(LU1 \ _vec(rhs[1]), axes(u)) - for i in 2 :(num_stages + 1) ÷ 2 - tmp = _reshape(LU2[i - 1] \ _vec(@.. rhs[2 * i - 2] + rhs[2 * i - 1] * im), axes(u)) + for i in 2:((num_stages + 1) ÷ 2) + tmp = _reshape( + LU2[i - 1] \ _vec(@.. rhs[2 * i - 2] + rhs[2 * i - 1] * im), axes(u)) z[2 * i - 2] = @.. real(tmp) z[2 * i - 1] = @.. imag(tmp) end - integrator.stats.nsolve +=(num_stages + 1) ÷ 2 + integrator.stats.nsolve += (num_stages + 1) ÷ 2 # compute norm of residuals iter > 1 && (ndwprev = ndw) ndw = 0.0 - for i in 1 : num_stages - ndw += internalnorm(calculate_residuals(z[i], uprev, u, atol, rtol, internalnorm, t), t) + for i in 1:num_stages + ndw += internalnorm( + calculate_residuals(z[i], uprev, u, atol, rtol, internalnorm, t), t) end # check divergence (not in initial step) @@ -1493,17 +1502,17 @@ end break end end - - for i in 1 : num_stages + + for i in 1:num_stages w[i] = @.. w[i] - z[i] end # transform `w` to `z` #z = T * w - for i in 1:num_stages - 1 + for i in 1:(num_stages - 1) z[i] = @.. zero(u) for j in 1:num_stages - z[i] = @.. z[i] + T[i,j] * w[j] + z[i] = @.. z[i] + T[i, j] * w[j] end end z[num_stages] = @.. T[num_stages, 1] * w[1] @@ -1513,13 +1522,12 @@ end i += 2 end - # check stopping criterion iter > 1 && (η = θ / (1 - θ)) if η * ndw < κ && (iter > 1 || iszero(ndw) || !iszero(integrator.success_iter)) # Newton method converges cache.status = η < alg.fast_convergence_cutoff ? FastConvergence : - Convergence + Convergence fail_convergence = false break end @@ -1534,15 +1542,15 @@ end cache.iter = iter u = @.. uprev + z[num_stages] - + if adaptive tmp = 0 - for i in 1 : num_stages - tmp = @.. tmp + e[i]/dt * z[i] + for i in 1:num_stages + tmp = @.. tmp + e[i] / dt * z[i] end mass_matrix != I && (tmp = mass_matrix * tmp) #utilde = @.. broadcast=false 1 / γ * dt * integrator.fsalfirst + tmp - utilde = @.. broadcast=false integrator.fsalfirst + tmp + utilde = @.. broadcast=false integrator.fsalfirst+tmp if alg.smooth_est utilde = _reshape(LU1 \ _vec(utilde), axes(u)) integrator.stats.nsolve += 1 @@ -1551,7 +1559,7 @@ end integrator.EEst = internalnorm(atmp, t) if !(integrator.EEst < oneunit(integrator.EEst)) && integrator.iter == 1 || - integrator.u_modified + integrator.u_modified f0 = f(uprev .+ utilde, p, t) OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) #utilde = @.. broadcast=false 1 / γ * dt * f0 + tmp @@ -1569,17 +1577,19 @@ end cache.dtprev = dt if alg.extrapolant != :constant derivatives = Matrix{typeof(u)}(undef, num_stages, num_stages) - derivatives[1, 1] = @.. z[1] / c[1] - for j in 2 : num_stages + derivatives[1, 1] = @.. z[1] / c[1] + for j in 2:num_stages derivatives[1, j] = @.. (z[j - 1] - z[j]) / (c[j - 1] - c[j]) #first derivatives end - for i in 2 : num_stages - derivatives[i, i] = @.. (derivatives[i - 1, i] - derivatives[i - 1, i - 1]) / c[i] - for j in i+1 : num_stages - derivatives[i, j] = @.. (derivatives[i - 1, j - 1] - derivatives[i - 1, j]) / (c[j - i] - c[j]) #all others + for i in 2:num_stages + derivatives[i, i] = @.. (derivatives[i - 1, i] - + derivatives[i - 1, i - 1]) / c[i] + for j in (i + 1):num_stages + derivatives[i, j] = @.. (derivatives[i - 1, j - 1] - + derivatives[i - 1, j]) / (c[j - i] - c[j]) #all others end end - for i in 1 : num_stages + for i in 1:num_stages cache.cont[i] = @.. derivatives[i, num_stages] end end @@ -1598,7 +1608,7 @@ end @unpack num_stages, tabs, index = cache tab = tabs[index] @unpack T, TI, γ, α, β, c, e = tab - @unpack κ, cont, derivatives, z, w, c_prime, αdt, βdt= cache + @unpack κ, cont, derivatives, z, w, c_prime, αdt, βdt = cache @unpack dw1, ubuff, dw2, cubuff, dw = cache @unpack ks, k, fw, J, W1, W2 = cache @unpack tmp, atmp, jac_config, linsolve1, linsolve2, rtol, atol, step_limiter! = cache @@ -1609,9 +1619,9 @@ end # precalculations γdt = γ / dt - for i in 1 : (num_stages - 1) ÷ 2 - αdt[i] = α[i]/dt - βdt[i] = β[i]/dt + for i in 1:((num_stages - 1) ÷ 2) + αdt[i] = α[i] / dt + βdt[i] = β[i] / dt end (new_jac = do_newJ(integrator, alg, cache, repeat_step)) && @@ -1622,17 +1632,20 @@ end end if !isthreaded(alg.threading) @inbounds for II in CartesianIndices(J) - for i in 1 : (num_stages - 1) ÷ 2 + for i in 1:((num_stages - 1) ÷ 2) W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + J[II] end end else - let W1 = W1, W2 = W2, γdt = γdt, αdt = αdt, βdt = βdt, mass_matrix = mass_matrix, + let W1 = W1, W2 = W2, γdt = γdt, αdt = αdt, βdt = βdt, + mass_matrix = mass_matrix, num_stages = num_stages, J = J - @inbounds @threaded alg.threading for i in 1 : (num_stages - 1) ÷ 2 + + @inbounds @threaded alg.threading for i in 1:((num_stages - 1) ÷ 2) for II in CartesianIndices(J) - W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + J[II] - end + W2[i][II] = -(αdt[i] + βdt[i] * im) * mass_matrix[Tuple(II)...] + + J[II] + end end end end @@ -1642,21 +1655,21 @@ end # TODO better initial guess if integrator.iter == 1 || integrator.u_modified || alg.extrapolant == :constant cache.dtprev = one(cache.dtprev) - for i in 1 : num_stages + for i in 1:num_stages @.. z[i] = map(zero, u) @.. w[i] = map(zero, u) @.. cache.cont[i] = map(zero, u) end else c_prime[num_stages] = dt / cache.dtprev - for i in 1 : num_stages - 1 + for i in 1:(num_stages - 1) c_prime[i] = c[i] * c_prime[num_stages] end - for i in 1 : num_stages # collocation polynomial + for i in 1:num_stages # collocation polynomial @.. z[i] = cont[num_stages] * (c_prime[i] - c[1] + 1) + cont[num_stages - 1] j = num_stages - 2 while j > 0 - @.. z[i] *= (c_prime[i] - c[num_stages - j] + 1) + @.. z[i] *= (c_prime[i] - c[num_stages - j] + 1) @.. z[i] += cont[j] j = j - 1 end @@ -1666,7 +1679,7 @@ end for i in 1:num_stages @.. w[i] = zero(u) for j in 1:num_stages - @.. w[i] += TI[i,j] * z[j] + @.. w[i] += TI[i, j] * z[j] end end end @@ -1682,7 +1695,7 @@ end # evaluate function ks[1] = fsallast - for i in 1 : num_stages + for i in 1:num_stages @.. tmp = uprev + z[i] f(ks[i], tmp, p, t + c[i] * dt) end @@ -1692,19 +1705,19 @@ end for i in 1:num_stages @.. fw[i] = zero(u) for j in 1:num_stages - @.. fw[i] += TI[i,j] * ks[j] + @.. fw[i] += TI[i, j] * ks[j] end end if mass_matrix === I Mw = w elseif mass_matrix isa UniformScaling - for i in 1 : num_stages - mul!(z[i], mass_matrix.λ, w[i]) + for i in 1:num_stages + mul!(z[i], mass_matrix.λ, w[i]) end Mw = z else - for i in 1 : num_stages + for i in 1:num_stages mul!(z[i], mass_matrix, w[i]) end Mw = z @@ -1714,38 +1727,52 @@ end needfactor = iter == 1 && new_W if needfactor - cache.linsolve1 = dolinsolve(integrator, linsolve1; A = W1, b = _vec(ubuff), linu = _vec(dw1)).cache + cache.linsolve1 = dolinsolve( + integrator, linsolve1; A = W1, b = _vec(ubuff), linu = _vec(dw1)).cache else - cache.linsolve1 = dolinsolve(integrator, linsolve1; A = nothing, b = _vec(ubuff), linu = _vec(dw1)).cache + cache.linsolve1 = dolinsolve( + integrator, linsolve1; A = nothing, b = _vec(ubuff), linu = _vec(dw1)).cache end if !isthreaded(alg.threading) - for i in 1 :(num_stages - 1) ÷ 2 - @.. cubuff[i]=complex(fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) + for i in 1:((num_stages - 1) ÷ 2) + @.. cubuff[i] = complex( + fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], + fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) if needfactor - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], + b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache else - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, + b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache end end else - let integrator = integrator, linsolve2 = linsolve2, fw = fw, αdt = αdt, βdt = βdt, Mw = Mw, W1 = W1, W2 = W2, - cubuff = cubuff, dw2 = dw2, needfactor = needfactor - @threaded alg.threading for i in 1:(num_stages - 1) ÷ 2 + let integrator = integrator, linsolve2 = linsolve2, fw = fw, αdt = αdt, + βdt = βdt, Mw = Mw, W1 = W1, W2 = W2, + cubuff = cubuff, dw2 = dw2, needfactor = needfactor + + @threaded alg.threading for i in 1:((num_stages - 1) ÷ 2) #@show i == Threads.threadid() - @.. cubuff[i]=complex(fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) + @.. cubuff[i] = complex( + fw[2 * i] - αdt[i] * Mw[2 * i] + βdt[i] * Mw[2 * i + 1], + fw[2 * i + 1] - βdt[i] * Mw[2 * i] - αdt[i] * Mw[2 * i + 1]) if needfactor - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = W2[i], b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + cache.linsolve2[i] = dolinsolve( + integrator, linsolve2[i]; A = W2[i], + b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache else - cache.linsolve2[i] = dolinsolve(integrator, linsolve2[i]; A = nothing, b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache + cache.linsolve2[i] = dolinsolve( + integrator, linsolve2[i]; A = nothing, + b = _vec(cubuff[i]), linu = _vec(dw2[i])).cache end end end end - + integrator.stats.nsolve += (num_stages + 1) / 2 - for i in 1 : (num_stages - 1) ÷ 2 + for i in 1:((num_stages - 1) ÷ 2) @.. dw[2 * i - 1] = real(dw2[i]) @.. dw[2 * i] = imag(dw2[i]) end @@ -1754,7 +1781,7 @@ end iter > 1 && (ndwprev = ndw) calculate_residuals!(atmp, dw1, uprev, u, atol, rtol, internalnorm, t) ndw = internalnorm(atmp, t) - for i in 2 : num_stages + for i in 2:num_stages calculate_residuals!(atmp, dw[i - 1], uprev, u, atol, rtol, internalnorm, t) ndw += internalnorm(atmp, t) end @@ -1771,17 +1798,17 @@ end end end - @.. w[1] = w[1] - dw1 - for i in 2 : num_stages + @.. w[1] = w[1] - dw1 + for i in 2:num_stages @.. w[i] = w[i] - dw[i - 1] end # transform `w` to `z` #mul!(z, T, w) - for i in 1:num_stages - 1 + for i in 1:(num_stages - 1) @.. z[i] = zero(u) for j in 1:num_stages - @.. z[i] += T[i,j] * w[j] + @.. z[i] += T[i, j] * w[j] end end @.. z[num_stages] = T[num_stages, 1] * w[1] @@ -1813,12 +1840,12 @@ end @.. broadcast=false u=uprev + z[num_stages] step_limiter!(u, integrator, p, t + dt) - + if adaptive utilde = w[2] @.. tmp = 0 - for i in 1 : num_stages - @.. tmp += e[i]/dt * z[i] + for i in 1:num_stages + @.. tmp += e[i] / dt * z[i] end mass_matrix != I && (mul!(w[1], mass_matrix, tmp); copyto!(tmp, w[1])) #@.. ubuff=1 / γ * dt * integrator.fsalfirst + tmp @@ -1826,7 +1853,7 @@ end if alg.smooth_est cache.linsolve1 = dolinsolve(integrator, linsolve1; b = _vec(ubuff), - linu = _vec(utilde)).cache + linu = _vec(utilde)).cache integrator.stats.nsolve += 1 end @@ -1845,7 +1872,7 @@ end if alg.smooth_est cache.linsolve1 = dolinsolve(integrator, linsolve1; b = _vec(ubuff), - linu = _vec(utilde)).cache + linu = _vec(utilde)).cache integrator.stats.nsolve += 1 end @@ -1858,16 +1885,18 @@ end cache.dtprev = dt if alg.extrapolant != :constant @.. derivatives[1, 1] = z[1] / c[1] - for j in 2 : num_stages + for j in 2:num_stages @.. derivatives[1, j] = (z[j - 1] - z[j]) / (c[j - 1] - c[j]) #first derivatives end - for i in 2 : num_stages - @.. derivatives[i, i] = (derivatives[i - 1, i] - derivatives[i - 1, i - 1]) / c[i] - for j in i+1 : num_stages - @.. derivatives[i, j] = (derivatives[i - 1, j - 1] - derivatives[i - 1, j]) / (c[j - i] - c[j]) #all others + for i in 2:num_stages + @.. derivatives[i, i] = (derivatives[i - 1, i] - + derivatives[i - 1, i - 1]) / c[i] + for j in (i + 1):num_stages + @.. derivatives[i, j] = (derivatives[i - 1, j - 1] - + derivatives[i - 1, j]) / (c[j - i] - c[j]) #all others end end - for i in 1 : num_stages + for i in 1:num_stages @.. cache.cont[i] = derivatives[i, num_stages] end end @@ -1877,4 +1906,3 @@ end integrator.stats.nf += 1 return end - diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl b/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl index 398d8445e9..f2b92910a9 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl @@ -273,7 +273,7 @@ import LinearAlgebra: eigen import FastGaussQuadrature: gaussradau function RadauIIATableau{T1, T2}(tab::RadauIIATableau{T1, T2}) where {T1, T2} - RadauIIATableau{T1, T2}(tab.T, tab.TI, tab.c, tab.γ,tab.α, tab.β, tab.e) + RadauIIATableau{T1, T2}(tab.T, tab.TI, tab.c, tab.γ, tab.α, tab.β, tab.e) end function RadauIIATableau(T1, T2, num_stages::Int) @@ -286,29 +286,29 @@ function RadauIIATableau(T1, T2, num_stages::Int) end function generateRadauTableau(T1, T2, num_stages::Int) - c = reverse!(1 .- gaussradau(num_stages, T1)[1])./2 + c = reverse!(1 .- gaussradau(num_stages, T1)[1]) ./ 2 if T1 == T2 c2 = c else - c2 = reverse!(1 .- gaussradau(num_stages, T2)[1])./2 + c2 = reverse!(1 .- gaussradau(num_stages, T2)[1]) ./ 2 end c_powers = Matrix{T1}(undef, num_stages, num_stages) - for i in 1 : num_stages + for i in 1:num_stages c_powers[i, 1] = 1 - for j in 2 : num_stages - c_powers[i,j] = c[i]*c_powers[i,j-1] + for j in 2:num_stages + c_powers[i, j] = c[i] * c_powers[i, j - 1] end end c_q = Matrix{T1}(undef, num_stages, num_stages) - for i in 1 : num_stages - for j in 1 : num_stages - c_q[i,j] = c_powers[i,j] * c[i] / j + for i in 1:num_stages + for j in 1:num_stages + c_q[i, j] = c_powers[i, j] * c[i] / j end end a = c_q / c_powers - local eigval, eigvec; + local eigval, eigvec try eigval, eigvec = eigen(a) catch @@ -316,8 +316,8 @@ function generateRadauTableau(T1, T2, num_stages::Int) end # α, β, and γ come from eigvals(inv(a)) which are equal to inv.(eivals(a)) eigval .= inv.(eigval) - α = [real(eigval[i]) for i in 1:2:num_stages-1] - β = [imag(eigval[i]) for i in 1:2:num_stages-1] + α = [real(eigval[i]) for i in 1:2:(num_stages - 1)] + β = [imag(eigval[i]) for i in 1:2:(num_stages - 1)] γ = real(eigval[num_stages]) T = Matrix{T1}(undef, num_stages, num_stages) @@ -328,14 +328,15 @@ function generateRadauTableau(T1, T2, num_stages::Int) @views T[:, 1] .= real.(eigvec[:, num_stages]) TI = inv(T) # TODO: figure out why all the order conditions are the same - A = c_powers'./(1:num_stages) + A = c_powers' ./ (1:num_stages) # TODO: figure out why these are the right b - b = vcat(-(num_stages)^2, -.5, zeros(num_stages - 2)) + b = vcat(-(num_stages)^2, -0.5, zeros(num_stages - 2)) e = A \ b tab = RadauIIATableau{T1, T2}(T, TI, c2, γ, α, β, e) end -const RadauIIATableauCache = Dict{Tuple{Type,Type,Int}, RadauIIATableau{T1, T2} where {T1, T2}}( - (Float64, Float64, 3)=>generateRadauTableau(Float64, Float64, 3), - (Float64, Float64, 5)=>generateRadauTableau(Float64, Float64, 5), - (Float64, Float64, 7)=>generateRadauTableau(Float64, Float64, 7),) +const RadauIIATableauCache = Dict{ + Tuple{Type, Type, Int}, RadauIIATableau{T1, T2} where {T1, T2}}( + (Float64, Float64, 3) => generateRadauTableau(Float64, Float64, 3), + (Float64, Float64, 5) => generateRadauTableau(Float64, Float64, 5), + (Float64, Float64, 7) => generateRadauTableau(Float64, Float64, 7)) diff --git a/lib/OrdinaryDiffEqFIRK/src/integrator_interface.jl b/lib/OrdinaryDiffEqFIRK/src/integrator_interface.jl index dc4bbb1e88..2cf4563276 100644 --- a/lib/OrdinaryDiffEqFIRK/src/integrator_interface.jl +++ b/lib/OrdinaryDiffEqFIRK/src/integrator_interface.jl @@ -1,4 +1,5 @@ -@inline function DiffEqBase.get_tmp_cache(integrator, alg::Union{RadauIIA3, RadauIIA5, RadauIIA9, AdaptiveRadau}, +@inline function DiffEqBase.get_tmp_cache( + integrator, alg::Union{RadauIIA3, RadauIIA5, RadauIIA9, AdaptiveRadau}, cache::OrdinaryDiffEqMutableCache) (cache.tmp, cache.atmp) end diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl index 29753d5e12..7fd21b7d99 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl @@ -16,21 +16,26 @@ sim21 = test_convergence(1 ./ 2 .^ (2.5:-1:0.5), prob_ode_2Dlinear, RadauIIA9()) using GenericSchur -prob_ode_linear_big = remake(prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) -prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), tspan = big.(prob_ode_2Dlinear.tspan)) +prob_ode_linear_big = remake( + prob_ode_linear, u0 = big.(prob_ode_linear.u0), tspan = big.(prob_ode_linear.tspan)) +prob_ode_2Dlinear_big = remake(prob_ode_2Dlinear, u0 = big.(prob_ode_2Dlinear.u0), + tspan = big.(prob_ode_2Dlinear.tspan)) #non-threaded tests for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] dts = 1 ./ 2 .^ (4.25:-1:0.25) local sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i)) - @test sim21.𝒪est[:final]≈ i atol=testTol + @test sim21.𝒪est[:final]≈i atol=testTol end #threaded tests using OrdinaryDiffEqCore for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear_big] dts = 1 ./ 2 .^ (4.25:-1:0.25) - local sim21 = test_convergence(dts, prob, AdaptiveRadau(min_order = i, max_order = i, threading = OrdinaryDiffEqCore.PolyesterThreads())) - @test sim21.𝒪est[:final]≈ i atol=testTol + local sim21 = test_convergence(dts, + prob, + AdaptiveRadau(min_order = i, max_order = i, + threading = OrdinaryDiffEqCore.PolyesterThreads())) + @test sim21.𝒪est[:final]≈i atol=testTol end # test adaptivity @@ -76,4 +81,4 @@ for iip in (true, false) @test sol.stats.njacs < sol.stats.nw # W reuse end @test length(sol) < 5000 # the error estimate is not very good -end \ No newline at end of file +end diff --git a/lib/OrdinaryDiffEqFIRK/test/runtests.jl b/lib/OrdinaryDiffEqFIRK/test/runtests.jl index b252cdf8f2..39ede8c3b3 100644 --- a/lib/OrdinaryDiffEqFIRK/test/runtests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/runtests.jl @@ -1,3 +1,3 @@ using SafeTestsets -@time @safetestset "FIRK Tests" include("ode_firk_tests.jl") \ No newline at end of file +@time @safetestset "FIRK Tests" include("ode_firk_tests.jl") diff --git a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl index 7bbcc0476b..7f81a7c925 100644 --- a/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl +++ b/lib/OrdinaryDiffEqIMEXMultistep/src/algorithms.jl @@ -29,11 +29,11 @@ struct CNAB2{CS, AD, F, F2, P, FDT, ST, CJ} <: autodiff::AD end -function CNAB2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function CNAB2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNAB2{ @@ -73,11 +73,11 @@ struct CNLF2{CS, AD, F, F2, P, FDT, ST, CJ} <: extrapolant::Symbol autodiff::AD end -function CNLF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function CNLF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CNLF2{ diff --git a/lib/OrdinaryDiffEqLinear/src/linear_caches.jl b/lib/OrdinaryDiffEqLinear/src/linear_caches.jl index 14aaeb0692..c2867776d1 100644 --- a/lib/OrdinaryDiffEqLinear/src/linear_caches.jl +++ b/lib/OrdinaryDiffEqLinear/src/linear_caches.jl @@ -571,9 +571,10 @@ function _phiv_timestep_caches(u_prototype, maxiter::Int, p::Int) n = length(u_prototype) T = eltype(u_prototype) u = zero(u_prototype) # stores the current state - W = similar(u_prototype, n, p+1) # stores the w vectors - P = similar(u_prototype, n, p+2) # stores output from phiv! - Ks = KrylovSubspace{T,T,typeof(similar(u_prototype,size(u_prototype,1),2))}(n, maxiter) # stores output from arnoldi! + W = similar(u_prototype, n, p + 1) # stores the w vectors + P = similar(u_prototype, n, p + 2) # stores output from phiv! + Ks = KrylovSubspace{T, T, typeof(similar(u_prototype, size(u_prototype, 1), 2))}( + n, maxiter) # stores output from arnoldi! phiv_cache = PhivCache(u_prototype, maxiter, p + 1) # cache used by phiv! (need +1 for error estimation) return u, W, P, Ks, phiv_cache end @@ -591,7 +592,7 @@ function alg_cache(alg::LinearExponential, u, rate_prototype, ::Type{uEltypeNoUn if alg.krylov == :off KsCache = nothing elseif alg.krylov == :simple - Ks = KrylovSubspace{T,T,typeof(similar(u,size(u,1),2))}(n, m) + Ks = KrylovSubspace{T, T, typeof(similar(u, size(u, 1), 2))}(n, m) expv_cache = ExpvCache{T}(m) KsCache = (Ks, expv_cache) elseif alg.krylov == :adaptive diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 659278af97..3c28ef913c 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -11,7 +11,8 @@ using SciMLBase: DAEFunction, DEIntegrator, NonlinearFunction, NonlinearProblem, import DiffEqBase import PreallocationTools using SimpleNonlinearSolve: SimpleTrustRegion, SimpleGaussNewton -using NonlinearSolve: FastShortcutNonlinearPolyalg, FastShortcutNLLSPolyalg, NewtonRaphson, step! +using NonlinearSolve: FastShortcutNonlinearPolyalg, FastShortcutNLLSPolyalg, NewtonRaphson, + step! using MuladdMacro, FastBroadcast import FastClosures: @closure using LinearAlgebra: UniformScaling, UpperTriangular diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl index 994ecea696..d5e47246af 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl @@ -229,8 +229,9 @@ end reltol = reltol) end - if !SciMLBase.successful_retcode(linres.retcode) && linres.retcode != SciMLBase.ReturnCode.Default - return convert(eltype(atmp,),Inf) + if !SciMLBase.successful_retcode(linres.retcode) && + linres.retcode != SciMLBase.ReturnCode.Default + return convert(eltype(atmp,), Inf) end cache.linsolve = linres.cache diff --git a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl index f87c6ce19b..d32f448193 100644 --- a/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqPDIRK/src/algorithms.jl @@ -30,11 +30,11 @@ struct PDIRK44{CS, AD, F, F2, P, FDT, ST, CJ, TO} <: threading::TO autodiff::AD end -function PDIRK44(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function PDIRK44(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, threading = true) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) PDIRK44{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl index d88df57dc9..98f2a30b3c 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/algorithms.jl @@ -117,7 +117,6 @@ for Alg in [ diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, step_limiter! = trivial_limiter!, stage_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(precs), diff_type, _unwrap_val(standardtag), @@ -137,7 +136,6 @@ end function GeneralRosenbrock(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, factorization = lu!, tableau = ROSENBROCK_DEFAULT_TABLEAU) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) GeneralRosenbrock{ @@ -165,7 +163,6 @@ function RosenbrockW6S4OS(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), concrete_jac = nothing, diff_type = Val{:central}, linsolve = nothing, precs = DEFAULT_PRECS) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) RosenbrockW6S4OS{_unwrap_val(chunk_size), @@ -205,7 +202,6 @@ for Alg in [ function $Alg(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) $Alg{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl index 33fc5dcd2b..34fa9e3dd7 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_caches.jl @@ -48,7 +48,8 @@ function full_cache(c::RosenbrockCache) c.ks..., c.fsalfirst, c.fsallast, c.dT, c.tmp, c.atmp, c.weight, c.linsolve_tmp] end -struct RosenbrockCombinedConstantCache{TF, UF, Tab, JType, WType, F, AD} <: RosenbrockConstantCache +struct RosenbrockCombinedConstantCache{TF, UF, Tab, JType, WType, F, AD} <: + RosenbrockConstantCache tf::TF uf::UF tab::Tab @@ -723,7 +724,8 @@ tabtype(::Rodas5P) = Rodas5PTableau tabtype(::Rodas5Pr) = Rodas5PTableau tabtype(::Rodas5Pe) = Rodas5PTableau -function alg_cache(alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}, +function alg_cache( + alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}, u, rate_prototype, ::Type{uEltypeNoUnits}, ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck, @@ -739,12 +741,12 @@ function alg_cache(alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5 alg_autodiff(alg), size(tab.H, 1)) end -function alg_cache(alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}, +function alg_cache( + alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr}, u, rate_prototype, ::Type{uEltypeNoUnits}, ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck, ::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits} - tab = tabtype(alg)(constvalue(uBottomEltypeNoUnits), constvalue(tTypeNoUnits)) # Initialize vectors dense = [zero(rate_prototype) for _ in 1:size(tab.H, 1)] @@ -792,7 +794,6 @@ function alg_cache(alg::Union{Rodas4, Rodas42, Rodas4P, Rodas4P2, Rodas5, Rodas5 alg.step_limiter!, alg.stage_limiter!, size(tab.H, 1)) end - function get_fsalfirstlast( cache::Union{Rosenbrock23Cache, Rosenbrock32Cache, Rosenbrock33Cache, Rosenbrock34Cache, diff --git a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl index 003595567e..365b15e10f 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_interpolants.jl @@ -49,7 +49,7 @@ end cache::Union{Rosenbrock23Cache, Rosenbrock32Cache}, idxs::Nothing, T::Type{Val{0}}, differential_vars) @rosenbrock2332pre0 - @inbounds @.. y₀+dt * (c1 * k[1] + c2 * k[2]) + @inbounds @.. y₀ + dt * (c1 * k[1] + c2 * k[2]) end @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, @@ -57,7 +57,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs, T::Type{Val{0}}, differential_vars) @rosenbrock2332pre0 - @.. y₀[idxs]+dt * (c1 * k[1][idxs] + c2 * k[2][idxs]) + @.. y₀[idxs] + dt * (c1 * k[1][idxs] + c2 * k[2][idxs]) end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, @@ -66,7 +66,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs::Nothing, T::Type{Val{0}}, differential_vars) @rosenbrock2332pre0 - @inbounds @.. out=y₀ + dt * (c1 * k[1] + c2 * k[2]) + @inbounds @.. out = y₀ + dt * (c1 * k[1] + c2 * k[2]) out end @@ -76,7 +76,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs, T::Type{Val{0}}, differential_vars) @rosenbrock2332pre0 - @views @.. out=y₀[idxs] + dt * (c1 * k[1][idxs] + c2 * k[2][idxs]) + @views @.. out = y₀[idxs] + dt * (c1 * k[1][idxs] + c2 * k[2][idxs]) out end @@ -92,7 +92,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs::Nothing, T::Type{Val{1}}, differential_vars) @rosenbrock2332pre1 - @.. c1diff * k[1]+c2diff * k[2] + @.. c1diff * k[1] + c2diff * k[2] end @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, @@ -100,7 +100,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs, T::Type{Val{1}}, differential_vars) @rosenbrock2332pre1 - @.. c1diff * k[1][idxs]+c2diff * k[2][idxs] + @.. c1diff * k[1][idxs] + c2diff * k[2][idxs] end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, @@ -109,7 +109,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs::Nothing, T::Type{Val{1}}, differential_vars) @rosenbrock2332pre1 - @.. out=c1diff * k[1] + c2diff * k[2] + @.. out = c1diff * k[1] + c2diff * k[2] out end @@ -119,7 +119,7 @@ end Rosenbrock32ConstantCache, Rosenbrock32Cache }, idxs, T::Type{Val{1}}, differential_vars) @rosenbrock2332pre1 - @views @.. out=c1diff * k[1][idxs] + c2diff * k[2][idxs] + @views @.. out = c1diff * k[1][idxs] + c2diff * k[2][idxs] out end @@ -128,108 +128,132 @@ From MATLAB ODE Suite by Shampine """ @muladd function _ode_interpolant( - Θ, dt, y₀, y₁, k, cache::Union{RosenbrockCombinedConstantCache, Rodas23WConstantCache, Rodas3PConstantCache, RosenbrockCache, Rodas23WCache, Rodas3PCache}, + Θ, dt, + y₀, + y₁, + k, + cache::Union{RosenbrockCombinedConstantCache, Rodas23WConstantCache, + Rodas3PConstantCache, RosenbrockCache, Rodas23WCache, Rodas3PCache}, idxs::Nothing, T::Type{Val{0}}, differential_vars) Θ1 = 1 - Θ if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @.. Θ1 * y₀+Θ * (y₁ + Θ1 * (k[1] + Θ * k[2])) + @.. Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * k[2])) else - @.. Θ1 * y₀+Θ * (y₁ + Θ1 * (k[1] + Θ * (k[2] + Θ * k[3]))) + @.. Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * (k[2] + Θ * k[3]))) end end @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs, T::Type{Val{0}}, differential_vars) Θ1 = 1 - Θ if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @views @.. Θ1 * y₀[idxs]+Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * k[2][idxs])) + @views @.. Θ1 * y₀[idxs] + Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * k[2][idxs])) else - @views @.. Θ1 * y₀[idxs]+Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * (k[2][idxs] + Θ * k[3][idxs]))) + @views @.. Θ1 * y₀[idxs] + + Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * (k[2][idxs] + Θ * k[3][idxs]))) end end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs::Nothing, T::Type{Val{0}}, differential_vars) Θ1 = 1 - Θ if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @.. out=Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * k[2])) + @.. out = Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * k[2])) else - @.. out=Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * (k[2] + Θ * k[3]))) + @.. out = Θ1 * y₀ + Θ * (y₁ + Θ1 * (k[1] + Θ * (k[2] + Θ * k[3]))) end out end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs, T::Type{Val{0}}, differential_vars) Θ1 = 1 - Θ if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @views @.. out=Θ1 * y₀[idxs] + Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * k[2][idxs])) + @views @.. out = Θ1 * y₀[idxs] + Θ * (y₁[idxs] + Θ1 * (k[1][idxs] + Θ * k[2][idxs])) else - @views @.. out=Θ1 * y₀[idxs]+Θ * (y₁[idxs] + - Θ1 * (k[1][idxs] + Θ * (k[2][idxs] + Θ * k[3][idxs]))) + @views @.. out = Θ1 * y₀[idxs] + + Θ * (y₁[idxs] + + Θ1 * (k[1][idxs] + Θ * (k[2][idxs] + Θ * k[3][idxs]))) end out end # First Derivative @muladd function _ode_interpolant( - Θ, dt, y₀, y₁, k, cache::Union{RosenbrockCache, Rodas23WCache, Rodas3PCache, RosenbrockCombinedConstantCache, Rodas23WConstantCache, Rodas3PConstantCache}, + Θ, dt, + y₀, + y₁, + k, + cache::Union{ + RosenbrockCache, Rodas23WCache, Rodas3PCache, RosenbrockCombinedConstantCache, + Rodas23WConstantCache, Rodas3PConstantCache}, idxs::Nothing, T::Type{Val{1}}, differential_vars) if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @.. (k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁)/dt + @.. (k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁) / dt else - @.. (k[1] + Θ * (-2 * k[1] + 2 * k[2] + - Θ * (-3 * k[2] + 3 * k[3] - 4 * Θ * k[3])) - - y₀ + y₁)/dt + @.. (k[1] + Θ * (-2 * k[1] + 2 * k[2] + + Θ * (-3 * k[2] + 3 * k[3] - 4 * Θ * k[3])) - + y₀ + y₁) / dt end end @muladd function _ode_interpolant(Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs, T::Type{Val{1}}, differential_vars) if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @views @.. (k[1][idxs] + Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] - 3 * k[2][idxs] * Θ) - - y₀[idxs] + y₁[idxs])/dt + @views @.. (k[1][idxs] + + Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] - 3 * k[2][idxs] * Θ) - + y₀[idxs] + y₁[idxs]) / dt else - @views @.. (k[1][idxs] + Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] + - Θ * (-3 * k[2][idxs] + 3 * k[3][idxs] - 4 * Θ * k[3][idxs])) - y₀[idxs] + y₁[idxs])/dt + @views @.. (k[1][idxs] + + Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] + + Θ * (-3 * k[2][idxs] + 3 * k[3][idxs] - 4 * Θ * k[3][idxs])) - + y₀[idxs] + y₁[idxs]) / dt end end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs::Nothing, T::Type{Val{1}}, differential_vars) if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @.. out=(k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁) / dt + @.. out = (k[1] + Θ * (-2 * k[1] + 2 * k[2] - 3 * k[2] * Θ) - y₀ + y₁) / dt else - @.. out=(k[1] + Θ * (-2 * k[1] + 2 * k[2] + - Θ * (-3 * k[2] + 3 * k[3] - 4 * Θ * k[3])) - y₀ + y₁) / dt + @.. out = (k[1] + + Θ * (-2 * k[1] + 2 * k[2] + + Θ * (-3 * k[2] + 3 * k[3] - 4 * Θ * k[3])) - y₀ + y₁) / dt end out end @muladd function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, - cache::Union{RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, + cache::Union{ + RosenbrockCombinedConstantCache, RosenbrockCache, Rodas23WConstantCache, Rodas23WCache, Rodas3PConstantCache, Rodas3PCache}, idxs, T::Type{Val{1}}, differential_vars) if !hasproperty(cache, :interp_order) || cache.interp_order == 2 - @views @.. out=(k[1][idxs] + - Θ * - (-2 * k[1][idxs] + 2 * k[2][idxs] - - 3 * k[2][idxs] * Θ) - - y₀[idxs] + y₁[idxs]) / dt + @views @.. out = (k[1][idxs] + + Θ * + (-2 * k[1][idxs] + 2 * k[2][idxs] - + 3 * k[2][idxs] * Θ) - + y₀[idxs] + y₁[idxs]) / dt else @views @.. broadcast=false out=(k[1][idxs] + Θ * (-2 * k[1][idxs] + 2 * k[2][idxs] + Θ * - (-3 * k[2][idxs] + 3 * k[3][idxs] - 4 * Θ * k[3][idxs])) - + (-3 * k[2][idxs] + 3 * k[3][idxs] - + 4 * Θ * k[3][idxs])) - y₀[idxs] + y₁[idxs]) / dt end out diff --git a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl index 1414a93f92..773f1eb7f5 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_perform_step.jl @@ -1206,15 +1206,16 @@ function initialize!(integrator, cache::RosenbrockCombinedConstantCache) integrator.kshortsize = size(cache.tab.H, 1) integrator.k = typeof(integrator.k)(undef, integrator.kshortsize) # Avoid undefined entries if k is an array of arrays - for i in 1:integrator.kshortsize + for i in 1:(integrator.kshortsize) integrator.k[i] = zero(integrator.u) end end -@muladd function perform_step!(integrator, cache::RosenbrockCombinedConstantCache, repeat_step = false) - (;t, dt, uprev, u, f, p) = integrator - (;tf, uf) = cache - (;A, C, gamma, c, d, H) = cache.tab +@muladd function perform_step!( + integrator, cache::RosenbrockCombinedConstantCache, repeat_step = false) + (; t, dt, uprev, u, f, p) = integrator + (; tf, uf) = cache + (; A, C, gamma, c, d, H) = cache.tab # Precalculations dtC = C ./ dt @@ -1287,20 +1288,20 @@ end end end if (integrator.alg isa Rodas5Pr) && integrator.opts.adaptive && - (integrator.EEst < 1.0) - k2 = 0.5 * (uprev + u + - 0.5 * (integrator.k[1] + 0.5 * (integrator.k[2] + 0.5 * integrator.k[3]))) - du1 = (0.25 * (integrator.k[2] + integrator.k[3]) - uprev + u) / dt - du = f(k2, p, t + dt / 2) - OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - if mass_matrix === I - du2 = du1 - du - else - du2 = mass_matrix * du1 - du - end - EEst = norm(du2) / norm(integrator.opts.abstol .+ integrator.opts.reltol .* k2) - integrator.EEst = max(EEst, integrator.EEst) - end + (integrator.EEst < 1.0) + k2 = 0.5 * (uprev + u + + 0.5 * (integrator.k[1] + 0.5 * (integrator.k[2] + 0.5 * integrator.k[3]))) + du1 = (0.25 * (integrator.k[2] + integrator.k[3]) - uprev + u) / dt + du = f(k2, p, t + dt / 2) + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) + if mass_matrix === I + du2 = du1 - du + else + du2 = mass_matrix * du1 - du + end + EEst = norm(du2) / norm(integrator.opts.abstol .+ integrator.opts.reltol .* k2) + integrator.EEst = max(EEst, integrator.EEst) + end end integrator.u = u @@ -1310,7 +1311,7 @@ end function initialize!(integrator, cache::RosenbrockCache) integrator.kshortsize = size(cache.tab.H, 1) resize!(integrator.k, integrator.kshortsize) - for i in 1:integrator.kshortsize + for i in 1:(integrator.kshortsize) integrator.k[i] = cache.dense[i] end end @@ -1389,9 +1390,9 @@ end if integrator.opts.adaptive if (integrator.alg isa Rodas5Pe) @.. du = 0.2606326497975715 * ks[1] - 0.005158627295444251 * ks[2] + - 1.3038988631109731 * ks[3] + 1.235000722062074 * ks[4] + - -0.7931985603795049 * ks[5] - 1.005448461135913 * ks[6] - - 0.18044626132120234 * ks[7] + 0.17051519239113755 * ks[8] + 1.3038988631109731 * ks[3] + 1.235000722062074 * ks[4] + + -0.7931985603795049 * ks[5] - 1.005448461135913 * ks[6] - + 0.18044626132120234 * ks[7] + 0.17051519239113755 * ks[8] end calculate_residuals!(atmp, ks[end], uprev, u, integrator.opts.abstol, integrator.opts.reltol, integrator.opts.internalnorm, t) @@ -1408,21 +1409,23 @@ end end end if (integrator.alg isa Rodas5Pr) && integrator.opts.adaptive && - (integrator.EEst < 1.0) - ks[2] = 0.5 * (uprev + u + - 0.5 * (integrator.k[1] + 0.5 * (integrator.k[2] + 0.5 * integrator.k[3]))) - du1 = (0.25 * (integrator.k[2] + integrator.k[3]) - uprev + u) / dt - f(du, ks[2], p, t + dt / 2) - OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) - if mass_matrix === I - @.. du2 = du1 - du - else - mul!(_vec(du2), mass_matrix, _vec(du1)) - @.. du2 -= du - end - EEst = norm(du2) / norm(integrator.opts.abstol .+ integrator.opts.reltol .* ks[2]) - integrator.EEst = max(EEst, integrator.EEst) - end + (integrator.EEst < 1.0) + ks[2] = 0.5 * (uprev + u + + 0.5 * + (integrator.k[1] + 0.5 * (integrator.k[2] + 0.5 * integrator.k[3]))) + du1 = (0.25 * (integrator.k[2] + integrator.k[3]) - uprev + u) / dt + f(du, ks[2], p, t + dt / 2) + OrdinaryDiffEqCore.increment_nf!(integrator.stats, 1) + if mass_matrix === I + @.. du2 = du1 - du + else + mul!(_vec(du2), mass_matrix, _vec(du1)) + @.. du2 -= du + end + EEst = norm(du2) / + norm(integrator.opts.abstol .+ integrator.opts.reltol .* ks[2]) + integrator.EEst = max(EEst, integrator.EEst) + end end cache.linsolve = linres.cache end diff --git a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl index 7ed62e5847..9e15ea1ae8 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/rosenbrock_tableaus.jl @@ -236,22 +236,18 @@ function Rodas4Tableau(T, T2) #BET2P=0.0317D0 #BET3P=0.0635D0 #BET4P=0.3438D0 - A = T[ - 0 0 0 0 0 0 - 1.544 0 0 0 0 0 - 0.9466785280815826 0.2557011698983284 0 0 0 0 - 3.314825187068521 2.896124015972201 0.9986419139977817 0 0 0 - 1.221224509226641 6.019134481288629 12.53708332932087 -0.6878860361058950 0 0 - 1.221224509226641 6.019134481288629 12.53708332932087 -0.6878860361058950 1 0 - ] - C = T[ - 0 0 0 0 0 - -5.6688 0 0 0 0 - -2.430093356833875 -0.2063599157091915 0 0 0 - -0.1073529058151375 -9.594562251023355 -20.47028614809616 0 0 - 7.496443313967647 -10.24680431464352 -33.99990352819905 11.70890893206160 0 - 8.083246795921522 -7.981132988064893 -31.52159432874371 16.31930543123136 -6.058818238834054 - ] + A = T[0 0 0 0 0 0 + 1.544 0 0 0 0 0 + 0.9466785280815826 0.2557011698983284 0 0 0 0 + 3.314825187068521 2.896124015972201 0.9986419139977817 0 0 0 + 1.221224509226641 6.019134481288629 12.53708332932087 -0.6878860361058950 0 0 + 1.221224509226641 6.019134481288629 12.53708332932087 -0.6878860361058950 1 0] + C = T[0 0 0 0 0 + -5.6688 0 0 0 0 + -2.430093356833875 -0.2063599157091915 0 0 0 + -0.1073529058151375 -9.594562251023355 -20.47028614809616 0 0 + 7.496443313967647 -10.24680431464352 -33.99990352819905 11.70890893206160 0 + 8.083246795921522 -7.981132988064893 -31.52159432874371 16.31930543123136 -6.058818238834054] c = T2[0, 0.386, 0.21, 0.63, 1, 1] d = T[0.25, -0.1043, 0.1035, -0.0362, 0, 0] H = T[10.12623508344586 -7.487995877610167 -34.80091861555747 -7.992771707568823 1.025137723295662 0 @@ -327,34 +323,29 @@ end function Rodas5Tableau(T, T2) gamma = convert(T2, 0.19) - A = T[ - 0 0 0 0 0 0 0 0 - 2.0 0 0 0 0 0 0 0 - 3.040894194418781 1.041747909077569 0 0 0 0 0 0 - 2.576417536461461 1.622083060776640 -0.9089668560264532 0 0 0 0 0 - 2.760842080225597 1.446624659844071 -0.3036980084553738 0.2877498600325443 0 0 0 0 - -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 0 0 0 - -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 1 0 0 - -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 1 1 0 - ] - C = T[ - 0 0 0 0 0 0 0 - -10.31323885133993 0 0 0 0 0 0 - -21.04823117650003 -7.234992135176716 0 0 0 0 0 - 32.22751541853323 -4.943732386540191 19.44922031041879 0 0 0 0 - -20.69865579590063 -8.816374604402768 1.260436877740897 -0.7495647613787146 0 0 0 - -46.22004352711257 -17.49534862857472 -289.6389582892057 93.60855400400906 318.3822534212147 0 0 - 34.20013733472935 -14.15535402717690 57.82335640988400 25.83362985412365 1.408950972071624 -6.551835421242162 0 - 42.57076742291101 -13.80770672017997 93.98938432427124 18.77919633714503 -31.58359187223370 -6.685968952921985 -5.810979938412932 - ] + A = T[0 0 0 0 0 0 0 0 + 2.0 0 0 0 0 0 0 0 + 3.040894194418781 1.041747909077569 0 0 0 0 0 0 + 2.576417536461461 1.622083060776640 -0.9089668560264532 0 0 0 0 0 + 2.760842080225597 1.446624659844071 -0.3036980084553738 0.2877498600325443 0 0 0 0 + -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 0 0 0 + -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 1 0 0 + -14.09640773051259 6.925207756232704 -41.47510893210728 2.343771018586405 24.13215229196062 1 1 0] + C = T[0 0 0 0 0 0 0 + -10.31323885133993 0 0 0 0 0 0 + -21.04823117650003 -7.234992135176716 0 0 0 0 0 + 32.22751541853323 -4.943732386540191 19.44922031041879 0 0 0 0 + -20.69865579590063 -8.816374604402768 1.260436877740897 -0.7495647613787146 0 0 0 + -46.22004352711257 -17.49534862857472 -289.6389582892057 93.60855400400906 318.3822534212147 0 0 + 34.20013733472935 -14.15535402717690 57.82335640988400 25.83362985412365 1.408950972071624 -6.551835421242162 0 + 42.57076742291101 -13.80770672017997 93.98938432427124 18.77919633714503 -31.58359187223370 -6.685968952921985 -5.810979938412932] c = T2[0, 0.38, 0.3878509998321533, 0.4839718937873840, 0.4570477008819580, 1, 1, 1] - d = T[gamma, -0.1823079225333714636, -0.319231832186874912, 0.3449828624725343, -0.377417564392089818, 0, 0, 0] + d = T[gamma, -0.1823079225333714636, -0.319231832186874912, + 0.3449828624725343, -0.377417564392089818, 0, 0, 0] - H = T[ - 27.354592673333357 -6.925207756232857 26.40037733258859 0.5635230501052979 -4.699151156849391 -1.6008677469422725 -1.5306074446748028 -1.3929872940716344 - 44.19024239501722 1.3677947663381929e-13 202.93261852171622 -35.5669339789154 -181.91095152160645 3.4116351403665033 2.5793540257308067 2.2435122582734066 - -44.0988150021747 -5.755396159656812e-13 -181.26175034586677 56.99302194811676 183.21182741427398 -7.480257918273637 -5.792426076169686 -5.32503859794143 - ] + H = T[27.354592673333357 -6.925207756232857 26.40037733258859 0.5635230501052979 -4.699151156849391 -1.6008677469422725 -1.5306074446748028 -1.3929872940716344 + 44.19024239501722 1.3677947663381929e-13 202.93261852171622 -35.5669339789154 -181.91095152160645 3.4116351403665033 2.5793540257308067 2.2435122582734066 + -44.0988150021747 -5.755396159656812e-13 -181.26175034586677 56.99302194811676 183.21182741427398 -7.480257918273637 -5.792426076169686 -5.32503859794143] # println("---Rodas5---") #= @@ -385,33 +376,29 @@ end function Rodas5PTableau(T, T2) gamma = convert(T2, 0.21193756319429014) - A = T[ - 0 0 0 0 0 0 0 0 - 3.0 0 0 0 0 0 0 0 - 2.849394379747939 0.45842242204463923 0 0 0 0 0 0 - -6.954028509809101 2.489845061869568 -10.358996098473584 0 0 0 0 0 - 2.8029986275628964 0.5072464736228206 -0.3988312541770524 -0.04721187230404641 0 0 0 0 - -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 0 0 0 - -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 1 0 0 - -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 1 1 0 - ] - C = T[ - 0 0 0 0 0 0 0 - -14.155112264123755 0 0 0 0 0 0 - -17.97296035885952 -2.859693295451294 0 0 0 0 0 - 147.12150275711716 -1.41221402718213 71.68940251302358 0 0 0 0 - 165.43517024871676 -0.4592823456491126 42.90938336958603 -5.961986721573306 0 0 0 - 24.854864614690072 -3.0009227002832186 47.4931110020768 5.5814197821558125 -0.6610691825249471 0 0 - 30.91273214028599 -3.1208243349937974 77.79954646070892 34.28646028294783 -19.097331116725623 -28.087943162872662 0 - 37.80277123390563 -3.2571969029072276 112.26918849496327 66.9347231244047 -40.06618937091002 -54.66780262877968 -9.48861652309627 - ] - c = T2[0, 0.6358126895828704, 0.4095798393397535, 0.9769306725060716, 0.4288403609558664, 1, 1, 1] - d = T[0.21193756319429014, -0.42387512638858027, -0.3384627126235924, 1.8046452872882734, 2.325825639765069, 0, 0, 0] - H = T[ - 25.948786856663858 -2.5579724845846235 10.433815404888879 -2.3679251022685204 0.524948541321073 1.1241088310450404 0.4272876194431874 -0.17202221070155493 - -9.91568850695171 -0.9689944594115154 3.0438037242978453 -24.495224566215796 20.176138334709044 15.98066361424651 -6.789040303419874 -6.710236069923372 - 11.419903575922262 2.8879645146136994 72.92137995996029 80.12511834622643 -52.072871366152654 -59.78993625266729 -0.15582684282751913 4.883087185713722 - ] + A = T[0 0 0 0 0 0 0 0 + 3.0 0 0 0 0 0 0 0 + 2.849394379747939 0.45842242204463923 0 0 0 0 0 0 + -6.954028509809101 2.489845061869568 -10.358996098473584 0 0 0 0 0 + 2.8029986275628964 0.5072464736228206 -0.3988312541770524 -0.04721187230404641 0 0 0 0 + -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 0 0 0 + -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 1 0 0 + -7.502846399306121 2.561846144803919 -11.627539656261098 -0.18268767659942256 0.030198172008377946 1 1 0] + C = T[0 0 0 0 0 0 0 + -14.155112264123755 0 0 0 0 0 0 + -17.97296035885952 -2.859693295451294 0 0 0 0 0 + 147.12150275711716 -1.41221402718213 71.68940251302358 0 0 0 0 + 165.43517024871676 -0.4592823456491126 42.90938336958603 -5.961986721573306 0 0 0 + 24.854864614690072 -3.0009227002832186 47.4931110020768 5.5814197821558125 -0.6610691825249471 0 0 + 30.91273214028599 -3.1208243349937974 77.79954646070892 34.28646028294783 -19.097331116725623 -28.087943162872662 0 + 37.80277123390563 -3.2571969029072276 112.26918849496327 66.9347231244047 -40.06618937091002 -54.66780262877968 -9.48861652309627] + c = T2[0, 0.6358126895828704, 0.4095798393397535, + 0.9769306725060716, 0.4288403609558664, 1, 1, 1] + d = T[0.21193756319429014, -0.42387512638858027, -0.3384627126235924, + 1.8046452872882734, 2.325825639765069, 0, 0, 0] + H = T[25.948786856663858 -2.5579724845846235 10.433815404888879 -2.3679251022685204 0.524948541321073 1.1241088310450404 0.4272876194431874 -0.17202221070155493 + -9.91568850695171 -0.9689944594115154 3.0438037242978453 -24.495224566215796 20.176138334709044 15.98066361424651 -6.789040303419874 -6.710236069923372 + 11.419903575922262 2.8879645146136994 72.92137995996029 80.12511834622643 -52.072871366152654 -59.78993625266729 -0.15582684282751913 4.883087185713722] RodasTableau(A, C, gamma, c, d, H) end diff --git a/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl b/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl index d3967b40ee..c7987db872 100644 --- a/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl +++ b/lib/OrdinaryDiffEqRosenbrock/src/stiff_addsteps.jl @@ -74,7 +74,7 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::RosenbrockCombinedConst W = 1 / dtgamma - J end - num_stages = size(A,1) + num_stages = size(A, 1) du = f(u, p, t) linsolve_tmp = @.. du + dtd[1] * dT k1 = _reshape(W \ _vec(linsolve_tmp), axes(uprev)) @@ -172,7 +172,6 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::RosenbrockCache, @.. $(_vec(ks[stage])) = -linres.u end - for j in 1:size(H, 1) copyat_or_push!(k, j, zero(du)) # Last stage doesn't affect ks diff --git a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl index 7292ba43a4..6ae774eb9c 100644 --- a/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqSDIRK/src/algorithms.jl @@ -114,7 +114,6 @@ function ImplicitEuler(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :constant, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ImplicitEuler{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -155,7 +154,6 @@ function ImplicitMidpoint(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ImplicitMidpoint{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -202,7 +200,6 @@ function Trapezoid(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -253,7 +250,8 @@ struct TRBDF2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: autodiff::AD end -function TRBDF2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function TRBDF2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, @@ -303,12 +301,12 @@ struct SDIRK2{CS, AD, F, F2, P, FDT, ST, CJ, StepLimiter} <: autodiff::AD end -function SDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function SDIRK2(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -355,7 +353,6 @@ function SDIRK22(; linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Trapezoid{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -412,7 +409,6 @@ function SSPSDIRK2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :constant, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SSPSDIRK2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -461,7 +457,6 @@ function Kvaerno3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Kvaerno3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -507,7 +502,6 @@ function KenCarp3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) KenCarp3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -546,7 +540,6 @@ function CFNLIRK3(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) CFNLIRK3{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -592,12 +585,12 @@ struct Cash4{CS, AD, F, F2, P, FDT, ST, CJ} <: controller::Symbol autodiff::AD end -function Cash4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function Cash4(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, embedding = 3) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Cash4{ @@ -643,7 +636,6 @@ function SFSDIRK4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SFSDIRK4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -686,7 +678,6 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SFSDIRK5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -694,7 +685,7 @@ function SFSDIRK5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), _unwrap_val(concrete_jac)}(linsolve, nlsolve, precs, - extrapolant, + extrapolant, AD_choice) end @@ -729,7 +720,6 @@ function SFSDIRK6(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SFSDIRK6{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -772,7 +762,6 @@ function SFSDIRK7(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SFSDIRK7{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -815,7 +804,6 @@ function SFSDIRK8(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) SFSDIRK8{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -858,7 +846,6 @@ function Hairer4(; linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Hairer4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -898,7 +885,6 @@ function Hairer42(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Hairer42{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -947,7 +933,6 @@ function Kvaerno4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Kvaerno4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -996,7 +981,6 @@ function Kvaerno5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) Kvaerno5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1042,7 +1026,6 @@ function KenCarp4(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) KenCarp4{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1090,7 +1073,6 @@ function KenCarp47(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) KenCarp47{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1136,7 +1118,6 @@ function KenCarp5(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI, step_limiter! = trivial_limiter!) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) KenCarp5{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1182,7 +1163,6 @@ function KenCarp58(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), smooth_est = true, extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) KenCarp58{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1227,7 +1207,6 @@ function ESDIRK54I8L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ESDIRK54I8L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1271,7 +1250,6 @@ function ESDIRK436L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ESDIRK436L2SA2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1314,7 +1292,6 @@ function ESDIRK437L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ESDIRK437L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1358,7 +1335,6 @@ function ESDIRK547L2SA2(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ESDIRK547L2SA2{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), @@ -1404,7 +1380,6 @@ function ESDIRK659L2SA(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), extrapolant = :linear, controller = :PI) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) ESDIRK659L2SA{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), diff --git a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl index c92d88bc22..0d9106a18e 100644 --- a/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl +++ b/lib/OrdinaryDiffEqStabilizedIRK/src/algorithms.jl @@ -20,12 +20,12 @@ struct IRKC{CS, AD, F, F2, P, FDT, ST, CJ, K, T, E} <: autodiff::AD end -function IRKC(; chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), +function IRKC(; + chunk_size = Val{0}(), autodiff = AutoForwardDiff(), standardtag = Val{true}(), concrete_jac = nothing, diff_type = Val{:forward}(), linsolve = nothing, precs = DEFAULT_PRECS, nlsolve = NLNewton(), κ = nothing, tol = nothing, extrapolant = :linear, controller = :Standard, eigen_est = nothing) - AD_choice = _process_AD_choice(autodiff, chunk_size, diff_type) IRKC{_unwrap_val(chunk_size), typeof(AD_choice), typeof(linsolve), typeof(nlsolve), diff --git a/test/downstream/autodiff_events.jl b/test/downstream/autodiff_events.jl index 9c2a23c5a0..e8a4a0d9a4 100644 --- a/test/downstream/autodiff_events.jl +++ b/test/downstream/autodiff_events.jl @@ -24,7 +24,7 @@ prob = ODEProblem(f, eltype(p).([1.0, 0.0]), eltype(p).((0.0, 1.0)), copy(p)) function test_f(p) _prob = remake(prob, p = p) solve(_prob, Tsit5(), abstol = 1e-14, reltol = 1e-14, callback = cb, - save_everystep = false).u[end] + save_everystep = false).u[end] end findiff = Calculus.finite_difference_jacobian(test_f, p) findiff diff --git a/test/downstream/delaydiffeq.jl b/test/downstream/delaydiffeq.jl index f3d2e3ac53..58228780d2 100644 --- a/test/downstream/delaydiffeq.jl +++ b/test/downstream/delaydiffeq.jl @@ -25,7 +25,7 @@ using Test sol_scalar = solve(prob_scalar, ddealg) @test sol.t≈sol_scalar.t atol=1e-3 - @test sol[1, :] ≈ sol_scalar.u atol=1e-3 + @test sol[1, :]≈sol_scalar.u atol=1e-3 end end diff --git a/test/gpu/linear_exp.jl b/test/gpu/linear_exp.jl index dbbde584cc..41cb74e5d2 100644 --- a/test/gpu/linear_exp.jl +++ b/test/gpu/linear_exp.jl @@ -8,7 +8,7 @@ using OrdinaryDiffEq A = MatrixOperator([2.0 -1.0; -1.0 2.0]) u0 = ones(2) -A_gpu = MatrixOperator(cu([2.0 -1.0; -1.0 2.0])) +A_gpu = MatrixOperator(cu([2.0 -1.0; -1.0 2.0])) u0_gpu = cu(ones(2)) prob_gpu = ODEProblem(A_gpu, u0_gpu, (0.0, 1.0)) @@ -22,7 +22,7 @@ sol3_gpu = solve(prob_gpu, LinearExponential(krylov = :adaptive))(1.0) |> Vector @test isapprox(sol2_gpu, sol_analytic, rtol = 1e-6) @test isapprox(sol3_gpu, sol_analytic, rtol = 1e-6) -A2_gpu = MatrixOperator(cu(sparse([2.0 -1.0; -1.0 2.0]))) +A2_gpu = MatrixOperator(cu(sparse([2.0 -1.0; -1.0 2.0]))) prob2_gpu = ODEProblem(A2_gpu, u0_gpu, (0.0, 1.0)) @test_broken sol2_1_gpu = solve(prob2_gpu, LinearExponential(krylov = :off))(1.0) |> Vector @@ -31,4 +31,4 @@ sol2_3_gpu = solve(prob2_gpu, LinearExponential(krylov = :adaptive))(1.0) |> Vec @test_broken isapprox(sol2_1_gpu, sol_analytic, rtol = 1e-6) @test isapprox(sol2_2_gpu, sol_analytic, rtol = 1e-6) -@test isapprox(sol2_3_gpu, sol_analytic, rtol = 1e-6) \ No newline at end of file +@test isapprox(sol2_3_gpu, sol_analytic, rtol = 1e-6) diff --git a/test/integrators/check_error.jl b/test/integrators/check_error.jl index dc80ff87fa..61ab159544 100644 --- a/test/integrators/check_error.jl +++ b/test/integrators/check_error.jl @@ -57,5 +57,5 @@ end @test_broken sol.retcode = ReturnCode.Success end -@test_throws ArgumentError solve(prob, Euler(), dt=0.1, adaptive=true) +@test_throws ArgumentError solve(prob, Euler(), dt = 0.1, adaptive = true) @test_throws ArgumentError solve(prob, Euler()) diff --git a/test/integrators/ode_cache_tests.jl b/test/integrators/ode_cache_tests.jl index 4337e41bb6..1dc92cbfc0 100644 --- a/test/integrators/ode_cache_tests.jl +++ b/test/integrators/ode_cache_tests.jl @@ -79,9 +79,11 @@ for alg in broken_CACHE_TEST_ALGS @test_broken length(solve(prob, alg, callback = callback, dt = 1 / 2)[end]) > 1 end -sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 1)), callback = callback, dt = 1 / 2) +sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 1)), + callback = callback, dt = 1 / 2) @test length(sol[end]) > 1 -sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 1)), callback = callback, dt = 1 / 2) +sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 1)), + callback = callback, dt = 1 / 2) @test length(sol[end]) > 1 # cache tests resizing multidimensional arrays diff --git a/test/integrators/step_limiter_test.jl b/test/integrators/step_limiter_test.jl index 98ffe37126..999b978370 100644 --- a/test/integrators/step_limiter_test.jl +++ b/test/integrators/step_limiter_test.jl @@ -26,8 +26,9 @@ end SDIRK2, SDIRK22, ABDF2, Feagin10, Feagin12, Feagin14, KenCarp3, KenCarp4, KenCarp5, Kvaerno3, Kvaerno4, Kvaerno5, Rosenbrock23, Rosenbrock32, ROS3P, Rodas3, Rodas23W, Rodas3P, Rodas4, Rodas42, - Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, - AdaptiveRadau, RadauIIA9, RadauIIA5, RadauIIA3, SIR54, Alshina2, Alshina3, Heun, Ralston, Midpoint, RK4, + Rodas4P, Rodas4P2, Rodas5, Rodas5P, Rodas5Pe, Rodas5Pr, + AdaptiveRadau, RadauIIA9, RadauIIA5, RadauIIA3, SIR54, + Alshina2, Alshina3, Heun, Ralston, Midpoint, RK4, OwrenZen3, OwrenZen4, OwrenZen5, BS3, DP5, Tsit5, DP8, TanYam7, TsitPap8, FRK65, PFRK87, BS5, Vern6, Vern7, Vern8, Vern9, QPRK98, SSPRKMSVS43, SSPRKMSVS32, SSPRK432, SSPRK43, diff --git a/test/interface/ad_tests.jl b/test/interface/ad_tests.jl index 26f98f1aa4..276fae2263 100644 --- a/test/interface/ad_tests.jl +++ b/test/interface/ad_tests.jl @@ -319,11 +319,9 @@ end K_ = [-1.0 0.0; 1.0 -1.0] @test isapprox(ForwardDiff.jacobian(f, K_)[2], 0.00226999, atol = 1e-6) - -implicit_algs = -[FBDF, - Rosenbrock23, - TRBDF2] +implicit_algs = [FBDF, + Rosenbrock23, + TRBDF2] @testset "deprecated AD keyword arguments still work with $alg" for alg in implicit_algs f = (du, u, p, t) -> du .= -0.5 * u @@ -347,4 +345,4 @@ implicit_algs = @test OrdinaryDiffEq.alg_autodiff(alg5) == OrdinaryDiffEq.alg_autodiff(alg6) @test OrdinaryDiffEq.alg_autodiff(alg7) == OrdinaryDiffEq.alg_autodiff(alg8) @test OrdinaryDiffEq.alg_autodiff(alg9) == OrdinaryDiffEq.alg_autodiff(alg10) -end \ No newline at end of file +end diff --git a/test/interface/aliasing_tests.jl b/test/interface/aliasing_tests.jl index 4e2bfe0bc7..83b26a26d8 100644 --- a/test/interface/aliasing_tests.jl +++ b/test/interface/aliasing_tests.jl @@ -4,7 +4,7 @@ import ODEProblemLibrary: prob_ode_linear # Test that the old keyword works, and that the new AliasSpecier works. u0_old_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias_u0 = true) -u0_new_alias_kwarg_sol = solve(prob_ode_linear, Tsit5(), alias = ODEAliasSpecifier(alias_u0 = true)) +u0_new_alias_kwarg_sol = solve( + prob_ode_linear, Tsit5(), alias = ODEAliasSpecifier(alias_u0 = true)) @test u0_old_alias_kwarg_sol == u0_new_alias_kwarg_sol - diff --git a/test/interface/autodiff_error_tests.jl b/test/interface/autodiff_error_tests.jl index 7b37ab87f6..5e4bdbd258 100644 --- a/test/interface/autodiff_error_tests.jl +++ b/test/interface/autodiff_error_tests.jl @@ -55,7 +55,7 @@ for alg in [ Rodas5(autodiff = AutoFiniteDiff()), QNDF(autodiff = AutoFiniteDiff()), TRBDF2(autodiff = AutoFiniteDiff()), - KenCarp4(autodiff = AutoFiniteDiff()), + KenCarp4(autodiff = AutoFiniteDiff()) ] u = [0.0, 0.0] function f1(u, p, t) diff --git a/test/interface/composite_algorithm_test.jl b/test/interface/composite_algorithm_test.jl index 1e3ebe8574..4bdfc958ff 100644 --- a/test/interface/composite_algorithm_test.jl +++ b/test/interface/composite_algorithm_test.jl @@ -49,9 +49,9 @@ v = @inferred OrdinaryDiffEqCore.ode_extrapolant( @test_throws ArgumentError solve(prob_ode_linear, alg_mixed) sol2 = solve(prob_ode_linear, Tsit5()) - sol3 = solve(prob_ode_linear, alg_mixed; dt = 0.05, adaptive=false) - sol4 = solve(prob_ode_linear, alg_mixed_r; dt = 0.05, adaptive=false) - sol5 = solve(prob_ode_linear, alg_mixed2; dt = 0.05, adaptive=false) + sol3 = solve(prob_ode_linear, alg_mixed; dt = 0.05, adaptive = false) + sol4 = solve(prob_ode_linear, alg_mixed_r; dt = 0.05, adaptive = false) + sol5 = solve(prob_ode_linear, alg_mixed2; dt = 0.05, adaptive = false) @test sol3.t == sol4.t && sol3.u == sol4.u @test sol3(0.8)≈sol2(0.8) atol=1e-4 @test sol5(0.8)≈sol2(0.8) atol=1e-4 diff --git a/test/interface/nojac.jl b/test/interface/nojac.jl index 46230434de..6f0229a4f0 100644 --- a/test/interface/nojac.jl +++ b/test/interface/nojac.jl @@ -253,6 +253,7 @@ integ = init(prob, Rosenbrock23(linsolve = SimpleLUFactorization()), abstol = 1e integ = init(prob, Rosenbrock23(linsolve = GenericLUFactorization()), abstol = 1e-6, reltol = 1e-6) @test integ.cache.jac_config === nothing -integ = init(prob, Rosenbrock23(linsolve = RFLUFactorization(), autodiff = AutoForwardDiff(chunksize = 3)), +integ = init(prob, + Rosenbrock23(linsolve = RFLUFactorization(), autodiff = AutoForwardDiff(chunksize = 3)), abstol = 1e-6, reltol = 1e-6) @test integ.cache.jac_config === nothing diff --git a/test/interface/ode_initdt_tests.jl b/test/interface/ode_initdt_tests.jl index 2045e4874d..2bee803e1e 100644 --- a/test/interface/ode_initdt_tests.jl +++ b/test/interface/ode_initdt_tests.jl @@ -66,7 +66,7 @@ prob = ODEProblem((u, p, t) -> 1e20 * sin(1e20 * t), 0.1, (0, 1e-19)) @test solve(prob, Tsit5()).retcode == ReturnCode.Success #test that we are robust to u0=0, t0!=0 -integ = init(ODEProblem(((u,p,t)->u), 0f0, (20f0, 0f0)), Tsit5()) +integ = init(ODEProblem(((u, p, t) -> u), 0.0f0, (20.0f0, 0.0f0)), Tsit5()) @test abs(integ.dt) > eps(integ.t) -integ = init(ODEProblem(((du,u,p,t)->du.=u), [0f0], (20f0, 0f0)), Tsit5()) +integ = init(ODEProblem(((du, u, p, t) -> du .= u), [0.0f0], (20.0f0, 0.0f0)), Tsit5()) @test abs(integ.dt) > eps(integ.t) diff --git a/test/interface/ode_strip_test.jl b/test/interface/ode_strip_test.jl index f30a4492aa..697332da2d 100644 --- a/test/interface/ode_strip_test.jl +++ b/test/interface/ode_strip_test.jl @@ -43,7 +43,6 @@ end @testset "Default Solution Stripping" begin stripped_sol = SciMLBase.strip_solution(default_sol) @test isnothing(stripped_sol.interp.cache.args) - end @test_throws SciMLBase.LazyInterpolationException SciMLBase.strip_solution(vern_sol) diff --git a/test/interface/precision_mixing.jl b/test/interface/precision_mixing.jl index 497944d65d..727025c3e0 100644 --- a/test/interface/precision_mixing.jl +++ b/test/interface/precision_mixing.jl @@ -2,7 +2,7 @@ using OrdinaryDiffEq function ODE(du, u, t, R, K) du .= u end -params = BigFloat[1. 0.91758707304098; 1.48439909482661 1.] +params = BigFloat[1.0 0.91758707304098; 1.48439909482661 1.0] u0 = BigFloat[0.1, 0.1] tspan = (1.0, 31.0) R = BigFloat[0.443280390004304303, 1.172917082211452] @@ -16,7 +16,6 @@ for alg in [AutoVern8(Rodas5(), nonstifftol = 11 / 10) Rodas5P() TRBDF2() KenCarp4() - RadauIIA5() - ] + RadauIIA5()] Solution = solve(odeProblem, alg, saveat = 1, abstol = 1.e-12, reltol = 1.e-6) -end \ No newline at end of file +end diff --git a/test/interface/static_array_tests.jl b/test/interface/static_array_tests.jl index 44d85fe05f..c4ba0d8fdf 100644 --- a/test/interface/static_array_tests.jl +++ b/test/interface/static_array_tests.jl @@ -94,8 +94,10 @@ function rober(u, p, t) end prob = ODEProblem{false}(rober, SA[1.0, 0.0, 0.0], (0.0, 1e5), SA[0.04, 3e7, 1e4]) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 3)), save_everystep = false) function hires_4(u, p, t) y1, y2, y3, y4 = u @@ -109,8 +111,10 @@ end u0 = SA[1, 0, 0, 0.0057] prob = ODEProblem(hires_4, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 4)), save_everystep = false) function hires_5(u, p, t) y1, y2, y3, y4, y5 = u @@ -125,8 +129,10 @@ end u0 = SA[1, 0, 0, 0, 0.0057] prob = ODEProblem(hires_5, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rodas4(autodiff = AutoForwardDiff(chunksize = 5)), save_everystep = false) function hires(u, p, t) y1, y2, y3, y4, y5, y6, y7, y8 = u @@ -145,8 +151,10 @@ end u0 = SA[1, 0, 0, 0, 0, 0, 0, 0.0057] prob = ODEProblem(hires, u0, (0.0, 321.8122)) # Defaults to reltol=1e-3, abstol=1e-6 -@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) const k1 = 0.35e0 const k2 = 0.266e2 @@ -235,8 +243,10 @@ u0[9] = 0.01 u0[17] = 0.007 u0 = SA[u0...] prob = ODEProblem(pollu, u0, (0.0, 60.0)) -@test_nowarn sol = solve(prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) -@test_nowarn sol = solve(prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) +@test_nowarn sol = solve( + prob, Rodas5(autodiff = AutoForwardDiff(chunksize = 8)), save_everystep = false) # DFBDF g1(du, u, p, t) = du .^ 2 - conj.(u) diff --git a/test/interface/stats_tests.jl b/test/interface/stats_tests.jl index a35607a536..2c5bf18285 100644 --- a/test/interface/stats_tests.jl +++ b/test/interface/stats_tests.jl @@ -23,12 +23,12 @@ probip = ODEProblem(g, u0, tspan) @test x[] == sol.stats.nf end @testset "$alg" for alg in [Rodas5P, KenCarp4] - @testset "$kwargs" for kwargs in [(autodiff = AutoForwardDiff(),), - (autodiff = AutoFiniteDiff(fdtype = Val{:forward}()),), - (autodiff = AutoFiniteDiff(fdtype = Val{:central}()),), - (autodiff = AutoFiniteDiff(fdtype = Val{:complex}()),)] + @testset "$kwargs" for kwargs in [(autodiff = AutoForwardDiff(),), + (autodiff = AutoFiniteDiff(fdtype = Val{:forward}()),), + (autodiff = AutoFiniteDiff(fdtype = Val{:central}()),), + (autodiff = AutoFiniteDiff(fdtype = Val{:complex}()),)] x[] = 0 - sol = solve(prob, alg(;kwargs...)) + sol = solve(prob, alg(; kwargs...)) @test x[] == sol.stats.nf end end diff --git a/test/interface/utility_tests.jl b/test/interface/utility_tests.jl index 2a8ba62c8f..a8a5628ab6 100644 --- a/test/interface/utility_tests.jl +++ b/test/interface/utility_tests.jl @@ -10,7 +10,7 @@ using OrdinaryDiffEq.OrdinaryDiffEqDifferentiation: WOperator, calc_W, calc_W!, tspan = (0.0, 1.0) dt = 0.01 dtgamma = 0.5dt - concrete_W = A - inv(dtgamma)*mm + concrete_W = A - inv(dtgamma) * mm # Out-of-place fun = ODEFunction((u, p, t) -> A * u; From 62b460cb86cf6609706f872ba5262f82094e8012 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 06:00:54 -0800 Subject: [PATCH 192/203] cannot sparse exponential --- test/integrators/ode_event_tests.jl | 30 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/test/integrators/ode_event_tests.jl b/test/integrators/ode_event_tests.jl index 32995814b1..69f0153d5b 100644 --- a/test/integrators/ode_event_tests.jl +++ b/test/integrators/ode_event_tests.jl @@ -411,23 +411,21 @@ step!(integrator, 1e-5, true) @test all(u -> u > 1.5, integrator.u) # https://github.com/SciML/OrdinaryDiffEq.jl/pull/1777 -if VERSION >= v"1.7" - @testset "Callbacks with LinearExponential" begin - A = sprand(ComplexF64, 100, 100, 0.5) - A += A' +@testset "Callbacks with LinearExponential" begin + A = Matrix(sprand(ComplexF64, 100, 100, 0.5)) + A += A' - t_l = LinRange(0, 1, 100) + t_l = LinRange(0, 1, 100) - saved_values = SavedValues(Float64, Float64) - function save_func(u, t, integrator) - real(u' * A * u) - end - cb = SavingCallback(save_func, saved_values, saveat = t_l) - - u0 = normalize(rand(ComplexF64, 100)) - A = MatrixOperator(-1im * A) - prob = ODEProblem(A, u0, (0, 1.0)) - solve(prob, LinearExponential(), dt = t_l[2] - t_l[1], callback = cb) - @test length(saved_values.saveval) == length(t_l) + saved_values = SavedValues(Float64, Float64) + function save_func(u, t, integrator) + real(u' * A * u) end + cb = SavingCallback(save_func, saved_values, saveat = t_l) + + u0 = normalize(rand(ComplexF64, 100)) + A = MatrixOperator(-1im * A) + prob = ODEProblem(A, u0, (0, 1.0)) + solve(prob, LinearExponential(), dt = t_l[2] - t_l[1], callback = cb) + @test length(saved_values.saveval) == length(t_l) end From 201f38dd05fb718e961f4265c77212c56404e666 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 06:18:20 -0800 Subject: [PATCH 193/203] fix default --- lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl index 751ca5c4ec..b1c39f5a3f 100644 --- a/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl +++ b/lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl @@ -27,7 +27,7 @@ vernsol = solve(prob_ode_2Dlinear, Vern7(), reltol = 1e-10) prob_ode_linear_fast = ODEProblem( ODEFunction(f_2dlinear, mass_matrix = 2 * I(2)), rand(2), (0.0, 1.0), 1.01) sol = solve(prob_ode_linear_fast) -@test all(isequal(3), sol.alg_choice) +@test all(isequal(4), sol.alg_choice) # for some reason the timestepping here is different from regular Rosenbrock23 (including the initial timestep) function rober(u, p, t) From 8bd7afcfd7196a080360a060cdb6bfa7b064ec22 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 06:21:17 -0800 Subject: [PATCH 194/203] allow statistics --- lib/OrdinaryDiffEqRKN/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OrdinaryDiffEqRKN/Project.toml b/lib/OrdinaryDiffEqRKN/Project.toml index 09dc6999b8..3cd5c9338c 100644 --- a/lib/OrdinaryDiffEqRKN/Project.toml +++ b/lib/OrdinaryDiffEqRKN/Project.toml @@ -23,7 +23,7 @@ Random = "<0.0.1, 1" RecursiveArrayTools = "3.27.0" Reexport = "1.2.2" SafeTestsets = "0.1.0" -Statistics = "1.11.1" +Statistics = "<0.0.1, 1" Test = "<0.0.1, 1" julia = "1.10" From e88e4fa4d823da248cb4f219f7771d7b7458d775 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 07:17:06 -0800 Subject: [PATCH 195/203] Release rosenbrock --- lib/OrdinaryDiffEqRosenbrock/Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OrdinaryDiffEqRosenbrock/Project.toml b/lib/OrdinaryDiffEqRosenbrock/Project.toml index d13bd3d5b0..bea0adb074 100644 --- a/lib/OrdinaryDiffEqRosenbrock/Project.toml +++ b/lib/OrdinaryDiffEqRosenbrock/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqRosenbrock" uuid = "43230ef6-c299-4910-a778-202eb28ce4ce" authors = ["ParamThakkar123 "] -version = "1.4.0" +version = "1.5.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -30,7 +30,7 @@ FastBroadcast = "0.3.5" FiniteDiff = "2.24.0" ForwardDiff = "0.10.36" LinearAlgebra = "<0.0.1, 1" -LinearSolve = "2.32.0" +LinearSolve = "2.32.0, 3" MacroTools = "0.5.13" MuladdMacro = "0.2.4" ODEProblemLibrary = "0.1.8" From 203bb1422c69fd3426d45a9fb24ca7766c2309e4 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Feb 2025 15:16:13 -0800 Subject: [PATCH 196/203] Update step_limiter_test.jl --- test/integrators/step_limiter_test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integrators/step_limiter_test.jl b/test/integrators/step_limiter_test.jl index 98ffe37126..168a95079b 100644 --- a/test/integrators/step_limiter_test.jl +++ b/test/integrators/step_limiter_test.jl @@ -1,4 +1,5 @@ using OrdinaryDiffEq, Test +using OrdinaryDiffEqFIRK: AdaptiveRadau, RadauIIA9, RadauIIA5, RadauIIA3 # define the counting variable const STEP_LIMITER_VAR = Ref(0) From 67f09834cf99fa42785664a27ab670aceecd2d14 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Thu, 7 Nov 2024 17:16:01 +0100 Subject: [PATCH 197/203] Move informative error message up the call stack so it is hit --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index f4a28df105..f9479f4378 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -37,6 +37,10 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) + if !hasmethod(_initialize_dae!, (Any, typeof(integrator.sol.prob), + BrownFullBasicInit, Val)) + error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") + end _initialize_dae!(integrator, integrator.sol.prob, initializealg, Val(DiffEqBase.isinplace(integrator.sol.prob))) From 0dfd92b4d68e0544cb3681bf6e684de94033bb82 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Fri, 8 Nov 2024 14:19:11 +0100 Subject: [PATCH 198/203] Make hasmethod check if BrownFullBasicInit is defined --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index f9479f4378..43b30a2f8e 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -37,9 +37,10 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) - if !hasmethod(_initialize_dae!, (Any, typeof(integrator.sol.prob), - BrownFullBasicInit, Val)) - error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") + if !hasmethod(_initialize_dae!, (typeof(integrator), + typeof(integrator.sol.prob), BrownFullBasicInit, + Val{DiffEqBase.isinplace(integrator.sol.prob)})) + error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") end _initialize_dae!(integrator, integrator.sol.prob, initializealg, From 6a1204f3c68df95eb6982ff86cabcc4ef08da220 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Wed, 13 Nov 2024 15:20:47 +0100 Subject: [PATCH 199/203] Add CheckInit error message --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 88 ++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 43b30a2f8e..f7c29bf0e1 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -176,6 +176,94 @@ function _initialize_dae!(integrator, prob::AbstractDEProblem, end ## CheckInit +struct CheckInitFailureError <: Exception + normresid::Any + abstol::Any +end + +function Base.showerror(io::IO, e::CheckInitFailureError) + print(io, + "DAE initialization failed: your u0 did not satisfy the initialization requirements, + normresid = $(e.normresid) > abstol = $(e.abstol). If you wish for the system to + automatically change the algebraic variables to satisfy the algebraic constraints, + please pass `initializealg = BrownBasicInit()` to solve (this option will require + `using OrdinaryDiffEqNonlinearSolve`). If you wish to perform an initialization on the + complete u0, please pass initializealg = ShampineCollocationInit() to solve. Note that + initialization can be a very difficult process for DAEs and in many cases can be + numerically intractable without symbolic manipulation of the system. For an automated + system that will generate numerically stable initializations, see ModelingToolkit.jl + structural simplification for more details." + ) +end + +function _initialize_dae!(integrator, prob::ODEProblem, alg::CheckInit, + isinplace::Val{true}) + @unpack p, t, f = integrator + M = integrator.f.mass_matrix + tmp = first(get_tmp_cache(integrator)) + u0 = integrator.u + + algebraic_vars = [all(iszero, x) for x in eachcol(M)] + algebraic_eqs = [all(iszero, x) for x in eachrow(M)] + (iszero(algebraic_vars) || iszero(algebraic_eqs)) && return + update_coefficients!(M, u0, p, t) + f(tmp, u0, p, t) + tmp .= ArrayInterface.restructure(tmp, algebraic_eqs .* _vec(tmp)) + + normresid = integrator.opts.internalnorm(tmp, t) + if normresid > integrator.opts.abstol + throw(CheckInitFailureError(normresid, integrator.opts.abstol)) + end +end + +function _initialize_dae!(integrator, prob::ODEProblem, alg::CheckInit, + isinplace::Val{false}) + @unpack p, t, f = integrator + u0 = integrator.u + M = integrator.f.mass_matrix + + algebraic_vars = [all(iszero, x) for x in eachcol(M)] + algebraic_eqs = [all(iszero, x) for x in eachrow(M)] + (iszero(algebraic_vars) || iszero(algebraic_eqs)) && return + update_coefficients!(M, u0, p, t) + du = f(u0, p, t) + resid = _vec(du)[algebraic_eqs] + + normresid = integrator.opts.internalnorm(resid, t) + if normresid > integrator.opts.abstol + throw(CheckInitFailureError(normresid, integrator.opts.abstol)) + end +end + +function _initialize_dae!(integrator, prob::DAEProblem, + alg::CheckInit, isinplace::Val{true}) + @unpack p, t, f = integrator + u0 = integrator.u + resid = get_tmp_cache(integrator)[2] + + f(resid, integrator.du, u0, p, t) + normresid = integrator.opts.internalnorm(resid, t) + if normresid > integrator.opts.abstol + throw(CheckInitFailureError(normresid, integrator.opts.abstol)) + end +end + +function _initialize_dae!(integrator, prob::DAEProblem, + alg::CheckInit, isinplace::Val{false}) + @unpack p, t, f = integrator + u0 = integrator.u + + nlequation_oop = u -> begin + f((u - u0) / dt, u, p, t) + end + + nlequation = (u, _) -> nlequation_oop(u) + + resid = f(integrator.du, u0, p, t) + normresid = integrator.opts.internalnorm(resid, t) + if normresid > integrator.opts.abstol + throw(CheckInitFailureError(normresid, integrator.opts.abstol)) + end function _initialize_dae!(integrator, prob::AbstractDEProblem, alg::CheckInit, isinplace::Union{Val{true}, Val{false}}) SciMLBase.get_initial_values( From e5f5c45f5ed8762b1b78cb79b2d15650255259d9 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Wed, 13 Nov 2024 15:21:57 +0100 Subject: [PATCH 200/203] Swap BrownFullBasicInit for CheckInit --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index f7c29bf0e1..8b78b3ba35 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -54,12 +54,20 @@ function _initialize_dae!(integrator, prob::ODEProblem, if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) - elseif !applicable(_initialize_dae!, integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) - error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) + end +end + +function _initialize_dae!(integrator, prob::ODEProblem, + alg::DefaultInit, x::Val{false}) + if SciMLBase.has_initializeprob(prob.f) + _initialize_dae!(integrator, prob, + OverrideInit(integrator.opts.abstol), x) + else + _initialize_dae!(integrator, prob, + CheckInit(), x) end end @@ -78,7 +86,7 @@ function _initialize_dae!(integrator, prob::DAEProblem, ShampineCollocationInit(), x) else _initialize_dae!(integrator, prob, - BrownFullBasicInit(integrator.opts.abstol), x) + CheckInit(), x) end end From 254150f1b45b4bfc43db5904005953c0f16b516c Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Tue, 3 Dec 2024 14:23:02 +0100 Subject: [PATCH 201/203] Unify methods so that CheckInit is default for all cases --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 49 ++------------------ 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 8b78b3ba35..109e96b6ab 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -37,11 +37,6 @@ variable, then the system is not Index 1! function DiffEqBase.initialize_dae!(integrator::ODEIntegrator, initializealg = integrator.initializealg) - if !hasmethod(_initialize_dae!, (typeof(integrator), - typeof(integrator.sol.prob), BrownFullBasicInit, - Val{DiffEqBase.isinplace(integrator.sol.prob)})) - error("This ODE requires a DAE initialization and thus a nonlinear solve but no nonlinear solve has been loaded. To solve this problem, do `using OrdinaryDiffEqNonlinearSolve` or pass a custom `nlsolve` choice into the `initializealg`.") - end _initialize_dae!(integrator, integrator.sol.prob, initializealg, Val(DiffEqBase.isinplace(integrator.sol.prob))) @@ -49,8 +44,10 @@ end ## Default algorithms -function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Union{Val{true}, Val{false}}) +function _initialize_dae!(integrator, + prob::Union{ODEProblem, DAEProblem}, + alg::DefaultInit, + x::Union{Val{true}, Val{false}}) if SciMLBase.has_initializeprob(prob.f) _initialize_dae!(integrator, prob, OverrideInit(integrator.opts.abstol), x) @@ -60,44 +57,6 @@ function _initialize_dae!(integrator, prob::ODEProblem, end end -function _initialize_dae!(integrator, prob::ODEProblem, - alg::DefaultInit, x::Val{false}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - else - _initialize_dae!(integrator, prob, - CheckInit(), x) - end -end - -function _initialize_dae!(integrator, prob::DAEProblem, - alg::DefaultInit, x::Union{Val{true}, Val{false}}) - if SciMLBase.has_initializeprob(prob.f) - _initialize_dae!(integrator, prob, - OverrideInit(integrator.opts.abstol), x) - elseif !applicable(_initialize_dae!, integrator, prob, - BrownFullBasicInit(), x) && - !applicable(_initialize_dae!, - integrator, prob, ShampineCollocationInit(), x) - error("`OrdinaryDiffEqNonlinearSolve` is not loaded, which is required for the default initialization algorithm (`BrownFullBasicInit` or `ShampineCollocationInit`). To solve this problem, either do `using OrdinaryDiffEqNonlinearSolve` or pass `initializealg = CheckInit()` to the `solve` function. This second option requires consistent `u0`.") - elseif prob.differential_vars === nothing - _initialize_dae!(integrator, prob, - ShampineCollocationInit(), x) - else - _initialize_dae!(integrator, prob, - CheckInit(), x) - end -end - -function _initialize_dae!(integrator, prob::DiscreteProblem, - alg::DefaultInit, x::Union{Val{true}, Val{false}}) - if SciMLBase.has_initializeprob(prob.f) - # integrator.opts.abstol is `false` for `DiscreteProblem`. - _initialize_dae!(integrator, prob, OverrideInit(one(eltype(prob.u0)) * 1e-12), x) - end -end - ## Nonlinear Solver Defaulting ## If an alg is given use it From 0a98a0cadea1dbdb3d00156b5d5cf4934b7c8196 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Mon, 9 Dec 2024 10:21:48 +0100 Subject: [PATCH 202/203] Remove export so it can live in non-breaking pull request --- .../src/OrdinaryDiffEqNonlinearSolve.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl index 3c28ef913c..c83e781f1e 100644 --- a/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl +++ b/lib/OrdinaryDiffEqNonlinearSolve/src/OrdinaryDiffEqNonlinearSolve.jl @@ -65,6 +65,4 @@ include("functional.jl") include("newton.jl") include("initialize_dae.jl") -export BrownFullBasicInit, ShampineCollocationInit - end From 4e1ae8c34b6631e80a0ec7b2f84da65b0c76eb55 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Fri, 14 Feb 2025 14:20:10 +0100 Subject: [PATCH 203/203] fix format --- lib/OrdinaryDiffEqCore/src/initialize_dae.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl index 109e96b6ab..aa6d828b66 100644 --- a/lib/OrdinaryDiffEqCore/src/initialize_dae.jl +++ b/lib/OrdinaryDiffEqCore/src/initialize_dae.jl @@ -231,6 +231,8 @@ function _initialize_dae!(integrator, prob::DAEProblem, if normresid > integrator.opts.abstol throw(CheckInitFailureError(normresid, integrator.opts.abstol)) end +end + function _initialize_dae!(integrator, prob::AbstractDEProblem, alg::CheckInit, isinplace::Union{Val{true}, Val{false}}) SciMLBase.get_initial_values(