User Manual

Here are key functionalities offered in ClimateModels.jl.

Climate Model Interface

The interface ties the ModelConfig data structure with methods like setup, build, and launch. In return, it provides standard methods to deal with inputs and outputs, as well as capabilities described below.

The ModelRun method, or just run, streamlines the process. It executes all three steps at once (setup, build, and launch). For example, let's use RandomWalker as the model.

fun=ClimateModels.RandomWalker

With the simplified ModelConfig constructors, we can just write any of the following:

ModelRun(ModelConfig(model=fun))

or

MC=run(ModelConfig(fun))
log(MC)
5-element Vector{String}:
 "9964371 initial setup"
 "4377694 add Project.toml to log"
 "154fa37 add Manifest.toml to log"
 "46cbcfd task started [c2e99646-1886-4f5e-94fd-090254bb79ed]"
 "fd8766a (HEAD -> main) task ended   [c2e99646-1886-4f5e-94fd-090254bb79ed]"

or

@ModelRun ClimateModels.RandomWalker
  ID            = 3b6d646d-1df8-4447-9c0c-7567eaf57a7c
  model         = RandomWalker
  configuration = anonymous
  run folder    = /tmp/3b6d646d-1df8-4447-9c0c-7567eaf57a7c
  log subfolder = /tmp/3b6d646d-1df8-4447-9c0c-7567eaf57a7c/log

By design of the ClimateModels interface, it is required that fun receives a ModelConfig as its sole input argument. This requirement is easily satisfied in practice.

Input parameters can be specified via the inputs keyword argument, or via files. See Parameters.

Breaking Things Down

Let's start with defining the model:

MC=ModelConfig(model=fun)
  ID            = 928d81e8-2682-4cf0-9a77-045ff6082cec
  model         = RandomWalker
  configuration = anonymous
  run folder    = /tmp/928d81e8-2682-4cf0-9a77-045ff6082cec
  log subfolder = /tmp/928d81e8-2682-4cf0-9a77-045ff6082cec/log

The sequence of calls within ModelRun is expanded below. In practice, setup typically handles files and software, build gets the model ready, and launch starts the model computation.

setup(MC)
build(MC)
launch(MC)

The model's top level function gets called via launch. In our example, it generates a CSV file found in the run folder as shown below.

Note

It is not required that compilation takes place during build. It can also be done beforehand or within launch.

Sometimes it is convenient to further break down the computational workflow into several tasks. These can be added to the ModelConfig via put! and then executed via launch, as demonstrated in Parameters.

The run folder name and its content can be viewed using pathof and readdir, respectively.

pathof(MC)
"/tmp/928d81e8-2682-4cf0-9a77-045ff6082cec"
readdir(MC)
2-element Vector{String}:
 "RandomWalker.csv"
 "log"

The log subfolder was created earlier by setup. The log function can then retrieve the workflow log.

log(MC)
5-element Vector{String}:
 "6176222 initial setup"
 "a8791cd add Project.toml to log"
 "6851e9f add Manifest.toml to log"
 "ee6eacb task started [bbfd0d76-e897-4c28-94ba-bda29ce06ca3]"
 "13a57df (HEAD -> main) task ended   [bbfd0d76-e897-4c28-94ba-bda29ce06ca3]"

This highlights that Project.toml and Manifest.toml for the environment being used have been archived. This happens during setup to document all dependencies and make the workflow reproducible.

Customization

A key point is that everything can be customized to, e.g., use popular models previously written in Fortran or C just as simply.

Here are simple ways to start usinf the ClimateModels.jl interface with your favorite model.

  • specify model directly as a function, and use defaults for everything else, as illustrated in random walk
  • specify model name as a String and the main Function as the configuration, as in CMIP6
  • put model in a Pluto notebook and ingest it via PlutoConfig as shown below

