Skip to content

Commit 377d7df

Browse files
committed
Add subseasonal calibration pipeline
1 parent 74e724d commit 377d7df

File tree

19 files changed

+820
-78
lines changed

19 files changed

+820
-78
lines changed

.buildkite/longruns/pipeline.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,15 @@ steps:
184184
- group: "Calibration experiments"
185185

186186
steps:
187-
- label: "Perfect model calibration test"
188-
key: "amip_pm_calibration"
187+
- label: "Subseasonal calibration test"
188+
key: "subseasonal_calibration"
189189
command:
190-
- "julia --color=yes --project=experiments/ClimaEarth experiments/calibration/run_calibration.jl"
191-
artifact_paths: "experiments/calibration/output/*"
192-
env:
193-
CLIMACOMMS_DEVICE: "CUDA"
194-
CLIMACOMMS_CONTEXT: "MPI"
190+
- julia --color=yes --project=experiments/ClimaEarth experiments/calibration/subseasonal/generate_observations.jl
191+
- julia --color=yes --project=experiments/ClimaEarth experiments/calibration/subseasonal/run_calibration.jl
192+
artifact_paths: "experiments/calibration/subseasonal/output/*"
195193
agents:
196194
queue: clima
197-
slurm_mem: 96GB
198-
slurm_ntasks: 3
199-
slurm_gpus_per_task: 1
200-
slurm_cpus_per_task: 4
201-
slurm_time: 05:00:00
195+
slurm_time: 24:00:00
202196

203197
- wait
204198

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ steps:
395395
- label: "Perfect model calibration test"
396396
key: "amip_pm_calibration"
397397
command:
398-
- "julia --color=yes --project=experiments/ClimaEarth experiments/calibration/run_calibration.jl"
398+
- "julia --color=yes --project=experiments/ClimaEarth experiments/calibration/test/run_calibration.jl"
399399
artifact_paths: "experiments/calibration/output/*"
400400
env:
401401
CLIMACOMMS_DEVICE: "CUDA"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ docs/src/generated/
3030
# Experiments
3131
!experiments/ClimaEarth/**/Manifest.toml
3232
!experiments/ClimaCore/**/Manifest.toml
33+
experiments/calibration/coarse_amip/output*/
3334

3435
# Output
3536
output/

config/atmos_configs/climaatmos_wx_diagedmf.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ insolation: "timevarying"
1515
rad: allskywithclear
1616
dt_cloud_fraction: "1hours"
1717
dt_rad: "1hours"
18-
# time_varying_trace_gases: ["O3"]
19-
# prescribed_aerosols: ["CB1", "CB2", "DST01", "OC1", "OC2", "SO4", "SSLT01"]
18+
aerosol_radiation: true
19+
time_varying_trace_gases: ["CO2", "O3"]
20+
prescribed_aerosols: ["CB1", "CB2", "DST01", "DST02", "DST03", "DST04", "DST05", "OC1", "OC2", "SO4", "SSLT01", "SSLT02", "SSLT03", "SSLT04", "SSLT05"]
2021
turbconv: diagnostic_edmfx
2122
implicit_diffusion: true
2223
approximate_linear_solve_iters: 2
2324
prognostic_tke: true
2425
edmfx_upwinding: first_order
25-
h_elem: 15
26-
z_max: 48000.0
26+
h_elem: 16
27+
z_max: 60000.0
2728
z_elem: 63
2829
dz_bottom: 30.0
2930
edmfx_entr_model: "Generalized"

config/subseasonal_configs/wxquest_diagedmf.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@ FLOAT_TYPE: "Float32"
22
albedo_model: "CouplerAlbedo"
33
atmos_config_file: "config/atmos_configs/climaatmos_wx_diagedmf.yml"
44
coupler_toml: ["toml/amip_diagedmf.toml"]
5-
mode_name: "subseasonal"
6-
era5_initial_condition_dir: "/net/sampo/data1/wxquest_data/initial_conditions"
75
initial_condition: "WeatherModel"
86
checkpoint_dt: "7days"
9-
dt: "30secs"
10-
dt_cpl: "30secs"
7+
dt: "120secs"
8+
dt_cpl: "120secs"
9+
dt_cloud_fraction: "1hours"
10+
dt_rad: "1hours"
1111
energy_check: false
1212
h_elem: 16
1313
land_fraction_source: "era5"
1414
binary_area_fraction: false
15-
16-
### integrated land ###
17-
# land_model: "integrated"
18-
19-
### bucket land ###
15+
mode_name: "subseasonal"
16+
era5_initial_condition_dir: "/net/sampo/data1/wxquest_data/initial_conditions"
2017
land_model: "bucket"
2118
bucket_albedo_type: "map_temporal"
22-
bucket_initial_condition: "/net/sampo/data1/wxquest_data/initial_conditions/era5_bucket_processed_20250907_0000.nc"
23-
2419
land_spun_up_ic: false
2520
land_temperature_anomaly: "nothing"
26-
use_land_diagnostics: true
2721
radiation_reset_rng_seed: true
28-
start_date: "20250907"
22+
start_date: "20180901"
2923
surface_setup: "PrescribedSurface"
3024
topo_smoothing: true
3125
topography: "Earth"
32-
t_end: "7days"
3326
netcdf_output_at_levels: true
27+
output_default_diagnostics: false
28+
use_coupler_diagnostics: false
29+
use_land_diagnostics: false
30+
strict_params: false
31+
insolation: "timevarying"
3432
extra_atmos_diagnostics:
35-
- short_name: [tas, mslp, pr, ua, va, rhoa, pfull, hur, hus, clw, cli, clivi, clwvi, cl, arup, tke]
36-
period: 1hours
37-
reduction_time: average
33+
- short_name: [hfls, hfss, rsus, rlus]
34+
period: 1months
35+
reduction_time: average

experiments/ClimaEarth/Artifacts.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ git-tree-sha1 = "7f14ef1c7859da1363b8973743b2a376c008f29f"
4545
[[era5_land_fraction.download]]
4646
sha256 = "1d6acf98656b50f1a324ee3daa267281fb017314d2169dbfda25208299f44870"
4747
url = "https://caltech.box.com/shared/static/glqlyb626j3szcjltyuwp534yzzhf770.gz"
48+
49+
[era5_monthly_averages_surface_single_level_1979_2024]
50+
git-tree-sha1 = "6cddb07eeee2dd46dc5a19e9b2f706302ddba2c9"
51+
52+
[[era5_monthly_averages_surface_single_level_1979_2024.download]]
53+
sha256 = "46b422722d98c89c6bc0b8641bff259db1caee253f45389ddf9eb9c2d31ed605"
54+
url = "https://caltech.box.com/shared/static/jbgtyt6oq9lxvk8il5zzck6k581q7f3k.gz"

experiments/ClimaEarth/Manifest-v1.11.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.11.8"
44
manifest_format = "2.0"
5-
project_hash = "3fd2c8b8c3ebb502a89202b3f7285e40572f38a0"
5+
project_hash = "c4f04d4e37057155b5f15db984f87880058617e1"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "f7304359109c768cf32dc5fa2d371565bb63b68a"
@@ -453,9 +453,9 @@ version = "0.34.0"
453453

454454
[[deps.ClimaCalibrate]]
455455
deps = ["Dates", "Distributed", "Distributions", "EnsembleKalmanProcesses", "JLD2", "Logging", "Random", "TOML", "YAML"]
456-
git-tree-sha1 = "0d7ff225f8cfe2f6adad34ed7ed6f32438d4a772"
456+
git-tree-sha1 = "a0c8232f78f6136f223629cfc4abf7df5c292374"
457457
uuid = "4347a170-ebd6-470c-89d3-5c705c0cacc2"
458-
version = "0.1.4"
458+
version = "0.2.0"
459459

