Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove OrdinaryDiffEq dependence in all environments #1979

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions .buildkite/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.4"
manifest_format = "2.0"
project_hash = "a3b8e1623c974758b823be61fb12f149202fadbb"
project_hash = "fd1e670d65913da2cbb0367d634efd6165bc7d16"

[[deps.ADTypes]]
git-tree-sha1 = "99a6f5d0ce1c7c6afdb759daa30226f71c54f6b0"
Expand Down Expand Up @@ -693,12 +693,6 @@ git-tree-sha1 = "1c6317308b9dc757616f0b5cb379db10494443a7"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.6.2+0"

[[deps.ExponentialUtilities]]
deps = ["Adapt", "ArrayInterface", "GPUArraysCore", "GenericSchur", "LinearAlgebra", "PrecompileTools", "Printf", "SparseArrays", "libblastrampoline_jll"]
git-tree-sha1 = "8e18940a5ba7f4ddb41fe2b79b6acaac50880a86"
uuid = "d4d017d3-3776-5f7e-afef-a10c40355c18"
version = "1.26.1"

[[deps.ExprTools]]
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Expand Down Expand Up @@ -911,12 +905,6 @@ git-tree-sha1 = "eb6f1f48aa994f3018cbd029a17863c6535a266d"
uuid = "d54b0c1a-921d-58e0-8e36-89d8069c0969"
version = "0.5.8"

[[deps.GenericSchur]]
deps = ["LinearAlgebra", "Printf"]
git-tree-sha1 = "af49a0851f8113fcfae2ef5027c6d49d0acec39b"
uuid = "c145ed77-6b09-5dd9-b285-bf645a82121e"
version = "0.5.4"

[[deps.Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
Expand Down Expand Up @@ -1738,12 +1726,6 @@ git-tree-sha1 = "dfdf5519f235516220579f949664f1bf44e741c5"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.6.3"

[[deps.OrdinaryDiffEq]]
deps = ["ADTypes", "Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "EnumX", "ExponentialUtilities", "FastBroadcast", "FastClosures", "FillArrays", "FiniteDiff", "ForwardDiff", "FunctionWrappersWrappers", "IfElse", "InteractiveUtils", "LineSearches", "LinearAlgebra", "LinearSolve", "Logging", "MacroTools", "MuladdMacro", "NonlinearSolve", "Polyester", "PreallocationTools", "PrecompileTools", "Preferences", "RecursiveArrayTools", "Reexport", "SciMLBase", "SciMLOperators", "SciMLStructures", "SimpleNonlinearSolve", "SimpleUnPack", "SparseArrays", "SparseDiffTools", "Static", "StaticArrayInterface", "StaticArrays", "TruncatedStacktraces"]
git-tree-sha1 = "a8b2d333cd90562b58b977b4033739360b37fb1f"
uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
version = "6.87.0"

[[deps.OrdinaryDiffEqCore]]
deps = ["ADTypes", "Adapt", "ArrayInterface", "DataStructures", "DiffEqBase", "DocStringExtensions", "EnumX", "FastBroadcast", "FastClosures", "FillArrays", "FunctionWrappersWrappers", "InteractiveUtils", "LinearAlgebra", "Logging", "MacroTools", "MuladdMacro", "Polyester", "PrecompileTools", "Preferences", "RecursiveArrayTools", "Reexport", "SciMLBase", "SciMLOperators", "SciMLStructures", "SimpleUnPack", "Static", "StaticArrayInterface", "StaticArraysCore", "TruncatedStacktraces"]
git-tree-sha1 = "bc70a38874c801549d415c16a23ec632ad91afd1"
Expand Down
2 changes: 0 additions & 2 deletions .buildkite/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NVTX = "5da4648a-3479-48b8-97b9-01cb529c0a1f"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqSSPRK = "669c94d9-1f4b-4b64-b377-1aa079aa2388"
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
PProf = "e4faabce-9ead-11e9-39d9-4379958e3056"
Expand All @@ -60,5 +59,4 @@ ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
OrdinaryDiffEq = "6"
SnoopCompileCore = "2"
2 changes: 1 addition & 1 deletion examples/hybrid/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ callback = SciMLBase.CallbackSet(
additional_callbacks...,
)

problem = ODE.ODEProblem(
problem = SciMLBase.ODEProblem(
CTS.ClimaODEFunction(;
T_imp! = ODEFunction(
implicit_tendency!;
Expand Down
48 changes: 5 additions & 43 deletions examples/hybrid/ode_config.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SciMLBase
import OrdinaryDiffEq as ODE
import ClimaTimeSteppers as CTS

is_explicit_CTS_algo_type(alg_or_tableau) =
Expand All @@ -8,35 +7,13 @@ is_explicit_CTS_algo_type(alg_or_tableau) =
is_imex_CTS_algo_type(alg_or_tableau) =
alg_or_tableau <: CTS.IMEXARKAlgorithmName

is_implicit_type(::typeof(ODE.IMEXEuler)) = true
is_implicit_type(alg_or_tableau) =
alg_or_tableau <: Union{
ODE.OrdinaryDiffEqImplicitAlgorithm,
ODE.OrdinaryDiffEqAdaptiveImplicitAlgorithm,
} || is_imex_CTS_algo_type(alg_or_tableau)

is_ordinary_diffeq_newton(::typeof(ODE.IMEXEuler)) = true
is_ordinary_diffeq_newton(alg_or_tableau) =
alg_or_tableau <: Union{
ODE.OrdinaryDiffEqNewtonAlgorithm,
ODE.OrdinaryDiffEqNewtonAdaptiveAlgorithm,
}

is_imex_CTS_algo(::CTS.IMEXAlgorithm) = true
is_imex_CTS_algo(::SciMLBase.AbstractODEAlgorithm) = false

is_implicit(::ODE.OrdinaryDiffEqImplicitAlgorithm) = true
is_implicit(::ODE.OrdinaryDiffEqAdaptiveImplicitAlgorithm) = true
is_implicit(ode_algo) = is_imex_CTS_algo(ode_algo)

is_rosenbrock(::ODE.Rosenbrock23) = true
is_rosenbrock(::ODE.Rosenbrock32) = true
is_rosenbrock(::SciMLBase.AbstractODEAlgorithm) = false
use_transform(ode_algo) =
!(is_imex_CTS_algo(ode_algo) || is_rosenbrock(ode_algo))
use_transform(ode_algo) = !is_imex_CTS_algo(ode_algo)

function jac_kwargs(ode_algo, Y, jacobi_flags)
if is_implicit(ode_algo)
if is_imex_CTS_algo(ode_algo)
W = SchurComplementW(Y, use_transform(ode_algo), jacobi_flags)
if use_transform(ode_algo)
return (; jac_prototype = W, Wfact_t = Wfact!)
Expand All @@ -57,32 +34,17 @@ function ode_configuration(
ode_name = split(ode_name, ".")[end]
end
ode_sym = Symbol(ode_name)
alg_or_tableau = if hasproperty(ODE, ode_sym)
@warn "apply_limiter flag is ignored for OrdinaryDiffEq algorithms"
getproperty(ODE, ode_sym)
else
getproperty(CTS, ode_sym)
end
alg_or_tableau = getproperty(CTS, ode_sym)
@info "Using ODE config: `$alg_or_tableau`"

if is_explicit_CTS_algo_type(alg_or_tableau)
return CTS.ExplicitAlgorithm(alg_or_tableau())
elseif !is_implicit_type(alg_or_tableau)
elseif !is_imex_CTS_algo_type(alg_or_tableau)
return alg_or_tableau()
elseif is_ordinary_diffeq_newton(alg_or_tableau)
if max_newton_iters == 1
error("OridinaryDiffEq requires at least 2 Newton iterations")
end
# κ like a relative tolerance; its default value in ODE is 0.01
nlsolve = ODE.NLNewton(;
κ = max_newton_iters == 2 ? Inf : 0.01,
max_iter = max_newton_iters,
)
return alg_or_tableau(; linsolve = linsolve!, nlsolve)
elseif is_imex_CTS_algo_type(alg_or_tableau)
newtons_method = CTS.NewtonsMethod(; max_iters = max_newton_iters)
return CTS.IMEXAlgorithm(alg_or_tableau(), newtons_method)
else
return alg_or_tableau(; linsolve = linsolve!)
error("Uncaught case")
end
end
103 changes: 0 additions & 103 deletions examples/ordinary_diff_eq_bug_fixes.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
using OrdinaryDiffEq:
AbstractNLSolver,
isnewton,
DIRK,
update_W!,
initialize!,
Divergence,
get_new_W!,
initial_η,
compute_step!,
apply_step!,
Convergence,
isJcurrent,
postamble!,
TryAgain
using SciMLBase: RECOMPILE_BY_DEFAULT

import OrdinaryDiffEq: nlsolve!
import SciMLBase: SplitFunction

#=
Expand All @@ -40,90 +24,3 @@ function SplitFunction{iip}(f1, f2; kwargs...) where {iip}
tgrad = f1.tgrad,
)
end

#=
Issue: nlsolve! has a goto statement that restarts the solver when the
conditions for DiffEqBase.SlowConvergence (denoted by TryAgain) are
satisfied. These conditions include !isJcurrent, which is always true
when a custom Wfact or Wfact_t is used because of how calc_W! is written.
So, when a custom Wfact or Wfact_t is used, nlsolve! sometimes enters an
infinite loop (though there are also situations where it converges after
several iterations of the loop). This is probably not the intended
behavior, so this patch limits the number of loop iterations to 100,
after which divergence is declared.
=#
function nlsolve!(
nlsolver::AbstractNLSolver,
integrator,
cache = nothing,
repeat_step = false,
)
num_redos = 0
@label REDO
if isnewton(nlsolver)
cache === nothing && throw(
ArgumentError(
"cache is not passed to `nlsolve!` when using NLNewton",
),
)
if nlsolver.method === DIRK
γW = nlsolver.γ * integrator.dt
else
γW = nlsolver.γ * integrator.dt / nlsolver.α
end
update_W!(nlsolver, integrator, cache, γW, repeat_step)
end

(; maxiters, κ, fast_convergence_cutoff) = nlsolver

initialize!(nlsolver, integrator)
nlsolver.status = Divergence
η = get_new_W!(nlsolver) ? initial_η(nlsolver, integrator) : nlsolver.ηold

local ndz
for iter in 1:maxiters
nlsolver.iter = iter

# compute next step and calculate norm of residuals
iter > 1 && (ndzprev = ndz)
ndz = compute_step!(nlsolver, integrator)
if !isfinite(ndz)
nlsolver.status = Divergence
break
end

# check divergence (not in initial step)
if iter > 1
θ = ndz / ndzprev

# divergence
if θ > 2
nlsolver.status = Divergence
break
end
end

apply_step!(nlsolver, integrator)

# check for convergence
iter > 1 && (η = θ / (1 - θ))
if (iter == 1 && ndz < 1e-5) ||
(iter > 1 && (η >= zero(η) && η * ndz < κ))
nlsolver.status = Convergence
break
end
end

if isnewton(nlsolver) &&
nlsolver.status == Divergence &&
!isJcurrent(nlsolver, integrator)
num_redos += 1
if num_redos < 100
nlsolver.status = TryAgain
@goto REDO
end
end

nlsolver.ηold = η
postamble!(nlsolver, integrator)
end
2 changes: 0 additions & 2 deletions perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NVTX = "5da4648a-3479-48b8-97b9-01cb529c0a1f"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PProf = "e4faabce-9ead-11e9-39d9-4379958e3056"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Expand All @@ -37,7 +36,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
OrdinaryDiffEq = "6"
Plots = "1"
SciMLBase = "1, 2"
SnoopCompileCore = "2"
Loading