Skip to content

Commit 3e78cf6

Browse files
committed
Fix restarting simulation from command line
This commit fixes a broken option in ClimaCoupler. ClimaCoupler would not restart correctly when the details for the restart were passed via command line, unless `restart_dir` was the same as `output_dir_root`. Version 0.29.1 of ClimaAtmos introduces a way to go around the underlying problem that introduced that bug and also introduced a second limitation to the restart system. Closes #1218
1 parent 796626f commit 3e78cf6

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

experiments/ClimaEarth/setup_run.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,17 @@ function setup_and_run(config_dict::AbstractDict)
242242
t_start = restart_t
243243
end
244244

245-
# TODO: Find a cleaner way to do this instead of having a second restart
246-
# just for atmos
247-
atmos_config_dict["restart_file"] = climaatmos_restart_path(output_dir_root, restart_t)
245+
if pkgversion(CA) >= v"0.29.1"
246+
# We only support a round number of seconds
247+
isinteger(float(t_start)) || error("Cannot restart from a non integer number of seconds")
248+
t_start_int = Int(float(t_start))
249+
atmos_config_dict["t_start"] = "$(t_start_int)secs"
250+
else
251+
# There was no `t_start`, so we have to use a workaround for this.
252+
# This does not support passing the command-line arguments (unless
253+
# restart_dir is exactly the same as output_dir_root)
254+
atmos_config_dict["restart_file"] = climaatmos_restart_path(output_dir_root, restart_t)
255+
end
248256

249257
@info "Starting from t_start $(t_start)"
250258
end

experiments/ClimaEarth/test/restart.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,26 @@ four_steps["dt"] = "180secs"
4747
four_steps["dt_cpl"] = "180secs"
4848
four_steps["t_end"] = "720secs"
4949
four_steps["dt_rad"] = "180secs"
50+
four_steps["checkpoint_dt"] = "720secs"
51+
four_steps["coupler_output_dir"] = tmpdir
5052
four_steps["job_id"] = "four_steps"
5153

54+
println("Simulating four steps")
5255
cs_four_steps = setup_and_run(four_steps)
5356

54-
println("Simulating two steps")
57+
# Check that we can pick up a simulation by providing t_restart and restart_dir
58+
println("Simulating four steps, options from command line")
59+
four_steps_reading = deepcopy(four_steps)
60+
61+
four_steps_reading["t_end"] = "900secs"
62+
four_steps_reading["restart_dir"] = cs_four_steps.dirs.checkpoints
63+
four_steps_reading["restart_t"] = 720
64+
four_steps_reading["job_id"] = "four_steps_reading"
65+
66+
cs_four_steps_reading = setup_and_run(four_steps_reading)
67+
@testset "Restarts from command line arguments" begin
68+
@test cs_four_steps_reading.tspan[1] == cs_four_steps.tspan[2]
69+
end
5570

5671
# Now, two steps plus one
5772
two_steps = deepcopy(default_config)
@@ -65,9 +80,10 @@ two_steps["checkpoint_dt"] = "360secs"
6580
two_steps["job_id"] = "two_steps"
6681

6782
# Copying since setup_and_run changes its content
83+
println("Simulating two steps")
6884
cs_two_steps1 = setup_and_run(two_steps)
6985

70-
println("Reading and simulating last step")
86+
println("Reading and simulating last two steps")
7187
# Two additional steps
7288
two_steps["t_end"] = "720secs"
7389
cs_two_steps2 = setup_and_run(two_steps)

experiments/ClimaEarth/user_io/arg_parsing.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ function get_coupler_args(config_dict::Dict)
9292

9393
# Restart information
9494
restart_dir = config_dict["restart_dir"]
95-
restart_t =
96-
isnothing(config_dict["restart_t"]) ? nothing : Int64(Utilities.time_to_seconds(config_dict["restart_t"]))
95+
restart_t = config_dict["restart_t"]
9796

9897
# Diagnostics information
9998
use_coupler_diagnostics = config_dict["use_coupler_diagnostics"]

0 commit comments

Comments
 (0)