-
Notifications
You must be signed in to change notification settings - Fork 6
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
Improve unit tests by testing the sequence of operations per algorithm #106
Comments
More local notes: using Revise;
import ClimaTimeSteppers as CTS
import OrdinaryDiffEq as ODE
import LinearAlgebra as LA
struct SchurComplementW{T}; p::T; end
Base.similar(w::SchurComplementW) = w
T_imp!(Yₜ, Y, p, t) = collect_meta(p, t, T_imp!)
T_exp!(Yₜ, Y, p, t) = collect_meta(p, t, T_exp!)
Wfact!(Yₜ, Y, p, Δt, t) = collect_meta(p, t, Wfact!)
implicit_tendency!(Yₜ, Y, p, t) = collect_meta(p, t, implicit_tendency!)
explicit_tendency!(Yₜ, Y, p, t) = collect_meta(p, t, explicit_tendency!)
tgrad!(Yₜ, Y, p, t) = collect_meta(p, t, tgrad!)
LA.ldiv!(x, W::SchurComplementW, b) = collect_meta(p, nothing, LA.ldiv!)
function collect_meta(p, t, f)
(; algo_mapper) = p
push!(algo_mapper[string(f)], t)
algo_mapper["ctr"][1] += 1
end
Y₀ = zeros(Float64, 1)
FT = Float64
algo_mapper = Dict(
"ctr" => [0],
"T_imp!" => [],
"T_exp!" => [],
"Wfact!" => [],
"implicit_tendency!" => [],
"explicit_tendency!" => [],
"tgrad!" => [],
"ldiv!" => [],
)
p = (; algo_mapper)
jac_prototype=SchurComplementW(p)
func_args = (; jac_prototype, Wfact = Wfact!, tgrad = tgrad!)
split_tendency_func = CTS.ClimaODEFunction(;
T_exp! = explicit_tendency!,
T_imp! = ODE.ODEFunction(implicit_tendency!; func_args...),
)
prob = ODE.ODEProblem(split_tendency_func, Y₀, (FT(0), FT(1)), p)
alg = CTS.NewARS343(CTS.NewtonsMethod(; max_iters=1))
integrator = ODE.init(prob, alg; dt=FT(0.1), save_everystep = true)
CTS.step_u!(integrator) |
charleskawczynski
changed the title
Add meta collection utility
Improve unit tests by testing the sequence of operations per algorithm
Jan 22, 2025
1 task
@dennisYatunin gave a great suggestion to handle the increment, we can define a type, overload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The essence of this issue is to improve unit tests by testing the sequence of operations per algorithm.
We might be able to do that by adding a meta collection utility. This would both improve the quality of our unit tests, and algorithm transparency (and optimization monitoring). Here's a scratch pad of what I had locally:
The text was updated successfully, but these errors were encountered: