Skip to content

Commit 68e41a2

Browse files
juliasloan25kmdeckychnli
authored
Add global P Model runs (#1317)
* global Pmodel * fix bugs * GPU broadcast fix * remove diagnostics from standalone canopy experiments - not used * Fix gpu bug? --------- Co-authored-by: kmdeck <[email protected]> Co-authored-by: Yuchen Li <[email protected]>
1 parent 5433c0d commit 68e41a2

File tree

15 files changed

+568
-255
lines changed

15 files changed

+568
-255
lines changed

.buildkite/longruns_gpu/pipeline.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ steps:
5252
env:
5353
CLIMACOMMS_DEVICE: "CUDA"
5454

55+
- label: ":snow_capped_mountain: Snowy Land + P Model"
56+
command:
57+
- julia --color=yes --project=.buildkite experiments/long_runs/snowy_land_pmodel.jl
58+
artifact_paths:
59+
- "snowy_land_pmodel_longrun_gpu/*png"
60+
- "snowy_land_pmodel_longrun_gpu/*pdf"
61+
agents:
62+
slurm_gpus: 1
63+
slurm_time: 3:00:00
64+
env:
65+
CLIMACOMMS_DEVICE: "CUDA"
66+
5567
- label: ":snow_capped_mountain: Low-Res Snowy Land"
5668
command:
5769
- julia --color=yes --project=.buildkite experiments/long_runs/low_res_snowy_land.jl

.buildkite/pipeline.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,27 @@ steps:
7373

7474
- label: "vaira_test"
7575
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/run_fluxnet.jl US-Var"
76-
artifact_paths: "experiments/integrated/fluxnet/US-Var/out/*pdf"
76+
artifact_paths: "experiments/integrated/fluxnet/US-Var/out/*png"
7777

7878
- label: "ozark_test"
7979
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/run_fluxnet.jl US-MOz"
80-
artifact_paths: "experiments/integrated/fluxnet/US-MOz/out/*pdf"
80+
artifact_paths: "experiments/integrated/fluxnet/US-MOz/out/*png"
8181

8282
- label: "niwot_test"
8383
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/run_fluxnet.jl US-NR1"
84-
artifact_paths: "experiments/integrated/fluxnet/US-NR1/out/*pdf"
84+
artifact_paths: "experiments/integrated/fluxnet/US-NR1/out/*png"
8585

8686
- label: "harvard_test"
8787
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/run_fluxnet.jl US-Ha1"
88-
artifact_paths: "experiments/integrated/fluxnet/US-Ha1/out/*pdf"
88+
artifact_paths: "experiments/integrated/fluxnet/US-Ha1/out/*png"
8989

9090
- label: "ozark_pft"
9191
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/ozark_pft.jl"
92-
artifact_paths: "experiments/integrated/fluxnet/US-MOz/pft/out/*pdf"
92+
artifact_paths: "experiments/integrated/fluxnet/US-MOz/pft/out/*png"
93+
94+
- label: "ozark_pmodel"
95+
command: "julia --color=yes --project=.buildkite experiments/integrated/fluxnet/ozark_pmodel.jl"
96+
artifact_paths: "experiments/integrated/fluxnet/US-MOz/pmodel/out/*png"
9397

9498
- label: "ozark_conservation"
9599
command: "julia --color=yes --project=.buildkite experiments/integrated/performance/conservation/ozark_conservation.jl"
@@ -119,6 +123,16 @@ steps:
119123
slurm_nodes: 1
120124
slurm_mem: 24G
121125

126+
- label: "Global Run + P Model CPU MPI"
127+
command: "srun julia --color=yes --project=.buildkite experiments/integrated/global/global_soil_canopy_pmodel.jl"
128+
artifact_paths: "experiments/integrated/global_pmodel/output_active/*png"
129+
env:
130+
CLIMACOMMS_CONTEXT: "MPI"
131+
agents:
132+
slurm_ntasks_per_node: 4
133+
slurm_nodes: 1
134+
slurm_mem: 24G
135+
122136
- label: "Canopy Implicit Stepping CPU"
123137
command: "julia --color=yes --project=.buildkite experiments/standalone/Vegetation/timestep_test.jl"
124138
artifact_paths: "experiments/standalone/Vegetation/timestep_test/output_active/*"

experiments/integrated/fluxnet/ozark_pft.jl

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ defined by plant functional types instead of fully site-specific parameters.
66
import ClimaLand
77

88
import SciMLBase
9-
import ClimaTimeSteppers as CTS
109
using ClimaCore
1110
import ClimaComms
1211
import ClimaParams as CP
@@ -106,22 +105,8 @@ prognostic_land_components = (:canopy, :soil, :soilco2)
106105

107106
# Set up the timestepping information for the simulation
108107
dt = Float64(450) # 7.5 minutes
109-
N_spinup_days = 15
110-
N_days = N_spinup_days + 340
111-
N_seconds = Float64(N_days * 3600 * 24)
112-
start_date = DateTime(2010) + Hour(time_offset)
113-
end_date = start_date + Day(N_days)
114-
115-
116-
timestepper = CTS.ARS111();
117-
ode_algo = CTS.IMEXAlgorithm(
118-
timestepper,
119-
CTS.NewtonsMethod(
120-
max_iters = 3,
121-
update_j = CTS.UpdateEvery(CTS.NewNewtonIteration),
122-
),
123-
);
124-
108+
(start_date, stop_date) =
109+
FluxnetSimulations.get_data_dates(site_ID, time_offset)
125110
# Define the PFT land cover percentages for the Ozark site. Currently we only
126111
# use the dominant PFT, which for Ozark is deciduous broadleaf temperate trees.
127112
pft_pcts = [
@@ -160,9 +145,6 @@ pft_pcts = [
160145
rooting_depth,
161146
) = FT.(params_from_pfts(pft_pcts))
162147

163-
# For now, replace ac_canopy with larger value in order to increase
164-
# stability of timestepping
165-
ac_canopy = ac_canopy * 3
166148
# This reads in the data from the flux tower site and creates
167149
# the atmospheric and radiative driver structs for the model
168150

@@ -244,9 +226,9 @@ photosynthesis = FarquharModel{FT}(canopy_domain; photosynthesis_parameters)
244226
# Set up plant hydraulics
245227
# Read in LAI from MODIS data
246228
surface_space = land_domain.space.surface;
247-
modis_lai_ncdata_path = ClimaLand.Artifacts.modis_lai_multiyear_paths(
248-
start_date = start_date,
249-
end_date = end_date;
229+
modis_lai_ncdata_path = ClimaLand.Artifacts.modis_lai_multiyear_paths(;
230+
start_date,
231+
end_date = stop_date,
250232
context = ClimaComms.context(surface_space),
251233
);
252234
LAI = ClimaLand.prescribed_lai_modis(
@@ -335,17 +317,17 @@ diags = ClimaLand.default_diagnostics(
335317
## How often we want to update the drivers
336318
## defined in the simulatons file
337319
data_dt = Float64(FluxnetSimulations.get_data_dt(site_ID))
338-
updateat = Array(start_date:Second(data_dt):end_date)
320+
updateat = Array(start_date:Second(data_dt):stop_date)
339321
simulation = LandSimulation(
340322
start_date,
341-
end_date,
323+
stop_date,
342324
dt,
343325
land;
344326
set_ic! = set_ic!,
345327
updateat,
346328
diagnostics = diags,
347329
)
348-
sol = solve!(simulation)
330+
solve!(simulation)
349331

350332
comparison_data = FluxnetSimulations.get_comparison_data(site_ID, time_offset)
351333
savedir =
@@ -357,7 +339,7 @@ LandSimVis.make_diurnal_timeseries(
357339
start_date;
358340
savedir,
359341
short_names = ["gpp", "shf", "lhf", "swu", "lwu"],
360-
spinup_date = start_date + Day(N_spinup_days),
342+
spinup_date = start_date + Day(20),
361343
comparison_data,
362344
)
363345
LandSimVis.make_timeseries(
@@ -366,6 +348,6 @@ LandSimVis.make_timeseries(
366348
start_date;
367349
savedir,
368350
short_names = ["swc", "tsoil"],
369-
spinup_date = start_date + Day(N_spinup_days),
351+
spinup_date = start_date + Day(20),
370352
comparison_data,
371353
)

experiments/integrated/fluxnet/ozark_pmodel.jl

Lines changed: 35 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import SciMLBase
2-
import ClimaTimeSteppers as CTS
32
import ClimaComms
43
ClimaComms.@import_required_backends
54
using ClimaCore
@@ -17,9 +16,9 @@ using ClimaLand.Canopy
1716
using ClimaLand.Canopy.PlantHydraulics
1817
import ClimaLand
1918
import ClimaLand.Parameters as LP
20-
19+
using ClimaLand.Simulations: LandSimulation, solve!
2120
import ClimaLand.FluxnetSimulations as FluxnetSimulations
22-
using CairoMakie, ClimaAnalysis, GeoMakie, Poppler_jll, Printf, StatsBase
21+
using CairoMakie, ClimaAnalysis, GeoMakie, Printf, StatsBase
2322
import ClimaLand.LandSimVis as LandSimVis
2423

2524
const FT = Float64
@@ -94,25 +93,14 @@ land_domain = Column(;
9493
surface_domain = ClimaLand.Domains.obtain_surface_domain(land_domain)
9594

9695
# Set up the timestepping information for the simulation
97-
t0 = Float64(0)
9896
dt = Float64(450) # 7.5 minutes
99-
N_spinup_days = 15
100-
N_days = N_spinup_days + 340
101-
tf = Float64(t0 + N_days * 3600 * 24)
102-
t_spinup = Float64(t0 + N_spinup_days * 3600 * 24)
103-
104-
timestepper = CTS.ARS111();
105-
ode_algo = CTS.IMEXAlgorithm(
106-
timestepper,
107-
CTS.NewtonsMethod(
108-
max_iters = 3,
109-
update_j = CTS.UpdateEvery(CTS.NewNewtonIteration),
110-
),
111-
);
11297

11398
# This reads in the data from the flux tower site and creates
11499
# the atmospheric and radiative driver structs for the model
115-
(start_date, end_date) = FluxnetSimulations.get_data_dates(site_ID, time_offset)
100+
(start_date, stop_date) =
101+
FluxnetSimulations.get_data_dates(site_ID, time_offset)
102+
# This reads in the data from the flux tower site and creates
103+
# the atmospheric and radiative driver structs for the model
116104
(; atmos, radiation) = FluxnetSimulations.prescribed_forcing_fluxnet(
117105
site_ID,
118106
lat,
@@ -193,8 +181,8 @@ photosynthesis = PModel{FT}()
193181
surface_space = land_domain.space.surface;
194182
modis_lai_ncdata_path = ClimaLand.Artifacts.modis_lai_multiyear_paths(;
195183
context = ClimaComms.context(surface_space),
196-
start_date = start_date + Second(t0),
197-
end_date = start_date + Second(t0) + Second(tf),
184+
start_date,
185+
end_date = stop_date,
198186
)
199187
LAI = ClimaLand.prescribed_lai_modis(
200188
modis_lai_ncdata_path,
@@ -255,40 +243,14 @@ snow = Snow.SnowModel(
255243

256244
# Integrated plant hydraulics, soil, and snow model
257245
land = LandModel{FT}(canopy, snow, soil, soilco2);
258-
259-
Y, p, cds = initialize(land);
260-
261-
FluxnetSimulations.set_fluxnet_ic!(Y, site_ID, start_date, time_offset, land)
262-
set_initial_cache! = make_set_initial_cache(land);
263-
set_initial_cache!(p, Y, t0);
264-
265-
exp_tendency! = make_exp_tendency(land);
266-
imp_tendency! = make_imp_tendency(land);
267-
jacobian! = make_jacobian(land);
268-
jac_kwargs =
269-
(; jac_prototype = ClimaLand.FieldMatrixWithSolver(Y), Wfact = jacobian!);
270-
271-
246+
set_ic! = FluxnetSimulations.make_set_fluxnet_initial_conditions(
247+
site_ID,
248+
start_date,
249+
time_offset,
250+
land,
251+
)
272252
# Callbacks
273-
output_vars = [
274-
"sif",
275-
"ra",
276-
"gs",
277-
"gpp",
278-
"ct",
279-
"swu",
280-
"lwu",
281-
"er",
282-
"et",
283-
"msf",
284-
"shf",
285-
"lhf",
286-
"rn",
287-
"swe",
288-
"swc",
289-
"tsoil",
290-
"si",
291-
]
253+
output_vars = ["gpp", "shf", "lhf", "swu", "lwu", "swc", "swe", "tsoil"]
292254
diags = ClimaLand.default_diagnostics(
293255
land,
294256
start_date;
@@ -297,49 +259,35 @@ diags = ClimaLand.default_diagnostics(
297259
average_period = :hourly,
298260
);
299261

300-
diagnostic_handler =
301-
ClimaDiagnostics.DiagnosticsHandler(diags, Y, p, t0, dt = dt);
302-
303-
diag_cb = ClimaDiagnostics.DiagnosticsCallback(diagnostic_handler);
304-
305-
## How often we want to update the drivers. Note that this uses the defined `t0`, and `tf`
306-
## defined in the simulatons file
307-
data_dt = Float64(FluxnetSimulations.get_data_dt(site_ID));
308-
updateat = Array(t0:data_dt:tf);
309-
model_drivers = ClimaLand.get_drivers(land);
310-
updatefunc = ClimaLand.make_update_drivers(model_drivers);
311-
driver_cb = ClimaLand.DriverUpdateCallback(updateat, updatefunc);
312-
313-
# For the P-model, we need to add a callback to check for and update at local noon
314-
pmodel_cb = ClimaLand.make_PModel_callback(FT, start_date, t0, dt, canopy)
315-
316-
cb = SciMLBase.CallbackSet(driver_cb, diag_cb, pmodel_cb);
317-
318-
prob = SciMLBase.ODEProblem(
319-
CTS.ClimaODEFunction(
320-
T_exp! = exp_tendency!,
321-
T_imp! = SciMLBase.ODEFunction(imp_tendency!; jac_kwargs...),
322-
dss! = ClimaLand.dss!,
323-
),
324-
Y,
325-
(t0, tf),
326-
p,
262+
## How often we want to update the drivers.
263+
data_dt = Second(FluxnetSimulations.get_data_dt(site_ID))
264+
updateat = Array(start_date:data_dt:stop_date)
265+
pmodel_cb = ClimaLand.make_PModel_callback(FT, start_date, dt, land.canopy)
266+
simulation = LandSimulation(
267+
start_date,
268+
stop_date,
269+
dt,
270+
land;
271+
user_callbacks = (pmodel_cb,),
272+
set_ic!,
273+
updateat,
274+
diagnostics = diags,
327275
);
276+
@time solve!(simulation)
328277

329-
@time sol = SciMLBase.solve(prob, ode_algo; dt = dt, callback = cb);
330-
331-
ClimaLand.Diagnostics.close_output_writers(diags)
332278
comparison_data = FluxnetSimulations.get_comparison_data(site_ID, time_offset)
333-
savedir =
334-
joinpath(pkgdir(ClimaLand), "experiments/integrated/fluxnet/$(site_ID)/out")
279+
savedir = joinpath(
280+
pkgdir(ClimaLand),
281+
"experiments/integrated/fluxnet/US-MOz/pmodel/out",
282+
)
335283
mkpath(savedir)
336284
LandSimVis.make_diurnal_timeseries(
337285
land_domain,
338286
diags,
339287
start_date;
340288
savedir,
341289
short_names = ["gpp", "shf", "lhf", "swu", "lwu"],
342-
spinup_date = start_date + Day(N_spinup_days),
290+
spinup_date = start_date + Day(20),
343291
comparison_data,
344292
)
345293
LandSimVis.make_timeseries(
@@ -348,6 +296,6 @@ LandSimVis.make_timeseries(
348296
start_date;
349297
savedir,
350298
short_names = ["swc", "tsoil", "swe"],
351-
spinup_date = start_date + Day(N_spinup_days),
299+
spinup_date = start_date + Day(20),
352300
comparison_data,
353301
)

experiments/integrated/fluxnet/ozark_soilsnow.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# Bonan, G. Climate change and terrestrial ecosystem modeling. Cambridge University Press, 2019.
88

99
import SciMLBase
10-
import ClimaTimeSteppers as CTS
1110
import ClimaComms
1211
ClimaComms.@import_required_backends
1312
using ClimaCore
@@ -95,10 +94,11 @@ compartment_surfaces = n_stem > 0 ? [zmax, h_stem, h_canopy] : [zmax, h_leaf]
9594
domain = Column(; zlim = (zmin, zmax), nelements = nelements, dz_tuple)
9695

9796
# Set up the timestepping information for the simulation
98-
start_date = DateTime(2010) + Hour(time_offset)
99-
N_days = 360
100-
end_date = start_date + Day(N_days)
101-
dt = FT(900)
97+
dt = Float64(900)
98+
99+
# This reads in the data from the flux tower site and creates
100+
# the atmospheric and radiative driver structs for the model
101+
(start_date, end_date) = FluxnetSimulations.get_data_dates(site_ID, time_offset)
102102

103103
# Height of sensor on flux tower
104104
atmos_h = FT(32)

0 commit comments

Comments
 (0)