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

Add support for saving checkpoints by calendar dates #3316

Merged
merged 1 commit into from
Sep 19, 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
2 changes: 1 addition & 1 deletion config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test_dycore_consistency:
help: "Test dycore consistency [`false` (default), `true`]"
value: false
dt_save_state_to_disk:
help: "Time between saving the state to disk. Examples: [`10secs`, `1hours`, `Inf` (do not save)]"
help: "Time between saving the state to disk. Examples: [`10secs`, `1hours`, `1months`, `Inf` (do not save)]"
value: "Inf"
dt_save_to_sol:
help: "Time between saving solution. Examples: [`10days`, `1hours`, `Inf` (do not save)]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dt_save_state_to_disk: "100days"
dt_save_state_to_disk: "3months"
initial_condition: "IsothermalProfile"
hyperdiff: false
# It seems radiative equilibrium needs a larger dz near the top
Expand Down
44 changes: 32 additions & 12 deletions src/callbacks/get_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function get_diagnostics(parsed_args, atmos_model, Y, p, dt)
return diagnostics, writers
end

function get_callbacks(config, sim_info, atmos, params, Y, p)
function get_callbacks(config, sim_info, atmos, params, Y, p, t_start)
(; parsed_args, comms_ctx) = config
FT = eltype(params)
(; dt, output_dir) = sim_info
Expand Down Expand Up @@ -209,18 +209,38 @@ function get_callbacks(config, sim_info, atmos, params, Y, p)
),
)

dt_save_state_to_disk =
time_to_seconds(parsed_args["dt_save_state_to_disk"])
if !(dt_save_state_to_disk == Inf)
callbacks = (
callbacks...,
call_every_dt(
(integrator) ->
save_state_to_disk_func(integrator, output_dir),
dt_save_state_to_disk;
skip_first = sim_info.restart,
),
if occursin("months", parsed_args["dt_save_state_to_disk"])
months = match(r"^(\d+)months$", parsed_args["dt_save_state_to_disk"])
isnothing(months) && error(
"$(period_str) has to be of the form <NUM>months, e.g. 2months for 2 months",
)
period_dates = Dates.Month(parse(Int, first(months)))
schedule = CAD.EveryCalendarDtSchedule(
period_dates;
reference_date = p.start_date,
date_last = p.start_date + Dates.Second(t_start),
)
cond = let schedule = schedule
(u, t, integrator) -> schedule(integrator)
end
affect! = let output_dir = output_dir
(integrator) -> save_state_to_disk_func(integrator, output_dir)
end
callbacks = (callbacks..., SciMLBase.DiscreteCallback(cond, affect!))
else
dt_save_state_to_disk =
time_to_seconds(parsed_args["dt_save_state_to_disk"])
if !(dt_save_state_to_disk == Inf)
callbacks = (
callbacks...,
call_every_dt(
(integrator) ->
save_state_to_disk_func(integrator, output_dir),
dt_save_state_to_disk;
skip_first = sim_info.restart,
),
)
end
end

if is_distributed(comms_ctx)
Expand Down
2 changes: 1 addition & 1 deletion src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ function get_simulation(config::AtmosConfig)
@info "ode_configuration: $s"

s = @timed_str begin
callback = get_callbacks(config, sim_info, atmos, params, Y, p)
callback = get_callbacks(config, sim_info, atmos, params, Y, p, t_start)
end
@info "get_callbacks: $s"

Expand Down
Loading