Utilities
This module contains functions, objects, and constants used by various modules in the coupler.
Utilities API
ClimaCoupler.Utilities.swap_space!
— Functionswap_space!(space_out::CC.Spaces.AbstractSpace, field_in::CC.Fields.Field)
Remap the values of a field onto a new space.
Arguments
space_out
: [CC.Spaces.AbstractSpace] The axes of the space we want to remap ontofield_in
: [CC.Fields.Field] to be remapped to new space.
ClimaCoupler.Utilities.get_comms_context
— Functionget_comms_context(config_dict)
Sets up the appropriate ClimaComms context for the device the model is to be run on, choosing from the following options: - CPU single threaded - CPU with MPI - GPU
If no device is passed to ClimaComms.context()
then ClimaComms
automatically selects the device from which this code is called.
Arguments
config_dict
: dictionary containing a "device" flag which decides which device context is needed
ClimaCoupler.Utilities.get_device
— Functionget_device(config_dict)
Returns the device on which the model is being run
Arguments
config_dict
: dictionary containing a "device" flag which decides which device to run on
ClimaCoupler.Utilities.show_memory_usage
— Functionshow_memory_usage()
Display and return the maximum resident set size (RSS) memory footprint on the CPU of this process since it began.
ClimaCoupler.Utilities.setup_output_dirs
— Functionsetup_output_dirs(output_dir = pwd(),
artifacts_dir = joinpath(output_dir, "artifacts"),
checkpoints_dir = joinpath(output_dir, "checkpoints"),
regrid_dir = nothing,
comms_ctx,
)
Create output directories for the experiment. If comms_ctx
is provided, only the root process will create the directories. By default, the artifacts and checkpoints directories are created inside the output directory with the names artifacts/
and checkpoints/
. The regrid directory is by default created as a temporary directory inside the output directory and is automatically deleted when the process exits.
ClimaUtilities.OutputPathGenerator
is used so that simulations can be re-run and re-started. The output path looks like:
coupler_output_dir_amip/
├── checkpoints
│ └── checkpoints for the various models
├── artifacts
│ └── plots produced by the postporcessing step
├── regrid_tmp_<random_tempdir>/
│ └── temporary files used for regridding
├── output_0000/
│ ├── atmos/
│ │ └── output of the atmos model
│ └── ocean/
│ └── output of the ocean model
├── output_0001/
│ └── ... component model outputs in their folders ...
├── output_0002/
│ └── ... component model outputs in their folders ...
└── output_active -> output_0002/
Arguments
output_dir::String
: The directory where the output files will be stored. Default is the current directory.regrid_dir::String
: The directory where the regridded files will be stored. Default isoutput_dir/regrid_tmp_<random_tempdir>/
.checkpoint_dir::String
: The directory where the checkpoint files will be stored. Default isoutput_dir/checkpoints/
.artifacts_dir::String
: The directory where the artifacts will be stored. Default isoutput_dir/artifacts/
.comms_ctx::Union{Nothing, ClimaComms.AbstractCommsContext}
: The communicator context. If provided, only the root process will create the directories.
Returns
- A tuple with the paths to the output, artifacts, regrid, and checkpoints directories.
ClimaCoupler.Utilities.time_to_seconds
— Functiontime_to_seconds(s::String)
Convert a string to seconds. The string should be in the format numberunit
, where unit
is one of secs
, mins
, hours
, or days
.
Arguments
s::String
: The string to convert to seconds.
Returns
- The number of seconds represented by the string.