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}:
 "a3c3392 initial setup"
 "278f0df add Project.toml to log"
 "5be02af add Manifest.toml to log"
 "98101ce task started [4d286804-ad66-4b44-8982-a658ee7c77f8]"
 "5133804 (HEAD -> main) task ended   [4d286804-ad66-4b44-8982-a658ee7c77f8]"

or

@ModelRun ClimateModels.RandomWalker
  ID            = e22c3960-7dbe-49d2-a22b-19b272ecaa1a
  model         = RandomWalker
  configuration = anonymous
  run folder    = /tmp/e22c3960-7dbe-49d2-a22b-19b272ecaa1a
  log subfolder = /tmp/e22c3960-7dbe-49d2-a22b-19b272ecaa1a/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            = 2eed6eb1-f146-4869-a722-50058d6f6549
  model         = RandomWalker
  configuration = anonymous
  run folder    = /tmp/2eed6eb1-f146-4869-a722-50058d6f6549
  log subfolder = /tmp/2eed6eb1-f146-4869-a722-50058d6f6549/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/2eed6eb1-f146-4869-a722-50058d6f6549"
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}:
 "410c53e initial setup"
 "8dc8ea3 add Project.toml to log"
 "b035698 add Manifest.toml to log"
 "7a780c8 task started [9f4bc811-ce8a-49a0-a22e-242c96634cbe]"
 "ed2666f (HEAD -> main) task ended   [9f4bc811-ce8a-49a0-a22e-242c96634cbe]"

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}:
 "2f94f43 initial setup"
 "8275efa initial tracked_parameters.toml"
 "d1e8034 add Project.toml to log"
 "72b95cb add Manifest.toml to log"
 "f163b96 task started [6bd88266-f3a8-4654-b214-d7153eebff46]"
 "2b8192e task ended   [6bd88266-f3a8-4654-b214-d7153eebff46]"
 "11f3f95 task started [2851d1e0-3b08-49c9-a4c0-f11d76569226]"
 "4c35453 modify tracked_parameters.toml"
 "e8ac0d1 (HEAD -> main) task ended   [2851d1e0-3b08-49c9-a4c0-f11d76569226]"

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)
7-element Vector{String}:
 "CellOrder.txt"
 "MC.cdf60133-361b-4a30-bb30-57ed10bdfa18"
 "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/e2451d9f-8033-49ac-9f51-978401682fac`
    Updating registry at `~/.julia/registries/General.toml`
   Installed PlutoUI ─ v0.7.60
    Updating `/tmp/e2451d9f-8033-49ac-9f51-978401682fac/Project.toml`
  [7f904dfe] ↑ PlutoUI v0.7.59 ⇒ v0.7.60
    Updating `/tmp/e2451d9f-8033-49ac-9f51-978401682fac/Manifest.toml`
  [35492f91] + AdaptivePredicates v1.1.1
  [67c07d97] ↑ Automa v1.0.3 ⇒ v1.0.4
  [159f3aea] ↑ Cairo v1.0.5 ⇒ v1.1.0
  [49dc2e85] - Calculus v0.5.1
  [944b1d66] ↑ CodecZlib v0.7.4 ⇒ v0.7.6
  [35d6a980] ↑ ColorSchemes v3.25.0 ⇒ v3.26.0
  [34da2185] ↑ Compat v4.15.0 ⇒ v4.16.0
  [187b0558] ↑ ConstructionBase v1.5.5 ⇒ v1.5.8
  [927a84f5] ↑ DelaunayTriangulation v1.0.3 ⇒ v1.3.0
  [31c24e10] ↑ Distributions v0.25.109 ⇒ v0.25.111
  [fa6b7ba4] - DualNumbers v0.6.8
  [411431e0] ↑ Extents v0.1.2 ⇒ v0.1.4
  [48062228] ↑ FilePathsBase v0.9.21 ⇒ v0.9.22
  [1a297f60] ↑ FillArrays v1.11.0 ⇒ v1.13.0
  [68eda718] + GeoFormatTypes v0.4.2
  [cf35fbd7] ↑ GeoInterface v1.3.4 ⇒ v1.3.6
  [34004b35] ↑ HypergeometricFunctions v0.3.23 ⇒ v0.3.24
  [b5f81e59] ↑ IOCapture v0.2.4 ⇒ v0.2.5
  [842dd82b] ↑ InlineStrings v1.4.0 ⇒ v1.4.2
  [d1acc4aa] ↑ IntervalArithmetic v0.22.13 ⇒ v0.22.16
  [692b3bcd] ↑ JLLWrappers v1.5.0 ⇒ v1.6.0
  [6fe1bfb0] ↑ OffsetArrays v1.14.0 ⇒ v1.14.1
  [7f904dfe] ↑ PlutoUI v0.7.59 ⇒ v0.7.60
  [92933f4c] ↑ ProgressMeter v1.10.0 ⇒ v1.10.2
  [43287f4e] ↑ PtrArrays v1.2.0 ⇒ v1.2.1
  [1fd47b50] ↑ QuadGK v2.9.4 ⇒ v2.11.0
  [91c51154] ↑ SentinelArrays v1.4.3 ⇒ v1.4.5
  [90137ffa] ↑ StaticArrays v1.9.4 ⇒ v1.9.7
  [1e83bf80] ↑ StaticArraysCore v1.4.2 ⇒ v1.4.3
  [fd094767] ↑ Suppressor v0.2.7 ⇒ v0.2.8
  [bd369af6] ↑ Tables v1.11.1 ⇒ v1.12.0
  [3bb67fe8] ↑ TranscodingStreams v0.10.9 ⇒ v0.11.2
  [410a4b4d] ↑ Tricks v0.1.8 ⇒ v0.1.9
  [b22a6f82] ↑ FFMPEG_jll v6.1.1+0 ⇒ v6.1.2+0
  [2e76f6c2] ↑ HarfBuzz_jll v2.8.1+1 ⇒ v8.3.1+0
  [1d5cc7b8] ↑ IntelOpenMP_jll v2024.1.0+0 ⇒ v2024.2.1+0
  [1d63c593] ↑ LLVMOpenMP_jll v15.0.7+0 ⇒ v17.0.6+0
  [856f044c] ↑ MKL_jll v2024.1.0+0 ⇒ v2024.2.0+0
  [458c3c95] ↑ OpenSSL_jll v3.0.13+1 ⇒ v3.0.15+0
  [91d4177d] ↑ Opus_jll v1.3.2+0 ⇒ v1.3.3+0
  [36c8627f] ↑ Pango_jll v1.52.2+0 ⇒ v1.54.1+0
