Skip to content

Commit fa115ba

Browse files
authored
Merge pull request #1613 from CliMA/js/input
add Input module
2 parents 12a2308 + d227b69 commit fa115ba

22 files changed

+1090
-582
lines changed

Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ authors = ["CliMA Contributors <[email protected]>"]
44
version = "0.1.2"
55

66
[deps]
7+
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
8+
ClimaAtmos = "b2c96348-7fb7-4fe0-8da9-78d88439e717"
79
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
810
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
911
ClimaUtilities = "b3f4f4ca-9299-4f7f-bd9b-81e1242a7513"
@@ -14,8 +16,11 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1416
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1517
SurfaceFluxes = "49b00bb7-8bd4-4f2b-b78c-51cd0450215f"
1618
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
19+
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
1720

1821
[compat]
22+
ArgParse = "1"
23+
ClimaAtmos = "0.27, 0.28, 0.29, 0.30, 0.31"
1924
ClimaComms = "0.6.2"
2025
ClimaCore = "0.14.25"
2126
ClimaUtilities = "0.1.22"
@@ -26,4 +31,5 @@ SciMLBase = "~2.110, ~2.111, ~2.112"
2631
StaticArrays = "1.9.8"
2732
SurfaceFluxes = "0.12.3, 0.13, 0.14"
2833
Thermodynamics = "0.14.1, 0.15"
34+
YAML = "0.4"
2935
julia = "1.10"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ experiment_pages = [
6363
),
6464
]
6565
interface_pages = [
66+
"input.md",
6667
"checkpointer.md",
6768
"conservation.md",
6869
"fieldexchanger.md",

docs/src/input.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Input
2+
3+
The `Input` module provides functions for parsing command-line arguments and loading
4+
configuration files for ClimaCoupler simulations.
5+
6+
## Providing Configuration Options
7+
8+
ClimaCoupler simulations have a variety of configuration options, which are
9+
described in the section [Available Configuration Options](#available-configuration-options) below.
10+
11+
Users can configure a coupled simulation through 2 main entry points:
12+
command-line arguments and configuration files. Each method, and the
13+
priority between them, is explained here.
14+
15+
Note that all of these configuration are optional; a default AMIP simulation
16+
can be set up with the 0-argument constructor `CoupledSimulation()`.
17+
18+
### Configuration Files
19+
20+
Configuration files are YAML files that specify simulation parameters. They can be
21+
used to specify a valid setting for any configuration option.
22+
23+
Note that since the atmosphere model has many configuration options on its own,
24+
we also support providing an atmosphere-specific configuration file. As a result,
25+
multiple configuration files can be used together:
26+
27+
- **Coupler config file** (`--config_file`): Main configuration file for the coupled simulation
28+
- **Atmos config file** (`--atmos_config_file`): Optional ClimaAtmos-specific configuration
29+
- **TOML parameter files** (`--coupler_toml`): One or more TOML files containing model parameters
30+
31+
When multiple config files are specified, values in the coupler config file will take
32+
precedence over those in the atmosphere config file. This is explained in more detail
33+
in the [Precendence of Config Files and CLI Arguments](#precendence-of-config-files-and-cli-arguments)
34+
section below.
35+
36+
### Parameter TOML Files
37+
38+
Analogous to configuration files, which specify simulation options such as component models or
39+
parameterizations to use, ClimaCoupler also accepts optional TOML files of parameter values.
40+
41+
If a TOML file is provided, the default parameter values will be overwritten by the values
42+
specified in the TOML. If no TOML file is provided, default parameter values will be used.
43+
44+
Since ClimaCoupler accepts coupler config files _and_ atmosphere config files, we may encounter
45+
a case where a TOML file is specified in both config files. In this case, the coupler TOML
46+
file takes highest priority; only if there is no coupler TOML will the atmosphere-specific
47+
TOML be used.
48+
49+
### Command-Line Input (CLI) Arguments
50+
51+
Command-line arguments can be provided when running a simulation:
52+
53+
```bash
54+
julia run_amip.jl --config_file="path/to/config.yml" --job_id="amip_default"
55+
```
56+
57+
Typically, we rely mostly on configuration files, and provide only the `config_file`
58+
and `job_id` via CLI arguments, though if desired any input can be specified in the command line.
59+
All available options and their defaults can be viewed by running with `--help`.
60+
61+
### Precendence of Config Files and CLI Arguments
62+
63+
Users have the ability to specify arguments via both CLI arguments and configuration
64+
files for any given simulation. If this is done, the options are merged
65+
with the following precedence (from lowest to highest priority):
66+
67+
1. **ClimaAtmos defaults** - Default values from the ClimaAtmos package
68+
2. **ClimaCoupler defaults** - Default values defined in [`argparse_settings()`](@ref)
69+
3. **Command-line arguments** - Arguments passed via the command line
70+
4. **ClimaAtmos configuration file** - YAML file specified via `--atmos_config_file` or in the coupler config file
71+
5. **ClimaCoupler configuration file** - YAML file specified via `--config_file` (default: `config/ci_configs/amip_default.yml`)
72+
73+
## Available Configuration Options
74+
75+
The following table lists all available command-line arguments organized by category:
76+
77+
#### Simulation-identifying information
78+
79+
| Argument | Type | Default | Valid Options | Description |
80+
|----------|------|---------|---------------|-------------|
81+
| `--config_file` | String | `config/ci_configs/amip_default.yml` | Any valid file path | YAML file used to set the configuration of the coupled model |
82+
| `--job_id` | String | `nothing` | Any string | A unique identifier for this run, defaults to the config file name |
83+
| `--print_config_dict` | Bool | `true` | `true`, `false` | Whether to print the final configuration dictionary |
84+
| `--mode_name` | String | `"amip"` | `cmip`, `amip`, `subseasonal`, `slabplanet`, `slabplanet_aqua`, `slabplanet_terra` | Mode of coupled simulation |
85+
| `--coupler_toml` | Vector{String} | `[]` | Any list of valid TOML file paths | Optional list of paths to TOML files used to overwrite default model parameters |
86+
87+
#### Computational simulation setup
88+
89+
| Argument | Type | Default | Valid Options | Description |
90+
|----------|------|---------|---------------|-------------|
91+
| `--unique_seed` | Bool | `false` | `true`, `false` | Whether to set the random number seed to a unique value |
92+
| `--FLOAT_TYPE` | String | `"Float64"` | `Float64`, `Float32` | Floating point precision |
93+
| `--device` | String | `"auto"` | `auto`, `CPUSingleThreaded`, `CPUMultiThreaded`, `CUDADevice` | Device type to control running on CPU or GPU |
94+
95+
#### Time information
96+
97+
| Argument | Type | Default | Valid Options | Description |
98+
|----------|------|---------|---------------|-------------|
99+
| `--use_itime` | Bool | `true` | `true`, `false` | Whether to use ClimaUtilities ITime (integer time) or Float64 |
100+
| `--t_end` | String | `"800secs"` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | End time of the simulation, relative to the start date |
101+
| `--t_start` | String | `"0secs"` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Start time of the simulation, relative to the start date |
102+
| `--start_date` | String | `"20000101"` | `"YYYYMMDD"` format | Start date of the simulation |
103+
| `--dt_cpl` | String | `"400secs"` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Coupling time step |
104+
| `--dt` | String | `"400secs"` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Component model time step (used if individual component dt's not specified) |
105+
| `--dt_atmos` | String | `nothing` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Atmos simulation time step (alternative to `dt`) |
106+
| `--dt_land` | String | `nothing` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Land simulation time step (alternative to `dt`) |
107+
| `--dt_ocean` | String | `nothing` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Ocean simulation time step (alternative to `dt`) |
108+
| `--dt_seaice` | String | `nothing` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Sea ice simulation time step (alternative to `dt`) |
109+
| `--checkpoint_dt` | String | `"90days"` | `"Nsecs"`, `"Nmins"`, `"Nhours"`, `"Ndays"`, `"Inf"` | Time interval for checkpointing |
110+
111+
Note: If any component model-specific timestep is specified, _all_ component-model
112+
specific timesteps should be specified, rather than only `dt`.
113+
114+
#### Space information
115+
116+
| Argument | Type | Default | Valid Options | Description |
117+
|----------|------|---------|---------------|-------------|
118+
| `--h_elem` | Int | `16` | Any positive integer | Number of horizontal elements to use for the boundary space |
119+
| `--share_surface_space` | Bool | `true` | `true`, `false` | Whether to share the surface space between surface models, atmosphere, and boundary |
120+
121+
#### Restart information
122+
123+
| Argument | Type | Default | Valid Options | Description |
124+
|----------|------|---------|---------------|-------------|
125+
| `--detect_restart_files` | Bool | `false` | `true`, `false` | Whether to automatically use restart files if available |
126+
| `--restart_dir` | String | `nothing` | Any valid directory path | Directory containing restart files |
127+
| `--restart_t` | Int | `nothing` | Any integer (seconds) | Time in seconds rounded to nearest index to use at `t_start` for restarted simulation |
128+
| `--restart_cache` | Bool | `true` | `true`, `false` | Whether to read the cache from the restart file if available |
129+
| `--save_cache` | Bool | `true` | `true`, `false` | Whether to save the state and cache or only the state when checkpointing |
130+
131+
#### Diagnostics and output
132+
133+
| Argument | Type | Default | Valid Options | Description |
134+
|----------|------|---------|---------------|-------------|
135+
| `--use_coupler_diagnostics` | Bool | `true` | `true`, `false` | Whether to compute and output coupler diagnostics |
136+
| `--coupler_output_dir` | String | `"experiments/ClimaEarth/output"` | Any valid directory path | Directory to save output files |
137+
138+
139+
140+
#### Conservation and RMSE checks
141+
142+
| Argument | Type | Default | Valid Options | Description |
143+
|----------|------|---------|---------------|-------------|
144+
| `--energy_check` | Bool | `false` | `true`, `false` | Whether to check energy conservation |
145+
| `--conservation_softfail` | Bool | `false` | `true`, `false` | Whether to soft fail on conservation errors |
146+
| `--rmse_check` | Bool | `false` | `true`, `false` | Whether to check RMSE of some physical fields |
147+
148+
#### ClimaAtmos specific
149+
150+
| Argument | Type | Default | Valid Options | Description |
151+
|----------|------|---------|---------------|-------------|
152+
| `--surface_setup` | String | `"PrescribedSurface"` | `PrescribedSurface`, `DefaultMoninObukhov` | Triggers ClimaAtmos into coupled mode |
153+
| `--atmos_config_file` | String | `nothing` | Any valid file path | Optional YAML file used to overwrite default model parameters |
154+
| `--atmos_log_progress` | Bool | `false` | `true`, `false` | Use ClimaAtmos walltime logging callback instead of default ClimaCoupler one |
155+
| `--albedo_model` | String | `"CouplerAlbedo"` | `ConstantAlbedo`, `RegressionFunctionAlbedo`, `CouplerAlbedo` | Type of albedo model |
156+
| `--extra_atmos_diagnostics` | Vector{Dict{Any, Any}} | `[]` | List of dictionaries | List of dictionaries containing information about additional atmosphere diagnostics to output |
157+
158+
#### ClimaLand specific
159+
160+
| Argument | Type | Default | Valid Options | Description |
161+
|----------|------|---------|---------------|-------------|
162+
| `--land_model` | String | `"bucket"` | `bucket`, `integrated` | Land model to use |
163+
| `--land_temperature_anomaly` | String | `"aquaplanet"` | `amip`, `aquaplanet`, `nothing` | Type of temperature anomaly for land model |
164+
| `--use_land_diagnostics` | Bool | `true` | `true`, `false` | Whether to compute and output land model diagnostics |
165+
| `--land_spun_up_ic` | Bool | `true` | `true`, `false` | Whether to use integrated land initial conditions from spun up state |
166+
| `--bucket_albedo_type` | String | `"map_static"` | `map_static`, `function`, `map_temporal` | Access bucket surface albedo information from data file |
167+
| `--bucket_initial_condition` | String | `""` | Any valid file path | File path for a NetCDF file (read documentation about requirements) |
168+
| `--era5_initial_condition_dir` | String | `nothing` | Any valid directory path | Directory containing ERA5 initial condition files (subseasonal mode). Filenames inferred from `start_date`. Generated with `https://github.com/CliMA/WeatherQuest` |
169+
170+
#### Ice model specific
171+
172+
| Argument | Type | Default | Valid Options | Description |
173+
|----------|------|---------|---------------|-------------|
174+
| `--ice_model` | String | `"prescribed"` | `prescribed`, `clima_seaice` | Sea ice model to use |
175+
176+
177+
#### Ocean model specific
178+
179+
| Argument | Type | Default | Valid Options | Description |
180+
|----------|------|---------|---------------|-------------|
181+
| `--evolving_ocean` | Bool | `true` | `true`, `false` | Whether to use a dynamic slab ocean model, as opposed to constant surface temperatures |
182+
183+
## Input API
184+
185+
```@docs
186+
ClimaCoupler.Input.argparse_settings
187+
ClimaCoupler.Input.parse_commandline
188+
ClimaCoupler.Input.get_coupler_config_dict
189+
ClimaCoupler.Input.get_coupler_args
190+
```

experiments/ClimaEarth/Manifest-v1.11.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.11.5"
3+
julia_version = "1.11.6"
44
manifest_format = "2.0"
5-
project_hash = "f84997fb003cca7320c93d5448b91701d73e02c0"
5+
project_hash = "d502ec36505df261b2f120a7277a749ea8bcd37a"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "8b2b045b22740e4be20654175cc38291d48539db"
@@ -465,7 +465,7 @@ uuid = "908f55d8-4145-4867-9c14-5dad1a479e4d"
465465
version = "0.4.6"
466466

467467
[[deps.ClimaCoupler]]
468-
deps = ["ClimaComms", "ClimaCore", "ClimaUtilities", "Dates", "JLD2", "Logging", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics"]
468+
deps = ["ArgParse", "ClimaAtmos", "ClimaComms", "ClimaCore", "ClimaUtilities", "Dates", "JLD2", "Logging", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics", "YAML"]
469469
path = "../.."
470470
uuid = "4ade58fe-a8da-486c-bd89-46df092ec0c7"
471471
version = "0.1.2"

0 commit comments

Comments
 (0)