Skip to content

Commit 4ac377a

Browse files
committed
Add save_cache option
1 parent cba618c commit 4ac377a

File tree

11 files changed

+31
-3
lines changed

11 files changed

+31
-3
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 state and cache or only the state 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: 4 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,8 @@ 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 =
498+
TimeManager.Callback(schedule_checkpoint, sim -> Checkpointer.checkpoint_sims(sim))
497499

498500
callbacks = (checkpoint_cb,)
499501

@@ -537,6 +539,7 @@ function CoupledSimulation(config_dict::AbstractDict)
537539
dir_paths,
538540
thermo_params,
539541
diags_handler,
542+
save_cache,
540543
)
541544

542545
#=

experiments/ClimaEarth/test/component_model_tests/climaland_tests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ end
126126
(;), # dir_paths
127127
thermo_params, # thermo_params
128128
nothing, # diags_handler
129+
true, # save_cache
129130
)
130131

131132
# Step the atmosphere once to get non-zero wind and humidity so the fluxes are non-zero

experiments/ClimaEarth/test/debug_plots_tests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ plot_field_names(sim::Interfacer.SurfaceStub) = (:stub_field,)
9292
(;), # dir_paths
9393
nothing, # thermo_params
9494
nothing, # diags_handler
95+
true, # save_cache
9596
)
9697

9798
output_plots = "test_debug"

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ end
128128
"""
129129
checkpoint_sims(cs::CoupledSimulation)
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.
132133
"""
133134
function checkpoint_sims(cs::Interfacer.CoupledSimulation)
134135
time = Int(round(float(cs.t[])))
@@ -148,7 +149,7 @@ function checkpoint_sims(cs::Interfacer.CoupledSimulation)
148149
output_dir,
149150
)
150151
end
151-
if !isnothing(Checkpointer.get_model_cache(sim))
152+
if !isnothing(Checkpointer.get_model_cache(sim)) && cs.save_cache
152153
Checkpointer.checkpoint_model_cache(
153154
sim,
154155
comms_ctx,

src/Interfacer.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct CoupledSimulation{
6060
NTP <: NamedTuple,
6161
TP,
6262
DH,
63+
SC <: Bool,
6364
}
6465
start_date::D
6566
fields::FV
@@ -73,6 +74,7 @@ struct CoupledSimulation{
7374
dir_paths::NTP
7475
thermo_params::TP
7576
diags_handler::DH
77+
save_cache::SC
7678
end
7779

7880
CoupledSimulation{FT}(args...) where {FT} = CoupledSimulation{FT, typeof.(args)...}(args...)

test/conservation_checker_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ for FT in (Float32, Float64)
8585
(;), # dir_paths
8686
nothing, # thermo_params
8787
nothing, # diags_handler
88+
true, # save_cache
8889
)
8990

9091
# set non-zero radiation and precipitation
@@ -187,6 +188,7 @@ for FT in (Float32, Float64)
187188
(;), # dir_paths
188189
nothing, # thermo_params
189190
nothing, # diags_handler
191+
true, # save_cache
190192
)
191193

192194
tot_energy, tot_water = ConservationChecker.check_conservation!(cs)

test/field_exchanger_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ for FT in (Float32, Float64)
226226
(;), # dir_paths
227227
nothing, # thermo_params
228228
nothing, # diags_handler
229+
true, # save_cache
229230
)
230231

231232
FieldExchanger.update_surface_fractions!(cs)
@@ -521,6 +522,7 @@ for FT in (Float32, Float64)
521522
(;), # dir_paths
522523
thermo_params, # thermo_params
523524
nothing, # diags_handler
525+
true, # save_cache
524526
)
525527

526528
# perform the exchange

0 commit comments

Comments
 (0)