⌅ [f50d1b31] ↑ Rmath_jll v0.4.2+0 ⇒ v0.4.3+0
  [02c8fc9c] ↑ XML2_jll v2.12.7+0 ⇒ v2.13.3+0
  [aed1982a] ↑ XSLT_jll v1.1.34+0 ⇒ v1.1.41+0
  [c7cfdc94] ↑ Xorg_libxcb_jll v1.15.0+0 ⇒ v1.17.0+0
  [0ac62f75] ↑ libass_jll v0.15.1+0 ⇒ v0.15.2+0
  [f638f0a6] ↑ libfdk_aac_jll v2.0.2+0 ⇒ v2.0.3+0
  [f27f6e37] ↑ libvorbis_jll v1.3.7+1 ⇒ v1.3.7+2
  [1270edf5] ↑ x264_jll v2021.5.5+0 ⇒ v10164.0.0+0
  [dfaa095f] ↑ x265_jll v3.5.0+0 ⇒ v3.6.0+0
  [8e850b90] ↑ libblastrampoline_jll v5.8.0+1 ⇒ v5.11.0+0
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
Precompiling project...
  ✓ ClimateModels
  ✓ PlutoUI
  ✓ MathTeXEngine
  ✓ GridLayoutBase
  ✓ Makie
  ✓ CairoMakie
  6 dependencies successfully precompiled in 98 seconds. 241 already precompiled.
  5 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions
        Info We haven't cleaned this depot up for a bit, running Pkg.gc()...
      Active manifest files: 3 found
      Active artifact files: 76 found
      Active scratchspaces: 5 found
     Deleted no artifacts, repos, packages or scratchspaces
  Activating project at `~/work/ClimateModels.jl/ClimateModels.jl/docs`
  Activating project at `/tmp/2c9dc60d-8911-490a-954a-66ecff787335`
  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.