Skip to content

Commit 5cfbc57

Browse files
committed
use ClimaUtilities CallbackManager
1 parent e078085 commit 5cfbc57

17 files changed

+82
-473
lines changed

docs/make.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ interface_pages = [
6565
"interfacer.md",
6666
"postprocessor.md",
6767
"regridder.md",
68-
"timemanager.md",
6968
"utilities.md",
7069
]
7170
performance_pages = ["performance.md"]

docs/src/timemanager.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

experiments/ClimaEarth/run_amip.jl

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,12 @@ import ClimaCore as CC
4848
# ## Coupler specific imports
4949
import ClimaCoupler
5050
import ClimaCoupler:
51-
ConservationChecker,
52-
Checkpointer,
53-
Diagnostics,
54-
FieldExchanger,
55-
FluxCalculator,
56-
Interfacer,
57-
Regridder,
58-
TimeManager,
59-
Utilities
51+
ConservationChecker, Checkpointer, Diagnostics, FieldExchanger, FluxCalculator, Interfacer, Regridder, Utilities
6052

6153
import ClimaUtilities.SpaceVaryingInputs: SpaceVaryingInput
6254
import ClimaUtilities.TimeVaryingInputs: TimeVaryingInput, evaluate!
6355
import ClimaUtilities.ClimaArtifacts: @clima_artifact
56+
import ClimaUtilities: CallbackManager
6457
import Interpolations
6558

