From 90d1c2a8f1d700cef90083826b0d8a2e41ae7923 Mon Sep 17 00:00:00 2001 From: Julia Sloan Date: Mon, 25 Nov 2024 12:01:16 -0800 Subject: [PATCH] add config_file, job_id defaults --- config/ci_configs/interactive_debug.yml | 19 ------------- experiments/ClimaEarth/cli_options.jl | 5 ++-- experiments/ClimaEarth/run_amip.jl | 3 +- experiments/ClimaEarth/user_io/arg_parsing.jl | 28 ++++++++----------- 4 files changed, 16 insertions(+), 39 deletions(-) delete mode 100644 config/ci_configs/interactive_debug.yml diff --git a/config/ci_configs/interactive_debug.yml b/config/ci_configs/interactive_debug.yml deleted file mode 100644 index 460823a040..0000000000 --- a/config/ci_configs/interactive_debug.yml +++ /dev/null @@ -1,19 +0,0 @@ -apply_limiter: false -coupler_output_dir: "experiments/ClimaEarth/output" -dt: "200secs" -dt_cpl: "200secs" -dt_save_to_sol: "10days" -energy_check: true -evolving_ocean: true -h_elem: 4 -land_albedo_type: "function" -mode_name: "slabplanet" -moist: "equil" -mono_surface: true -precip_model: "0M" -rad: "gray" -start_date: "20100101" -surface_setup: "PrescribedSurface" -t_end: "20days" -turb_flux_partition: "CombinedStateFluxesMOST" -vert_diff: "true" diff --git a/experiments/ClimaEarth/cli_options.jl b/experiments/ClimaEarth/cli_options.jl index a361bf0909..e02fa70ebb 100644 --- a/experiments/ClimaEarth/cli_options.jl +++ b/experiments/ClimaEarth/cli_options.jl @@ -5,10 +5,11 @@ function argparse_settings() ### ClimaCoupler flags # Simulation-identifying information "--config_file" - help = "[REQUIRED] A yaml file used to set the configuration of the coupled model" + help = "A yaml file used to set the configuration of the coupled model [\"config/ci_configs/amip_default.yml\" (default)]" arg_type = String + default = "config/ci_configs/amip_default.yml" "--job_id" - help = "[REQUIRED] A unique identifier for this run" + help = "A unique identifier for this run, defaults to the config file name" arg_type = String default = nothing "--print_config_dict" diff --git a/experiments/ClimaEarth/run_amip.jl b/experiments/ClimaEarth/run_amip.jl index 98d347cf08..c7b46ed39c 100644 --- a/experiments/ClimaEarth/run_amip.jl +++ b/experiments/ClimaEarth/run_amip.jl @@ -88,8 +88,9 @@ We can additionally pass the configuration dictionary to the component model ini include("cli_options.jl") include("user_io/arg_parsing.jl") -config_dict, job_id = get_coupler_config() +config_dict = get_coupler_config() (; + job_id, mode_name, random_seed, FT, diff --git a/experiments/ClimaEarth/user_io/arg_parsing.jl b/experiments/ClimaEarth/user_io/arg_parsing.jl index 201665657a..433b2941eb 100644 --- a/experiments/ClimaEarth/user_io/arg_parsing.jl +++ b/experiments/ClimaEarth/user_io/arg_parsing.jl @@ -7,29 +7,21 @@ is returned along with the job ID. # Returns - `config_dict`: A dictionary mapping configuration keys to the specified settings -- `job_id`: A unique identifier for the job """ function get_coupler_config() - ## coupler simulation default configuration + # Read in command line arguments parsed_args = parse_commandline(argparse_settings()) - ## modify parsed args for fast testing from REPL #hide - if isinteractive() - parsed_args["config_file"] = - isnothing(parsed_args["config_file"]) ? joinpath(pkg_dir, "config/ci_configs/interactive_debug.yml") : - parsed_args["config_file"] - parsed_args["job_id"] = "interactive_debug" - end - - ## the unique job id should be passed in via the command line + # Extract the configuration file and job ID + config_file = parsed_args["config_file"] job_id = parsed_args["job_id"] - @assert !isnothing(job_id) "job_id must be passed in via the command line" - - ## read in config dictionary from file, overriding the coupler defaults in `parsed_args` - config_dict = YAML.load_file(parsed_args["config_file"]) - config_dict = merge(parsed_args, config_dict) + # Get the job ID from the config file string if not provided + job_id = isnothing(job_id) ? split(split(config_file, '/')[end], '.')[1] : job_id - return config_dict, job_id + # Read in config dictionary from file, overriding the defaults in `parsed_args` + config_dict = merge(parsed_args, YAML.load_file(parsed_args["config_file"])) + config_dict["job_id"] = job_id + return config_dict end """ @@ -47,6 +39,7 @@ This function may modify the input dictionary to remove unnecessary keys. function get_coupler_args!(config_dict::Dict) # Simulation-identifying information; Print `config_dict` if requested config_dict["print_config_dict"] && @info(config_dict) + job_id = config_dict["job_id"] mode_name = config_dict["mode_name"] # Computational simulation setup information @@ -108,6 +101,7 @@ function get_coupler_args!(config_dict::Dict) use_land_diagnostics = config_dict["use_land_diagnostics"] return (; + job_id, mode_name, random_seed, FT,