460460
[deps.ClimaCalibrate.extensions]
461461
CESExt = "CalibrateEmulateSample"

experiments/ClimaEarth/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
3838

3939
[compat]
4040
CUDA = "5"
41-
ClimaCalibrate = "0.1"
41+
ClimaCalibrate = "0.2"
4242
ClimaLand = "1.4"
4343
ClimaOcean = "0.8.6"
4444
ClimaParams = "1.0"

experiments/calibration/README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# ClimaCoupler Calibration Experiments
22

3-
This folder contains a trivial perfect-model calibration of the atmosphere coupled with the bucket model.
4-
The calibration uses 30-day and lat/lon averages of top-of-atmosphere shortwave
5-
radiation to calibrate the `total_solar_irradiance` parameter in a perfect model setting.
6-
The current run script uses the `ClimaCalibrate.SlurmManager` to add Slurm workers
7-
which run each ensemble member in parallel.
83

9-
To run this calibration on a Slurm cluster, ensure that `run_calibration.sh` is
10-
configured for your cluster and run `sbatch run_calibration.sh`. The output will
11-
be generated in `experiments/calibration/output`.
4+
This folder contains pipelines to reproduce coupled calibration experiments.
5+
Each pipeline has its own subfolder:
126

13-
Components:
14-
- run_calibration.sh: SBATCH script used to instantiate the project and run the calibration on a Slurm cluster.
15-
- run_calibration.jl: Julia script for the overall calibration and postprocessing. Contains the expriment configuration, such as ensemble size and number of iterations.
16-
- model_interface.jl: Contains `forward_model`, the function that gets run during calibration. This basically just uses the `setup_run` function.
17-
- model_config.yml: Contains the configuration for the coupler
18-
-
7+
- perfect_model: A trivial perfect-model calibration of the atmosphere coupled
8+
with the bucket model. The calibration uses 30-day and lat/lon averages of
9+
top-of-atmosphere shortwave radiation to calibrate the `total_solar_irradiance`
10+
parameter in a perfect model setting. The current run script uses the
11+
`ClimaCalibrate.SlurmManager` to add Slurm workers which run each ensemble
12+
member in parallel.
13+
- subseasonal: Calibrates the inverse entrainment timescale to ERA5 October monthly surface fluxes and surface temperature from 2018 to 2024.

