|
| 1 | +# This test runs a small AMIP simulation four times. |
| 2 | +# |
| 3 | +# - The first time the simulation is run for four steps |
| 4 | +# - The second time the simulation is run for two steps |
| 5 | +# - The third time the simulation is run for two steps, but restarting from the |
| 6 | +# second simulation |
| 7 | +# |
| 8 | +# After all these simulations are run, we compare the first and last runs. They |
| 9 | +# should be bit-wise identical. |
| 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("../code_loading.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__, "restart_cmip.yml") |
| 40 | +config_dict = Input.get_coupler_config_dict(config_file) |
| 41 | + |
| 42 | +# Four steps |
| 43 | +four_steps = deepcopy(config_dict) |
| 44 | + |
| 45 | +four_steps["t_end"] = "960secs" |
| 46 | +four_steps["coupler_output_dir"] = tmpdir |
| 47 | +four_steps["checkpoint_dt"] = "960secs" |
| 48 | +four_steps["job_id"] = "four_steps" |
| 49 | + |
| 50 | +println("Simulating four steps") |
| 51 | +cs_four_steps = setup_and_run(four_steps) |
| 52 | + |
| 53 | +# Check that we can pick up a simulation by providing t_restart and restart_dir |
| 54 | +println("Simulating four steps, options from command line") |
| 55 | +four_steps_reading = deepcopy(four_steps) |
| 56 | + |
| 57 | +four_steps_reading["t_end"] = "1200secs" |
| 58 | +four_steps_reading["detect_restart_files"] = true |
| 59 | +four_steps_reading["restart_dir"] = cs_four_steps.dir_paths.checkpoints_dir |
| 60 | +four_steps_reading["restart_t"] = 960 |
| 61 | +four_steps_reading["job_id"] = "four_steps_reading" |
| 62 | +Input.update_t_start_for_restarts!(four_steps_reading) |
| 63 | + |
| 64 | +cs_four_steps_reading = setup_and_run(four_steps_reading) |
| 65 | +@testset "CMIP restarts (state and cache)" begin |
| 66 | + @test cs_four_steps_reading.tspan[1] == cs_four_steps.tspan[2] |
| 67 | +end |
| 68 | + |
| 69 | +# Now, two steps plus one |
| 70 | +two_steps = deepcopy(config_dict) |
| 71 | + |
| 72 | +two_steps["t_end"] = "480secs" |
| 73 | +two_steps["coupler_output_dir"] = tmpdir |
| 74 | +two_steps["checkpoint_dt"] = "480secs" |
| 75 | +two_steps["job_id"] = "two_steps" |
| 76 | + |
| 77 | +# Copying since setup_and_run changes its content |
| 78 | +println("Simulating two steps") |
| 79 | +cs_two_steps1 = setup_and_run(two_steps) |
| 80 | + |
| 81 | +println("Reading and simulating last two steps") |
| 82 | +# Two additional steps |
| 83 | +two_steps["t_end"] = "960secs" |
| 84 | +two_steps["detect_restart_files"] = true |
| 85 | +Input.update_t_start_for_restarts!(two_steps) |
| 86 | +cs_two_steps2 = setup_and_run(two_steps) |
| 87 | + |
| 88 | +@testset "Restarts" begin |
| 89 | + # We put cs_four_steps.fields in a NamedTuple so that we can start the recursion in compare |
| 90 | + @test compare( |
| 91 | + (; coupler_fields = cs_four_steps.fields), |
| 92 | + (; coupler_fields = cs_two_steps2.fields), |
| 93 | + ) |
| 94 | + |
| 95 | + @test compare( |
| 96 | + cs_four_steps.model_sims.atmos_sim.integrator.u, |
| 97 | + cs_two_steps2.model_sims.atmos_sim.integrator.u, |
| 98 | + ) |
| 99 | + |
| 100 | + @test compare( |
| 101 | + cs_four_steps.model_sims.atmos_sim.integrator.p, |
| 102 | + cs_two_steps2.model_sims.atmos_sim.integrator.p, |
| 103 | + ignore = [ |
| 104 | + :walltime_estimate, # Stateful |
| 105 | + :output_dir, # Changes across runs |
| 106 | + :scratch, # Irrelevant |
| 107 | + :ghost_buffer, # Irrelevant |
| 108 | + :hyperdiffusion_ghost_buffer, # Irrelevant |
| 109 | + :data_handler, # Stateful |
| 110 | + :face_clear_sw_direct_flux_dn, # Not filled by RRTGMP |
| 111 | + :face_sw_direct_flux_dn, # Not filled by RRTGMP |
| 112 | + :rc, # CUDA internal object |
| 113 | + ], |
| 114 | + ) |
| 115 | + |
| 116 | + @test compare( |
| 117 | + cs_four_steps.model_sims.land_sim.integrator.u, |
| 118 | + cs_two_steps2.model_sims.land_sim.integrator.u, |
| 119 | + ) |
| 120 | + @test compare( |
| 121 | + cs_four_steps.model_sims.land_sim.integrator.p, |
| 122 | + cs_two_steps2.model_sims.land_sim.integrator.p, |
| 123 | + ignore = [:dss_buffer_3d, :dss_buffer_2d, :rc], |
| 124 | + ) |
| 125 | + |
| 126 | + @test compare( |
| 127 | + cs_four_steps.model_sims.ice_sim.ice.model, |
| 128 | + cs_two_steps2.model_sims.ice_sim.ice.model, |
| 129 | + ignore = [:clock, :parent, :ptr] |
| 130 | + ) |
| 131 | + |
| 132 | + @test compare( |
| 133 | + cs_four_steps.model_sims.ocean_sim.ocean.model, |
| 134 | + cs_two_steps2.model_sims.ocean_sim.ocean.model, |
| 135 | + ignore = [:clock, :parent, :ptr] |
| 136 | + ) |
| 137 | +end |
0 commit comments