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}:
"296dfa2 initial setup"
"439f6f4 add Project.toml to log"
"411fc0e add Manifest.toml to log"
"c3da0f4 task started [6704bb1a-68bd-4ce0-8346-e0c72c02dcb4]"
"7cf77a2 (HEAD -> main) task ended [6704bb1a-68bd-4ce0-8346-e0c72c02dcb4]"
or
@ModelRun ClimateModels.RandomWalker
ID = 13851a02-b90d-4ba9-88d4-73c78d726fa6
model = RandomWalker
configuration = anonymous
run folder = /tmp/13851a02-b90d-4ba9-88d4-73c78d726fa6
log subfolder = /tmp/13851a02-b90d-4ba9-88d4-73c78d726fa6/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 = 4c79ae0b-c356-4db5-9e8c-a7c9bd1d7872
model = RandomWalker
configuration = anonymous
run folder = /tmp/4c79ae0b-c356-4db5-9e8c-a7c9bd1d7872
log subfolder = /tmp/4c79ae0b-c356-4db5-9e8c-a7c9bd1d7872/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.
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/4c79ae0b-c356-4db5-9e8c-a7c9bd1d7872"
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}:
"e165b4a initial setup"
"1a760ac add Project.toml to log"
"eb7114e add Manifest.toml to log"
"d2ffd24 task started [f89f1f2f-6c0f-4f9c-8ea9-ea55e926b335]"
"861993f (HEAD -> main) task ended [f89f1f2f-6c0f-4f9c-8ea9-ea55e926b335]"
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 aString
and the mainFunction
as theconfiguration
, as in CMIP6 - put
model
in a Pluto notebook and ingest it viaPlutoConfig
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.
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 intotracked_parameters.toml
duringsetup
. - Modified parameters are automatically recorded in
tracked_parameters.toml
duringlaunch
. log
called on aModelConfig
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.
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}:
"4ac7465 initial setup"
"e2c70d3 initial tracked_parameters.toml"
"baa67a7 add Project.toml to log"
"a44a5fd add Manifest.toml to log"
"f350eb7 task started [c695abf1-e232-4c24-afd3-4cb776d181a0]"
"5239c20 task ended [c695abf1-e232-4c24-afd3-4cb776d181a0]"
"25153dc task started [c4b1940d-4235-4979-b3a4-2c7bfd644e48]"
"e83686d modify tracked_parameters.toml"
"86f391a (HEAD -> main) task ended [c4b1940d-4235-4979-b3a4-2c7bfd644e48]"
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.acbaa808-01f5-46a0-a26c-5918700a55d9"
"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/fc41f081-f729-4b14-b65d-789c1898205b`
Updating registry at `~/.julia/registries/General.toml`
No Changes to `/tmp/fc41f081-f729-4b14-b65d-789c1898205b/Project.toml`
Updating `/tmp/fc41f081-f729-4b14-b65d-789c1898205b/Manifest.toml`
[0234f1f7] ↑ HDF5_jll v1.14.2+1 ⇒ v1.14.3+1
⌅ [fe0851c0] ↓ OpenMPI_jll v5.0.2+0 ⇒ v4.1.6+0
[32165bc3] - PMIx_jll v4.2.7+0
[1080aeaf] - libevent_jll v2.1.13+1
[eb928a42] - prrte_jll v3.0.2+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
1 dependency successfully precompiled in 2 seconds. 302 already precompiled.
1 dependency precompiled but a different version is currently loaded. Restart julia to access the new version
Info We haven't cleaned this depot up for a bit, running Pkg.gc()...
Active manifest files: 3 found
Active artifact files: 79 found
Active scratchspaces: 4 found
Deleted no artifacts, repos, packages or scratchspaces
Activating project at `~/work/ClimateModels.jl/ClimateModels.jl/docs`
Activating project at `/tmp/687a4e5d-c632-4480-b958-f56a630d63b7`
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"
For more examples with NetCDF.jl and Zarr.jl, please look at IPCC notebook and CMIP6 notebok.