experiments/calibration/api.jl

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import Dates
2+
3+
"""
4+
struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period}
5+
short_names::Vector{String}
6+
minibatch_size::Int64
7+
n_iterations::Int64
8+
sample_date_ranges::Vector{NTuple{2, DATE}}
9+
extend::EXTEND
10+
spinup::SPINUP
11+
nelements::Tuple{Int64, Int64}
12+
output_dir::String
13+
rng_seed::Int64
14+
end
15+
16+
A configuration struct for keeping track of multiple fields that are of interest
17+
to a user running calibration, or that are needed in multiple places (e.g., for
18+
ensemble members and generating observations).
19+
"""
20+
struct CalibrateConfig{SPINUP <: Dates.Period, EXTEND <: Dates.Period}
21+
"Configuration file to use for ClimaCoupler simulation"
22+
config_file::String
23+
24+
"The short names of the observations used for calibration. The short names
25+
should match the same names used for the diagnostics."
26+
short_names::Vector{String}
27+
28+
"The size of the minibatch for each iteration"
29+
minibatch_size::Int64
30+
31+
"The number of iterations to run the calibration for"
32+
n_iterations::Int64
33+
34+
"The date ranges of the samples for calibration and used to determine the
35+
start and end dates of a simulation for each iteration of calibration"
36+
sample_date_ranges::Vector{NTuple{2, Dates.DateTime}}
37+
38+
"The amount of time to run a simulation after the last date of the
39+
minibatch"
40+
extend::EXTEND
41+
42+
"The amount of time to run a simulation before the first date of the
43+
minibatch"
44+
spinup::SPINUP
45+
46+
"The directory to store the iterations and members of the calibration."
47+
output_dir::String
48+
49+
"An integer value for ensuring calibrations are the same between multiple
50+
calibrations with the same settings"
51+
rng_seed::Int64
52+
end
53+
54+
"""
55+
CalibrateConfig(;
56+
config_file,
57+
short_names,
58+
sample_date_ranges,
59+
extend,
60+
spinup = Dates.Month(3),
61+
minibatch_size,
62+
n_iterations,
63+
output_dir = "calibration/weatherquest",,
64+
rng_seed = 42,
65+
)
66+
67+
Initializes a CalibrateConfig, which is of interest to a user running
68+
calibration or contains values needed in multiple places during calibration.
69+
70+
Keyword arguments
71+
=====================
72+
73+
- `config_file`: Configuration file to use for ClimaCoupler simulation.
74+
75+
- `short_names`: Short names of the observations. The currently supported short
76+
names are `pr`, `tas`, and `mslp`.
77+
78+
- `minibatch_size`: The size of the minibatch for each iteration.
79+
80+
- `n_iterations`: The number of iterations to run the calibration for.
81+
82+
- `sample_date_ranges`: The date ranges for each sample. The dates should be the
83+
same as found in the time series data of the observations.
84+
85+
- `extend`: The amount of time to run the simulation after the end date
86+
determined by `sample_date_ranges`. For seasonal averages, `extend` should be
87+
`Dates.Month(3)` and for monthly averages, `extend` should be
88+
`Dates.Month(1)`.
89+
90+
- `spinup`: The amount of time to run the simulation before the start date
91+
determined by `sample_date_ranges`.
92+
93+
- `nelements`: The resolution of the model. This is also used to determine the
94+
mask of the observations.
95+
96+
- `output_dir`: The location to save the calibration at.
97+
98+
- `rng_seed`: An integer to ensure that calibration runs with the same settings
99+
are the same.
100+
"""
101+
function CalibrateConfig(;
102+
config_file,
103+
short_names,
104+
minibatch_size,
105+
n_iterations,
106+
sample_date_ranges,
107+
extend,
108+
spinup = Dates.Month(3),
109+
output_dir = "calibration/weatherquest",
110+
rng_seed = 42,
111+
)
112+
isempty(short_names) && error("Cannot run calibration with no short names")
113+
isempty(sample_date_ranges) &&
114+
error("Cannot run calibration with no date ranges for the samples")
115+
116+
sample_date_ranges = [
117+
(Dates.DateTime(date_pair[1]), Dates.DateTime(date_pair[2])) for
118+
date_pair in sample_date_ranges
119+
]
120+
121+
for (start_date, stop_date) in sample_date_ranges
122+
start_date <= stop_date || error(
123+
"The start date ($start_date) should be before the stop date ($stop_date)",
124+
)
125+
end
126+
issorted(sample_date_ranges) ||
127+
error("The samples in $sample_date_ranges should be sorted")
128+
129+
minibatch_size > 0 || error("The minibatch size ($minibatch_size) should be positive")
130+
n_iterations > 0 || error("The number of iterations ($n_iterations) should be positive")
131+
132+
num_samples = length(sample_date_ranges)
133+
minibatch_size > num_samples && error(
134+
"The minibatch size is $minibatch_size, but the number of samples is $num_samples",
135+
)
136+
137+
remaining = num_samples % minibatch_size
138+
remaining == 0 || @warn(
139+
"Number of samples is not divisible by the minibatch size; the last $remaining samples may be missing when running the calibration"
140+
)
141+
142+
return CalibrateConfig(
143+
config_file,
144+
short_names,
145+
minibatch_size,
146+
n_iterations,
147+
sample_date_ranges,
148+
extend,
149+
spinup,
150+
output_dir,
151+
rng_seed,
152+
)
153+
154+
end

0 commit comments

Comments
 (0)