|
| 1 | +# This test runs a small AMIP simulation twice times. |
| 2 | +# |
| 3 | +# - The first time the simulation is run for two steps |
| 4 | +# - The second time the simulation is run for two steps, but restarting from the |
| 5 | +# first simulation |
| 6 | +# |
| 7 | +# Since the caches are not read from the restart file, the results will not be |
| 8 | +# bit-wise identical to running the simulation without restarting. This test |
| 9 | +# only checks that a simulation can be restarted from the state only without erroring. |
| 10 | +# |
| 11 | +# The content of the simulation is not the most important, but it helps if it |
| 12 | +# has all of the complexity possible. |
| 13 | + |
| 14 | +import ClimaComms |
| 15 | +ClimaComms.@import_required_backends |
| 16 | +import ClimaUtilities.OutputPathGenerator: maybe_wait_filesystem |
| 17 | +import YAML |
| 18 | +import Logging |
| 19 | +using Test |
| 20 | + |
| 21 | +# Uncomment the following for cleaner output (but more difficult debugging) |
| 22 | +# Logging.disable_logging(Logging.Warn) |
| 23 | + |
| 24 | +include("compare.jl") |
| 25 | +include("../setup_run.jl") |
| 26 | + |
| 27 | +comms_ctx = ClimaComms.context() |
| 28 | +@info "Context: $(comms_ctx)" |
| 29 | +ClimaComms.init(comms_ctx) |
| 30 | + |
| 31 | +# Make sure that all MPI processes agree on the output_loc |
| 32 | +tmpdir = ClimaComms.iamroot(comms_ctx) ? mktempdir(pwd()) : "" |
| 33 | +tmpdir = ClimaComms.bcast(comms_ctx, tmpdir) |
| 34 | +# Sometimes the shared filesystem doesn't work properly and the folder is not |
| 35 | +# synced across MPI processes. Let's add an additional check here. |
| 36 | +maybe_wait_filesystem(ClimaComms.context(), tmpdir) |
| 37 | + |
| 38 | +# Parse the input config file as a dictionary |
| 39 | +config_file = joinpath(@__DIR__, "amip_test.yml") |
| 40 | +config_dict = get_coupler_config_dict(config_file) |
| 41 | + |
| 42 | +# Four steps |
| 43 | +two_steps = deepcopy(config_dict) |
| 44 | + |
| 45 | +two_steps["dt"] = "180secs" |
| 46 | +two_steps["dt_cpl"] = "180secs" |
| 47 | +two_steps["t_end"] = "360secs" |
| 48 | +two_steps["dt_rad"] = "180secs" |
| 49 | +two_steps["checkpoint_dt"] = "360secs" |
| 50 | +two_steps["coupler_output_dir"] = tmpdir |
| 51 | +two_steps["job_id"] = "two_steps" |
| 52 | + |
| 53 | +println("Simulating two steps") |
| 54 | +cs_two_steps = setup_and_run(two_steps) |
| 55 | + |
| 56 | +# Check that we can pick up a simulation by providing t_restart and restart_dir |
| 57 | +println("Simulating two steps, options from command line") |
| 58 | +two_steps_reading = deepcopy(two_steps) |
| 59 | + |
| 60 | +two_steps_reading["t_end"] = "540secs" |
| 61 | +two_steps_reading["detect_restart_files"] = true |
| 62 | +two_steps_reading["restart_dir"] = cs_two_steps.dir_paths.checkpoints_dir |
| 63 | +two_steps_reading["restart_t"] = 360 |
| 64 | +two_steps_reading["restart_cache"] = false |
| 65 | +two_steps_reading["job_id"] = "two_steps_reading" |
| 66 | + |
| 67 | +cs_two_steps_reading = setup_and_run(two_steps_reading) |
| 68 | +@testset "Restarts from command line arguments" begin |
| 69 | + @test cs_two_steps_reading.tspan[1] == cs_two_steps.tspan[2] |
| 70 | +end |
0 commit comments