diff --git a/esmvaltool/utils/recipe_run_workflow/recipe_run_workflow/site/metoffice-env b/esmvaltool/utils/recipe_run_workflow/recipe_run_workflow/site/metoffice-env new file mode 100644 index 00000000000..34a7ad9b6fd --- /dev/null +++ b/esmvaltool/utils/recipe_run_workflow/recipe_run_workflow/site/metoffice-env @@ -0,0 +1,55 @@ +#!/bin/bash -l +# +# Usage metoffice-env COMMAND +# +# ENVIRONMENT +# MODULE_NAME The name of the module to load +# PYTHONPATH_PREPEND The path to prepend to PYTHONPATH after loading the +# module +# QUIET_MODE Don't print confirmation messages +# +# OPTIONS +# COMMAND The command to execute with options +set -eu + +module_count(){ + module list -t 2>&1 | wc -l +} + +safe_load(){ + PRE_LOAD_COUNT=$(module_count) + + module load "${1}" + # Check module count to determine whether module load was successful. + if (( PRE_LOAD_COUNT == $(module_count) )); then + echo "[ERROR] Failed to load: ${1}" + exit 1 + fi +} + +# Must be run before importing numpy, see +# https://www-avd/sci/dask_best_practice/numpy-threads.html. +export OMP_NUM_THREADS=1 +export OPENBLAS_NUM_THREADS=1 +export MKL_NUM_THREADS=1 +export VECLIB_MAXIMUM_THREADS=1 +export NUMEXPR_NUM_THREADS=1 + +# Ensure '~/.local' isn't added to 'sys.path'. +export PYTHONNOUSERSITE=True + +safe_load "${MODULE_NAME}" + +# If PYTHONPATH_PREPEND has been set, prepend it to PYTHONPATH to extend the +# Python environment. +if [[ ! -z ${PYTHONPATH_PREPEND:-} ]]; then + echo "[INFO] Prepending the following to PYTHONPATH: ${PYTHONPATH_PREPEND}" + export PYTHONPATH=${PYTHONPATH_PREPEND}:${PYTHONPATH:-} +fi + +if [[ -z ${QUIET_MODE:-} ]]; then + echo "[OK] Modules loaded." +fi + +command="/usr/bin/time -v -o ${CYLC_TASK_LOG_ROOT}.time $@" +exec ${command} diff --git a/esmvaltool/utils/recipe_run_workflow/recipe_run_workflow/site/metoffice.cylc b/esmvaltool/utils/recipe_run_workflow/recipe_run_workflow/site/metoffice.cylc new file mode 100644 index 00000000000..e69de29bb2d