Sometimes, one may also want to define custom setup, build, or launch methods. To do this, one can define a concrete type of AbstractModelConfig using ModelConfig as a blueprint. This is the recommended approach when other languanges like Fortran or Python are involved (e.g., Hector.

Note

Defining a concrete type of AbstractModelConfig can also be practical with pure Julia model, e.g. to speed up launch, generate ensembles, facilitate checkpointing, etc. That's the case in the Oceananigans.jl example.

For popular models the customized interface elements can be provided via a dedicated package. This may allow them to be maintained independently by developers and users most familiar with each model. MITgcmTools.jl does this for MITgcm. It provides its own suite of examples that use the ClimateModels.jl interface.

Tracked Worklow Support

When creating a ModelConfig, it receives a unique identifier (UUIDs.uuid4()). By default, this identifier is used in the name of the run folder attached to the ModelConfig.

The run folder normally gets created by setup. During this phase, log is used to create a git enabled subfolder called log. This will allow us to record steps in our workflow – again via log.

As shown in the Parameters example:

  • Parameters specified via inputs are automatically recorded into tracked_parameters.toml during setup.
  • Modified parameters are automatically recorded in tracked_parameters.toml during launch.
  • log called on a ModelConfig with no other argument shows the workflow record.

Parameters

Let's now mofdify model parameters, then rerun a model, and keep track of these workflow steps.

After an initial model run of 100 steps, duration NS is extended to 200 time steps. The put! and launch sequence then reruns the model.

Note

The same method can be used to break down a workflow in several steps. Each call to launch sequentially takes the next task from the stack (i.e., channel). Once the task channel is empty then launch does nothing.

mc=ModelConfig(fun,(NS=100,filename="run01.csv"))
run(mc)

mc.inputs[:NS]=200
mc.inputs[:filename]="run02.csv"
put!(mc)
launch(mc)

log(mc)
9-element Vector{String}:
 "a0284d3 initial setup"
 "1f1faf5 initial tracked_parameters.toml"
 "2b49073 add Project.toml to log"
 "8923309 add Manifest.toml to log"
 "7259eb5 task started [1e75a49d-558c-4c50-919e-61504b35f1b8]"
 "f4383cf task ended   [1e75a49d-558c-4c50-919e-61504b35f1b8]"
 "f9a4048 task started [db50a07b-0687-4bbd-86c8-3a352dfd200a]"
 "fdc1f0f modify tracked_parameters.toml"
 "4987016 (HEAD -> main) task ended   [db50a07b-0687-4bbd-86c8-3a352dfd200a]"

The call sequence is readily reflected in the workflow log, and the run folder now has two output files.

readdir(mc)
3-element Vector{String}:
 "log"
 "run01.csv"
 "run02.csv"

In more complex models, there generally is a large number of parameters that are often organized in a collection of text files.

The ClimateModels.jl interface is easily customized to turn those into a tracked_parameters.toml file as demonstrated in the Hector and in the MITgcm.

ClimateModels.jl thus readily enables interacting with parameters and tracking their values even with complex models as highlighted in the JuliaCon 2021 Presentation.

Pluto Notebook Integration

Any Pluto notebook is easily integrated to the ClimateModels.jl framework via PlutoConfig.

filename=joinpath(tempdir(),"notebook.jl")
PC=PlutoConfig(filename,(linked_model="MC",))
run(PC)
readdir(PC)
6-element Vector{String}:
 "CellOrder.txt"
 "Manifest.toml"
 "Project.toml"
 "log"
 "main.jl"
 "stdout.txt"

The Pluto notebook gets split up into main code (1) and environment (2). This approach provides a simple way to go from model documentation, in notebook format, to large simulations run, done in batch mode.

Files get copied into pathof(PC) as before. If notebook.jl contains a ModelConfig, let's call it MC, then the pathof(MC) folder can be linked into pathof(PC) at the end. This feature is controlled by linked_model as illustrated just before. A data input folder can be specified via the data_folder key. This will result in the specified folder getting linked into pathof(PC) before running the notebook.

update provides a simple method for updating notebook dependencies. Such routine maintanance is often followed by rerunning the notebook to detect potential updating issues.

update(PlutoConfig(filename))
run(PlutoConfig(filename))
  Activating project at `/tmp/ced40219-9f2c-430d-93a7-0601a2a56bdb`
    Updating registry at `~/.julia/registries/General.toml`
   Installed ClimateModels ─ v0.3.11
    Updating `/tmp/ced40219-9f2c-430d-93a7-0601a2a56bdb/Project.toml`
  [f6adb021] ↑ ClimateModels v0.3.9 ⇒ v0.3.11
    Updating `/tmp/ced40219-9f2c-430d-93a7-0601a2a56bdb/Manifest.toml`
  [79e6a3ab] ↑ Adapt v4.3.0 ⇒ v4.4.0
  [39de3d68] ↑ AxisArrays v0.4.7 ⇒ v0.4.8
  [179af706] ↑ CFTime v0.2.2 ⇒ v0.2.4
  [0b6fb165] ↑ ChunkCodecCore v0.5.3 ⇒ v1.0.0
  [4c0bbee4] ↑ ChunkCodecLibZlib v0.2.1 ⇒ v1.0.0
  [55437552] ↑ ChunkCodecLibZstd v0.2.1 ⇒ v1.0.0
  [f6adb021] ↑ ClimateModels v0.3.9 ⇒ v0.3.11
  [35d6a980] ↑ ColorSchemes v3.30.0 ⇒ v3.31.0
  [34da2185] ↑ Compat v4.18.0 ⇒ v4.18.1
  [a93c6f00] ↑ DataFrames v1.7.1 ⇒ v1.8.0
  [31c24e10] ↑ Distributions v0.25.120 ⇒ v0.25.122
  [429591f6] ↑ ExactPredicates v2.2.8 ⇒ v2.2.9
  [7a1cc6ca] ↑ FFTW v1.9.0 ⇒ v1.10.0
  [1a297f60] ↑ FillArrays v1.13.0 ⇒ v1.14.0
  [cd3eb016] ↑ HTTP v1.10.17 ⇒ v1.10.19
  [d1acc4aa] ↑ IntervalArithmetic v0.22.36 ⇒ v1.0.0
  [033835bb] ↑ JLD2 v0.6.0 ⇒ v0.6.2
  [e6f89c97] ↑ LoggingExtras v1.1.0 ⇒ v1.2.0
  [08abe8d2] ↑ PrettyTables v2.4.0 ⇒ v3.0.11
  [fdea26ae] ↑ SIMD v3.7.1 ⇒ v3.7.2
  [276daf66] ↑ SpecialFunctions v2.5.1 ⇒ v2.6.1
  [1986cc42] ↑ Unitful v1.24.0 ⇒ v1.25.0
  [f8c6e375] ↑ Git_jll v2.51.0+0 ⇒ v2.51.1+0
  [7746bdde] ↑ Glib_jll v2.84.3+0 ⇒ v2.86.0+0
  [aacddb02] ↑ JpegTurbo_jll v3.1.2+0 ⇒ v3.1.3+0
  [4b2f31a3] ↑ Libmount_jll v2.41.1+0 ⇒ v2.41.2+0
  [89763e89] ↑ Libtiff_jll v4.7.1+0 ⇒ v4.7.2+0
  [38a345b3] ↑ Libuuid_jll v2.41.1+0 ⇒ v2.41.2+0
  [9bd350c2] ↑ OpenSSH_jll v10.0.1+0 ⇒ v10.0.2+0
  [458c3c95] ↑ OpenSSL_jll v3.5.2+0 ⇒ v3.5.4+0
  [36c8627f] ↑ Pango_jll v1.56.3+0 ⇒ v1.56.4+0
Precompiling project...
   4449.4 ms  ✓ ClimateModels
   9032.8 ms  ✓ ClimateModels → ClimateModelsMakieExt
  2 dependencies successfully precompiled in 14 seconds. 318 already precompiled.
  2 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions. Otherwise, loading dependents of these packages may trigger further precompilation to work with the unexpected versions.
        Info We haven't cleaned this depot up for a bit, running Pkg.gc()...
      Active manifest files: 3 found
      Active artifact files: 75 found
      Active scratchspaces: 3 found
     Deleted no artifacts, repos, packages or scratchspaces
  Activating project at `~/work/ClimateModels.jl/ClimateModels.jl/docs`
  Activating project at `/tmp/51da826b-5117-402c-a51a-9223780b8bec`
ERROR: LoadError: UndefVarError: `NS` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] top-level scope
   @ /tmp/51da826b-5117-402c-a51a-9223780b8bec/main.jl:80
in expression starting at /tmp/51da826b-5117-402c-a51a-9223780b8bec/main.jl:79
  Activating project at `~/work/ClimateModels.jl/ClimateModels.jl/docs`

Files and Cloud Support

Numerical model output often gets archived, distributed, and retrieved over the web. Some times, downloading data is most convenient. In other cases, it is preferable to compute in the cloud and just download final results.

ClimateModels.jl has examples for most common file formats. These are handled via Downloads.jl, NetCDF.jl, DataFrames.jl, CSV.jl, and TOML.jl.

fil=joinpath(pathof(mc),"run02.csv")

CSV=ClimateModels.CSV
DataFrame=ClimateModels.DataFrame

CSV.File(fil) |> DataFrame
"200×2 DataFrame"
Note

For more examples with NetCDF.jl and Zarr.jl, please look at IPCC notebook and CMIP6 notebok.