6659
pkg_dir = pkgdir(ClimaCoupler)
@@ -472,7 +465,7 @@ if use_coupler_diagnostics
472465
monthly_3d_diags = Diagnostics.init_diagnostics(
473466
(:T, :u, :q_tot, :q_liq_ice),
474467
atmos_sim.domain.center_space;
475-
save = TimeManager.Monthly(),
468+
save = CallbackManager.Monthly(),
476469
operations = (; accumulate = Diagnostics.TimeMean([Int(0)])),
477470
output_dir = dir_paths.output,
478471
name_tag = "monthly_mean_3d_",
@@ -481,7 +474,7 @@ if use_coupler_diagnostics
481474
monthly_2d_diags = Diagnostics.init_diagnostics(
482475
(:precipitation_rate, :toa_fluxes, :T_sfc, :turbulent_energy_fluxes),
483476
boundary_space;
484-
save = TimeManager.Monthly(),
477+
save = CallbackManager.Monthly(),
485478
operations = (; accumulate = Diagnostics.TimeMean([Int(0)])),
486479
output_dir = dir_paths.output,
487480
name_tag = "monthly_mean_2d_",
@@ -530,20 +523,20 @@ The currently implemented callbacks are:
530523
NB: Eventually, we will call all of radiation from the coupler, in addition to the albedo calculation.
531524
=#
532525

533-
checkpoint_cb = TimeManager.HourlyCallback(
526+
checkpoint_cb = CallbackManager.HourlyCallback(
534527
dt = hourly_checkpoint_dt,
535528
func = checkpoint_sims,
536529
ref_date = [dates.date[1]],
537530
active = hourly_checkpoint,
538531
) # 20 days
539-
update_firstdayofmonth!_cb = TimeManager.MonthlyCallback(
532+
update_firstdayofmonth!_cb = CallbackManager.MonthlyCallback(
540533
dt = FT(1),
541-
func = TimeManager.update_firstdayofmonth!,
534+
func = CallbackManager.update_firstdayofmonth!,
542535
ref_date = [dates.date1[1]],
543536
active = true,
544537
)
545538
dt_water_albedo = parse(FT, filter(x -> !occursin(x, "hours"), dt_rad))
546-
albedo_cb = TimeManager.HourlyCallback(
539+
albedo_cb = CallbackManager.HourlyCallback(
547540
dt = dt_water_albedo,
548541
func = FluxCalculator.water_albedo_from_atmosphere!,
549542
ref_date = [dates.date[1]],
@@ -683,7 +676,7 @@ function solve_coupler!(cs)
683676
## step in time
684677
for t in ((tspan[begin] + Δt_cpl):Δt_cpl:tspan[end])
685678

686-
cs.dates.date[1] = TimeManager.current_date(cs, t)
679+
cs.dates.date[1] = Interfacer.current_date(cs, t)
687680

688681
## print date on the first of month
689682
if cs.dates.date[1] >= cs.dates.date1[1]
@@ -717,7 +710,7 @@ function solve_coupler!(cs)
717710

718711
## update water albedo from wind at dt_water_albedo
719712
## (this will be extended to a radiation callback from the coupler)
720-
TimeManager.trigger_callback!(cs, cs.callbacks.water_albedo)
713+
CallbackManager.trigger_callback(cs, cs.callbacks.water_albedo)
721714

722715

723716
## update the surface fractions for surface models,
@@ -752,10 +745,10 @@ function solve_coupler!(cs)
752745
FieldExchanger.import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) # radiative and/or turbulent
753746

754747
## callback to update the fist day of month if needed
755-
TimeManager.trigger_callback!(cs, cs.callbacks.update_firstdayofmonth!)
748+
CallbackManager.trigger_callback(cs, cs.callbacks.update_firstdayofmonth!)
756749

757750
## callback to checkpoint model state
758-
TimeManager.trigger_callback!(cs, cs.callbacks.checkpoint)
751+
CallbackManager.trigger_callback(cs, cs.callbacks.checkpoint)
759752
end
760753
return nothing
761754
end

experiments/ClimaEarth/run_cloudless_aquaplanet.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import ClimaCoupler:
3232
FluxCalculator,
3333
Interfacer,
3434
Regridder,
35-
TimeManager,
35+
CallbackManager,
3636
Utilities
3737

3838
pkg_dir = pkgdir(ClimaCoupler)
@@ -217,20 +217,20 @@ dates = (; date = [date], date0 = [date0], date1 = [Dates.firstdayofmonth(date0)
217217
## Initialize Callbacks
218218
=#
219219

220-
checkpoint_cb = TimeManager.HourlyCallback(
220+
checkpoint_cb = CallbackManager.HourlyCallback(
221221
dt = FT(480),
222222
func = checkpoint_sims,
223223
ref_date = [dates.date[1]],
224224
active = hourly_checkpoint,
225225
) # 20 days
226-
update_firstdayofmonth!_cb = TimeManager.MonthlyCallback(
226+
update_firstdayofmonth!_cb = CallbackManager.MonthlyCallback(
227227
dt = FT(1),
228-
func = TimeManager.update_firstdayofmonth!,
228+
func = CallbackManager.update_firstdayofmonth!,
229229
ref_date = [dates.date1[1]],
230230
active = true,
231231
)
232232
dt_water_albedo = parse(FT, filter(x -> !occursin(x, "hours"), dt_rad))
233-
albedo_cb = TimeManager.HourlyCallback(
233+
albedo_cb = CallbackManager.HourlyCallback(
234234
dt = dt_water_albedo,
235235
func = FluxCalculator.water_albedo_from_atmosphere!,
236236
ref_date = [dates.date[1]],
@@ -325,7 +325,7 @@ function solve_coupler!(cs)
325325
## step in time
326326
for t in ((tspan[begin] + Δt_cpl):Δt_cpl:tspan[end])
327327

328-
cs.dates.date[1] = TimeManager.current_date(cs, t)
328+
cs.dates.date[1] = Interfacer.current_date(cs, t)
329329

330330
## print date on the first of month
331331
if cs.dates.date[1] >= cs.dates.date1[1]
@@ -335,7 +335,7 @@ function solve_coupler!(cs)
335335
ClimaComms.barrier(comms_ctx)
336336

337337
## update water albedo from wind at dt_water_albedo (this will be extended to a radiation callback from the coupler)
338-
TimeManager.trigger_callback!(cs, cs.callbacks.water_albedo)
338+
CallbackManager.trigger_callback(cs, cs.callbacks.water_albedo)
339339

340340
## run component models sequentially for one coupling timestep (Δt_cpl)
341341
FieldExchanger.update_model_sims!(cs.model_sims, cs.fields, cs.turbulent_fluxes)
@@ -350,10 +350,10 @@ function solve_coupler!(cs)
350350
FieldExchanger.import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) # radiative and/or turbulent
351351

352352
## callback to update the fist day of month if needed
353-
TimeManager.trigger_callback!(cs, cs.callbacks.update_firstdayofmonth!)
353+
CallbackManager.trigger_callback(cs, cs.callbacks.update_firstdayofmonth!)
354354

355355
## callback to checkpoint model state
356-
TimeManager.trigger_callback!(cs, cs.callbacks.checkpoint)
356+
CallbackManager.trigger_callback(cs, cs.callbacks.checkpoint)
357357

358358
end
359359

experiments/ClimaEarth/run_cloudy_aquaplanet.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import ClimaCoupler:
3232
FluxCalculator,
3333
Interfacer,
3434
Regridder,
35-
TimeManager,
35+
CallbackManager,
3636
Utilities
3737

3838
pkg_dir = pkgdir(ClimaCoupler)
@@ -238,15 +238,15 @@ dates = (; date = [date], date0 = [date0], date1 = [Dates.firstdayofmonth(date0)
238238
## Initialize Callbacks
239239
=#
240240

241-
checkpoint_cb = TimeManager.HourlyCallback(
241+
checkpoint_cb = CallbackManager.HourlyCallback(
242242
dt = FT(480),
243243
func = checkpoint_sims,
244244
ref_date = [dates.date[1]],
245245
active = hourly_checkpoint,
246246
) # 20 days
247-
update_firstdayofmonth!_cb = TimeManager.MonthlyCallback(
247+
update_firstdayofmonth!_cb = CallbackManager.MonthlyCallback(
248248
dt = FT(1),
249-
func = TimeManager.update_firstdayofmonth!,
249+
func = CallbackManager.update_firstdayofmonth!,
250250
ref_date = [dates.date1[1]],
251251
active = true,
252252
)
@@ -337,7 +337,7 @@ function solve_coupler!(cs)
337337
## step in time
338338
for t in ((tspan[begin] + Δt_cpl):Δt_cpl:tspan[end])
339339

340-
cs.dates.date[1] = TimeManager.current_date(cs, t)
340+
cs.dates.date[1] = Interfacer.current_date(cs, t)
341341

342342
## print date on the first of month
343343
if cs.dates.date[1] >= cs.dates.date1[1]
@@ -359,10 +359,10 @@ function solve_coupler!(cs)
359359
FieldExchanger.import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) # radiative and/or turbulent
360360

361361
## callback to update the fist day of month if needed
362-
TimeManager.trigger_callback!(cs, cs.callbacks.update_firstdayofmonth!)
362+
CallbackManager.trigger_callback(cs, cs.callbacks.update_firstdayofmonth!)
363363

364364
## callback to checkpoint model state
365-
TimeManager.trigger_callback!(cs, cs.callbacks.checkpoint)
365+
CallbackManager.trigger_callback(cs, cs.callbacks.checkpoint)
366366

367367
end
368368

experiments/ClimaEarth/run_cloudy_slabplanet.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import ClimaCoupler:
3232
FluxCalculator,
3333
Interfacer,
3434
Regridder,
35-
TimeManager,
35+
CallbackManager,
3636
Utilities
3737

3838
pkg_dir = pkgdir(ClimaCoupler)
@@ -284,20 +284,20 @@ model_sims = (atmos_sim = atmos_sim, ocean_sim = ocean_sim);
284284
## Initialize Callbacks
285285
=#
286286

287-
checkpoint_cb = TimeManager.HourlyCallback(
287+
checkpoint_cb = CallbackManager.HourlyCallback(
288288
dt = FT(480),
289289
func = checkpoint_sims,
290290
ref_date = [dates.date[1]],
291291
active = hourly_checkpoint,
292292
) # 20 days
293-
update_firstdayofmonth!_cb = TimeManager.MonthlyCallback(
293+
update_firstdayofmonth!_cb = CallbackManager.MonthlyCallback(
294294
dt = FT(1),
295-
func = TimeManager.update_firstdayofmonth!,
295+
func = CallbackManager.update_firstdayofmonth!,
296296
ref_date = [dates.date1[1]],
297297
active = true,
298298
)
299299
dt_water_albedo = parse(FT, filter(x -> !occursin(x, "hours"), dt_rad))
300-
albedo_cb = TimeManager.HourlyCallback(
300+
albedo_cb = CallbackManager.HourlyCallback(
301301
dt = dt_water_albedo,
302302
func = FluxCalculator.water_albedo_from_atmosphere!,
303303
ref_date = [dates.date[1]],
@@ -389,7 +389,7 @@ function solve_coupler!(cs)
389389
## step in time
390390
for t in ((tspan[begin] + Δt_cpl):Δt_cpl:tspan[end])
391391

392-
cs.dates.date[1] = TimeManager.current_date(cs, t)
392+
cs.dates.date[1] = Interfacer.current_date(cs, t)
393393

394394
## print date on the first of month
395395
if cs.dates.date[1] >= cs.dates.date1[1]
@@ -399,7 +399,7 @@ function solve_coupler!(cs)
399399
ClimaComms.barrier(comms_ctx)
400400

401401
## update water albedo from wind at dt_water_albedo (this will be extended to a radiation callback from the coupler)
402-
TimeManager.trigger_callback!(cs, cs.callbacks.water_albedo)
402+
CallbackManager.trigger_callback(cs, cs.callbacks.water_albedo)
403403

404404
## run component models sequentially for one coupling timestep (Δt_cpl)
405405
FieldExchanger.update_model_sims!(cs.model_sims, cs.fields, cs.turbulent_fluxes)
@@ -414,10 +414,10 @@ function solve_coupler!(cs)
414414
FieldExchanger.import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) # radiative and/or turbulent
415415

416416
## callback to update the fist day of month if needed
417-
TimeManager.trigger_callback!(cs, cs.callbacks.update_firstdayofmonth!)
417+
CallbackManager.trigger_callback(cs, cs.callbacks.update_firstdayofmonth!)
418418

419419
## callback to checkpoint model state
420-
TimeManager.trigger_callback!(cs, cs.callbacks.checkpoint)
420+
CallbackManager.trigger_callback(cs, cs.callbacks.checkpoint)
421421

422422
end
423423

experiments/ClimaEarth/run_dry_held_suarez.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import ClimaCore
2626

2727
## Coupler specific imports
2828
import ClimaCoupler
29-
import ClimaCoupler: Checkpointer, FieldExchanger, Interfacer, TimeManager, Utilities
29+
import ClimaCoupler: Checkpointer, FieldExchanger, Interfacer, CallbackManager, Utilities
3030

3131
pkg_dir = pkgdir(ClimaCoupler)
3232

@@ -179,15 +179,15 @@ dates = (; date = [date], date0 = [date0], date1 = [Dates.firstdayofmonth(date0)
179179
#=
180180
## Initialize Callbacks
181181
=#
182-
checkpoint_cb = TimeManager.HourlyCallback(
182+
checkpoint_cb = CallbackManager.HourlyCallback(
183183
dt = FT(480),
184184
func = checkpoint_sims,
185185
ref_date = [dates.date[1]],
186186
active = hourly_checkpoint,
187187
) # 20 days TODO: not GPU friendly
188-
update_firstdayofmonth!_cb = TimeManager.MonthlyCallback(
188+
update_firstdayofmonth!_cb = CallbackManager.MonthlyCallback(
189189
dt = FT(1),
190-
func = TimeManager.update_firstdayofmonth!,
190+
func = CallbackManager.update_firstdayofmonth!,
191191
ref_date = [dates.date1[1]],
192192
active = true,
193193
)
@@ -237,7 +237,7 @@ function solve_coupler!(cs)
237237
## step in time
238238
walltime = @elapsed for t in ((tspan[begin] + Δt_cpl):Δt_cpl:tspan[end])
239239

240-
cs.dates.date[1] = TimeManager.current_date(cs, t)
240+
cs.dates.date[1] = Interfacer.current_date(cs, t)
241241

242242
## print date on the first of month
243243
if cs.dates.date[1] >= cs.dates.date1[1]
@@ -250,10 +250,10 @@ function solve_coupler!(cs)
250250
FieldExchanger.import_atmos_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) # radiative and/or turbulent
251251

252252
## callback to update the fist day of month if needed
253-
TimeManager.trigger_callback!(cs, cs.callbacks.update_firstdayofmonth!)
253+
CallbackManager.trigger_callback(cs, cs.callbacks.update_firstdayofmonth!)
254254

255255
## callback to checkpoint model state
256-
TimeManager.trigger_callback!(cs, cs.callbacks.checkpoint)
256+
CallbackManager.trigger_callback(cs, cs.callbacks.checkpoint)
257257

258258
end
259259
ClimaComms.iamroot(comms_ctx) ? @show(walltime) : nothing

0 commit comments

Comments
 (0)