Skip to content

Commit 4100858

Browse files
committed
Add save_cache option
1 parent 97eeb0b commit 4100858

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

experiments/ClimaEarth/cli_options.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ function argparse_settings()
104104
help = "Boolean flag indicating whether to read the cache from the restart file if available [`true` (default), `false`]"
105105
arg_type = Bool
106106
default = true
107+
"--save_cache"
108+
help = "Boolean flag indicating whether to save the cache or not when checkpointing [`true` (default), `false`]"
109+
arg_type = Bool
110+
default = true
107111
# Diagnostics information
108112
"--use_coupler_diagnostics"
109113
help = "Boolean flag indicating whether to compute and output coupler diagnostics [`true` (default), `false`]"

experiments/ClimaEarth/setup_run.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function CoupledSimulation(config_dict::AbstractDict)
131131
restart_dir,
132132
restart_t,
133133
restart_cache,
134+
save_cache,
134135
use_land_diagnostics,
135136
diagnostics_dt,
136137
evolving_ocean,
@@ -493,7 +494,10 @@ function CoupledSimulation(config_dict::AbstractDict)
493494
=#
494495
schedule_checkpoint =
495496
EveryCalendarDtSchedule(TimeManager.time_to_period(checkpoint_dt); start_date)
496-
checkpoint_cb = TimeManager.Callback(schedule_checkpoint, Checkpointer.checkpoint_sims)
497+
checkpoint_cb = TimeManager.Callback(
498+
schedule_checkpoint,
499+
sim -> Checkpointer.checkpoint_sims(sim, save_cache),
500+
)
497501

498502
callbacks = (checkpoint_cb,)
499503

experiments/ClimaEarth/test/restart_state_only.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ two_steps["dt_rad"] = "180secs"
4949
two_steps["checkpoint_dt"] = "360secs"
5050
two_steps["coupler_output_dir"] = tmpdir
5151
two_steps["job_id"] = "two_steps"
52+
two_steps["save_cache"] = false
5253

5354
println("Simulating two steps")
5455
cs_two_steps = setup_and_run(two_steps)
5556

57+
@testset "Cache files should not exist" begin
58+
checkpoints_dir = joinpath(tmpdir, two_steps["job_id"], "checkpoints")
59+
checkpoint_files = filter!(isfile, readdir(checkpoints_dir, join = true))
60+
are_not_cache_files = .!occursin.("cache", basename.(checkpoint_files))
61+
@test all(are_not_cache_files)
62+
end
63+
5664
# Check that we can pick up a simulation by providing t_restart and restart_dir
5765
println("Simulating two steps, options from command line")
5866
two_steps_reading = deepcopy(two_steps)
@@ -63,6 +71,7 @@ two_steps_reading["restart_dir"] = cs_two_steps.dir_paths.checkpoints_dir
6371
two_steps_reading["restart_t"] = 360
6472
two_steps_reading["restart_cache"] = false
6573
two_steps_reading["job_id"] = "two_steps_reading"
74+
two_steps_reading["save_cache"] = false
6675

6776
cs_two_steps_reading = setup_and_run(two_steps_reading)
6877
@testset "Restarts from command line arguments" begin

experiments/ClimaEarth/user_io/arg_parsing.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ function get_coupler_args(config_dict::Dict)
144144
restart_dir = config_dict["restart_dir"]
145145
restart_t = config_dict["restart_t"]
146146
restart_cache = config_dict["restart_cache"]
147+
save_cache = config_dict["save_cache"]
147148

148149
# Diagnostics information
149150
use_coupler_diagnostics = config_dict["use_coupler_diagnostics"]
@@ -192,6 +193,7 @@ function get_coupler_args(config_dict::Dict)
192193
restart_dir,
193194
restart_t,
194195
restart_cache,
196+
save_cache,
195197
use_coupler_diagnostics,
196198
diagnostics_dt,
197199
evolving_ocean,

src/Checkpointer.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ function restore_cache!(sim::Interfacer.ComponentModelSimulation, new_cache)
126126
end
127127

128128
"""
129-
checkpoint_sims(cs::CoupledSimulation)
129+
checkpoint_sims(cs::CoupledSimulation, save_cache)
130130
131-
This is a callback function that checkpoints all simulations defined in the current coupled simulation.
131+
This is a callback function that checkpoints all simulations defined in the
132+
current coupled simulation. The argument `save_cache` determines whether to save
133+
the cache or not.
132134
"""
133-
function checkpoint_sims(cs::Interfacer.CoupledSimulation)
135+
function checkpoint_sims(cs::Interfacer.CoupledSimulation, save_cache)
134136
time = Int(round(float(cs.t[])))
135137
day = floor(Int, time / (60 * 60 * 24))
136138
sec = floor(Int, time % (60 * 60 * 24))
@@ -148,7 +150,7 @@ function checkpoint_sims(cs::Interfacer.CoupledSimulation)
148150
output_dir,
149151
)
150152
end
151-
if !isnothing(Checkpointer.get_model_cache(sim))
153+
if !isnothing(Checkpointer.get_model_cache(sim)) && save_cache
152154
Checkpointer.checkpoint_model_cache(
153155
sim,
154156
comms_ctx,

0 commit comments

Comments
 (0)