Skip to content

Commit 983de78

Browse files
#3856: Use site-specific lists of recipes in the RTW
Co-authored-by: Emma Hogan <[email protected]>
1 parent 2a6be12 commit 983de78

File tree

8 files changed

+276
-148
lines changed

8 files changed

+276
-148
lines changed

doc/sphinx/source/utils/RTW/add_a_recipe.rst

Lines changed: 101 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,141 @@ How to add a recipe to the |RTW|
33

44
.. include:: common.txt
55

6-
.. note::
7-
Before you follow these steps to add your recipe, you must be able to
8-
successfully run the recipe with the latest version of ESMValTool on the
9-
compute server you use at your site, as detailed by the ``platform`` option
10-
in the ``[[COMPUTE]]`` section in the site-specific ``.cylc`` file in the
11-
``esmvaltool/utils/recipe_test_workflow/site/`` directory.
6+
Overview
7+
--------
128

13-
#. Open a `new ESMValTool issue`_ on GitHub, assign yourself to the issue, and
14-
add the ``Recipe Test Workflow (RTW)`` label to the issue, see
15-
`ESMValTool issue #3663`_ for an example.
9+
To add a recipe to the |RTW| you will:
1610

17-
#. Create a branch.
11+
* Run the recipe at your site
12+
* Note the actual duration and memory usage
13+
* Edit your site's recipe file
14+
* Create the recipe's KGOs
15+
* Request a review
1816

19-
#. Obtain the duration and memory usage of the recipe from the messages printed
20-
to screen, or at the end of the ``run/main_log.txt`` file in the recipe
21-
output directory after running your recipe on the compute cluster you use at
22-
your site; these messages will look something like::
17+
The recipe will then run at your site whenever the |RTW| is run.
2318

24-
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Time for running the recipe was: 0:02:13.334742
25-
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Maximum memory used (estimate): 2.4 GB
26-
[...]
27-
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Run was successful
19+
Preparation
20+
-----------
2821

29-
#. Add the recipe to the ``[task parameters]`` section in the
30-
``esmvaltool/utils/recipe_test_workflow/flow.cylc`` file.
22+
#. Open a `new ESMValTool issue`_ on GitHub. Assign yourself to the issue and
23+
add the ``Recipe Test Workflow (RTW)`` label. `ESMValTool issue #3663`_
24+
provides an example.
3125

32-
.. hint::
33-
If the recipe takes less than 10 minutes to run then it should be added
34-
to the ``fast`` option. Recipes that take longer than ten minutes should
35-
be added to the ``medium`` option.
26+
#. Create a branch.
27+
28+
#. Run the recipe:
29+
30+
* with the latest version of ESMValTool
31+
* on the compute server you use at your site
3632

3733
.. hint::
38-
The line added should follow the format of ``recipe_new_recipe, \``,
39-
unless the line is the last one in the list, in which case the line added
40-
should follow the format of ``recipe_new_recipe``.
41-
42-
#. If the duration of the recipe is larger than the value specified by the
43-
``execution time limit`` option in the ``[[COMPUTE]]`` section in the
44-
aforementioned site-specific ``.cylc`` file, and / or the memory usage of
45-
the recipe is larger than the value specified by the ``--mem`` option in the
46-
``[[[directives]]]`` section in the ``[[COMPUTE]]`` section, add a section
47-
(in alphabetical order) to this file as shown below (round the duration to
48-
the nearest second)::
49-
50-
[[process<fast=recipe_albedolandcover>]]
51-
# Actual: 0m31s, 2.5 GB on 2024-04-08.
52-
execution time limit = PT2M
53-
[[[directives]]]
54-
--mem = 3G
34+
Your compute server is defined in the
35+
``esmvaltool/utils/recipe_test_workflow/site/<site>.cylc`` file as
36+
follows::
37+
38+
[[COMPUTE]]
39+
platform = <your compute server>
40+
41+
#. Obtain the actual duration and memory usage of the recipe. This can be found
42+
either in the message printed to screen, or at the end of the
43+
``run/main_log.txt`` file in the recipe output directory. The relevant lines will
44+
look something like::
45+
46+
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Time for running the recipe was: 0:02:13.334742
47+
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Maximum memory used (estimate): 2.4 GB
48+
[...]
49+
YYYY-MM-DD HH:MM:SS:sss UTC [12345] INFO Run was successful
50+
51+
Adding the recipe
52+
-----------------
53+
54+
#. Add the recipe in alphabetical order to either ``FAST_RECIPES`` or
55+
``MEDIUM_RECIPES`` in the ``<site>-recipes.jinja`` file. It should look
56+
something like::
57+
58+
{
59+
'recipe_path': 'recipe_a_fast_recipe',
60+
'actual': '2m13s, 2.4 GB on YYYY-MM-DD',
61+
'max_time': 'PT3M',
62+
'max_memory': '3G',
63+
}
64+
65+
.. important::
66+
Add the recipe to ``FAST_RECIPES`` if it takes *less* than 10 mins to
67+
run at your site. Add the recipe to ``MEDIUM_RECIPES`` if it takes *more*
68+
than 10 mins.
5569

5670
.. hint::
57-
The ``fast`` key in the example task definition above
58-
(``[[process<fast=recipe_albedolandcover>]]``) should match name of the
59-
option the recipe was added to in the ``[task parameters]`` section in
60-
the ``esmvaltool/utils/recipe_test_workflow/flow.cylc`` file
71+
The :ref:`site/site-recipes.jinja <site_recipes_file>`.
72+
file provides more information.
6173

6274
.. hint::
63-
Set the ``execution time limit`` to 10-20% more than the actual duration.
64-
For actual durations of up to ``1m45s``, set the ``execution time limit``
65-
to ``PT2M`` (2 minutes).
75+
Set the ``max_time`` to 10-20% more than the actual duration. For actual
76+
durations of up to ``1m45s``, set ``max_time`` to ``PT2M`` (2 minutes).
6677

6778
.. hint::
6879
Try not to regularly waste more than 500 MiB in memory usage. Typically,
6980
rounding the actual memory usage up to the nearest integer is acceptable.
7081

71-
#. Stop any running ``recipe_test_workflow`` workflows::
72-
73-
cylc stop recipe_test_workflow/*
82+
Create the |KGOs|
83+
-----------------
7484

7585
#. Run the |RTW|, as detailed in the :ref:`quick_start_guide`; it is expected
7686
that the ``compare`` task will fail.
7787

78-
#. Update the Known Good Outputs (|KGOs|):
88+
.. important::
89+
The ``compare`` task fails because the |KGOs| for the recipe do not yet
90+
exist. This run of the |RTW| will generate the outputs that will be
91+
used as |KGOs|.
7992

80-
* Recursively copy the recipe output directory (i.e.
81-
``recipe_<recipe>_<date>_<time>/``) from the
82-
``${HOME}/cylc-run/recipe_test_workflow/runN/share/cycle/<cycle>/``
83-
directory to your site-specific |KGO| directory, as detailed by the
84-
``KGO_ROOT_PATH`` option in the site-specific ``.conf`` file in the
85-
``esmvaltool/utils/recipe_test_workflow/opt/`` directory::
93+
#. Recursively copy the recipe output directory
94+
``recipe_<recipe>_<date>_<time>/`` to your site-specific |KGO| directory::
8695

87-
cp -r ${HOME}/cylc-run/recipe_test_workflow/runN/share/cycle/<cycle>/recipe_<recipe>_<date>_<time> <KGO_ROOT_PATH>
96+
cp -r ${HOME}/cylc-run/recipe_test_workflow/runN/share/cycle/<cycle>/recipe_<recipe>_<date>_<time> <KGO_ROOT_PATH>
8897

89-
.. note::
90-
Cylc is typically configured such that
91-
``${HOME}/cylc-run/recipe_test_workflow/runN/share`` is a symbolic link
92-
to a share directory located on a scratch disk; the recipe output
93-
directory is not stored in ``${HOME}``.
98+
.. hint::
99+
``<cycle>`` will look something like: ``20250101T0900Z``. The recipe output
100+
directory will look something like: ``recipe_python_20250101_090000``
101+
102+
.. hint::
103+
Find your site specific ``KGO_ROOT_PATH`` in the ``rose-suite-<site>.conf`` file
104+
in the ``esmvaltool/utils/recipe_test_workflow/opt/`` directory.
105+
106+
.. note::
107+
Cylc is typically configured such that
108+
``${HOME}/cylc-run/recipe_test_workflow/runN/share`` is a symbolic link
109+
to a share directory located on a scratch disk; the recipe output
110+
directory is not stored in ``${HOME}``.
94111

95-
* Enable write permissions for all users on the recipe output directory in
96-
your site-specific |KGO| directory::
112+
#. Enable write permissions for all users on the recipe output directory in
113+
your site-specific |KGO| directory::
97114

98-
chmod -R a+w <KGO_ROOT_PATH>/recipe_<recipe>_<date>_<time>
115+
chmod -R a+w <KGO_ROOT_PATH>/recipe_<recipe>_<date>_<time>
99116

100117
#. Stop any running ``recipe_test_workflow`` workflows::
101118

102-
cylc stop recipe_test_workflow/*
119+
cylc stop recipe_test_workflow/*
103120

104121
#. Run the |RTW| again, as detailed in the :ref:`quick_start_guide`; the
105122
``compare`` task should now succeed.
106123

107-
#. Add the recipe to the documentation:
124+
.. important::
125+
Unless you want the |RTW| to continue running every night, repeat the
126+
previous step to stop the workflow.
108127

109-
* Add a URL for the recipe in ``doc/sphinx/source/utils/RTW/common.txt``
110-
under the ``.. Links`` section in alphabetical order (follow the format
111-
``.. _<name>: <URL>``).
128+
Request a review
129+
----------------
112130

113-
* Add the recipe to the list of :ref:`currently_tested_recipes` in
114-
alphabetical order (follow the format ``* `<name>`_``).
131+
#. Commit and push your changes.
115132

116-
#. Commit and push your changes, create a PR, assign yourself to the PR, and
117-
add the ``Recipe Test Workflow (RTW)`` label to the PR, see
133+
#. Create a PR. Assign yourself to the PR, and add the
134+
``Recipe Test Workflow (RTW)`` label to the PR. Refer to
118135
`ESMValTool PR #3664`_ for an example.
136+
137+
.. note::
138+
Reviewers will automatically be assigned to your PR.
139+
140+
Congratulations!
141+
----------------
142+
143+
The recipe will now run at your site whenever the RTW is run.

doc/sphinx/source/utils/RTW/common.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@
1414

1515
.. Links
1616

17-
.. _Autoassess landsurface soilmoisture: https://docs.esmvaltool.org/en/latest/recipes/recipe_autoassess_landsurface_soilmoisture.html#available-recipes-and-diagnostics
18-
.. _Consecutive dry days: https://docs.esmvaltool.org/en/latest/recipes/recipe_consecdrydays.html
1917
.. _CMIP Documentation: https://www.wcrp-climate.org/wgcm-cmip
2018
.. _Cylc Documentation: https://cylc.github.io/cylc-doc/stable/html/index.html
19+
.. _Cylc ISO8601 Durations: https://cylc.github.io/cylc-doc/stable/html/tutorial/scheduling/datetime-cycling.html#iso8601-durations
20+
.. _Cylc Jinja2: https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/jinja2.html
2121
.. _Cylc Review: https://cylc.github.io/cylc-doc/7.9.3/html/tutorial.html#viewing-suite-logs-in-a-web-browser-cylc-review
22-
.. _Ensclus: https://docs.esmvaltool.org/en/latest/recipes/recipe_ensclus.html
2322
.. _ESMValTool Documentation: https://esmvaltool.org/
2423
.. _ESMValTool issue #3663: https://github.com/ESMValGroup/ESMValTool/issues/3663
2524
.. _ESMValTool PR #3664: https://github.com/ESMValGroup/ESMValTool/pull/3664
26-
.. _Examples python: https://docs.esmvaltool.org/en/latest/recipes/recipe_examples.html
27-
.. _Heatwaves coldwaves: https://docs.esmvaltool.org/en/latest/recipes/recipe_heatwaves_coldwaves.html
28-
.. _Landcover - Albedo: https://docs.esmvaltool.org/en/latest/recipes/recipe_albedolandcover.html#landcover-albedo
25+
.. _Jinja2: https://jinja.palletsprojects.com/en/stable/
2926
.. _new ESMValTool issue: https://github.com/ESMValGroup/ESMValTool/issues/new
30-
.. _Ocean Atlantic Meridional Overturning Circulation (AMOC): https://docs.esmvaltool.org/en/latest/recipes/recipe_oceans.html#recipe-ocean-amoc-yml
31-
.. _Ocean multimap: https://docs.esmvaltool.org/en/latest/recipes/recipe_oceans.html#recipe-ocean-multimap-yml
32-
.. _Radiation budget: https://docs.esmvaltool.org/en/latest/recipes/recipe_radiation_budget.html
3327
.. _Rose Documentation: https://metomi.github.io/rose/doc/html/index.html
28+
.. _metoffice-recipes.cylc: https://github.com/ESMValGroup/ESMValTool/blob/main/esmvaltool/utils/recipe_test_workflow/site/metoffice-recipes.cylc
29+
.. _Slurm sbatch --mem: https://slurm.schedmd.com/sbatch.html#OPT_mem

doc/sphinx/source/utils/RTW/tested_recipes.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ Currently tested recipes
66

77
.. include:: common.txt
88

9-
The following currently tested recipes are available in the |RTW|:
9+
The recipes tested with the |RTW| at each site are defined in the following
10+
files:
1011

11-
* `Autoassess landsurface soilmoisture`_
12-
* `Consecutive dry days`_
13-
* `Ensclus`_
14-
* `Examples python`_
15-
* `Heatwaves coldwaves`_
16-
* `Landcover - Albedo`_
17-
* `Ocean Atlantic Meridional Overturning Circulation (AMOC)`_
18-
* `Ocean multimap`_
19-
* `Radiation budget`_
12+
* `metoffice-recipes.cylc`_
13+
* dkrz-recipes.cylc **(COMING SOON!)**
14+
* jasmin-recipes.cylc **(COMING SOON!)**
15+
16+
.. hint::
17+
The :ref:`site/site-recipes.jinja <site_recipes_file>`.
18+
file provides more information.

doc/sphinx/source/utils/RTW/user_guide/workflow.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ Portability
7474
The |RTW| is portable; site-specific information can be found in the ``site``
7575
and ``opt`` directories within the |RTW|. The files required are:
7676

77+
.. _site_recipes_file:
78+
79+
``site/<site>-recipes.jinja``
80+
Contains all the recipes run at the ``SITE``
81+
82+
.. hint::
83+
* The file uses the `Jinja2`_ templating language, which has a similar syntax
84+
to Python
85+
* Jinja2 gives |Cylc| many powerful features. Refer to `Cylc Jinja2`_ for
86+
more information
87+
7788
``site/<site>.cylc``
7889
Contains task definitions specific to the ``SITE``, for example, ``COMPUTE``
7990

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Module for custom Jinja2 Tests.
3+
4+
In Jinja2 "tests" are used to test a variable against an expression.
5+
Refer to Jinja2 tests:
6+
https://jinja.palletsprojects.com/en/stable/templates/#tests
7+
8+
Jinja2 has a number of Builtin tests:
9+
https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-tests
10+
11+
Jinja2 also allows for writing custom tests in Python:
12+
https://jinja.palletsprojects.com/en/stable/api/#custom-tests
13+
14+
Cylc supports custom filters, tests and globals as described here:
15+
https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/jinja2.html#custom-jinja2-filters-tests-and-globals
16+
17+
"""
18+
from pathlib import Path
19+
20+
21+
def file_exists(file_path):
22+
"""
23+
Test if a file exists.
24+
25+
Parameters
26+
----------
27+
file_path : str
28+
A file path.
29+
30+
Returns
31+
-------
32+
bool
33+
Returns True if the file exists.
34+
"""
35+
run_directory = Path.cwd()
36+
site_recipes_file_path = run_directory / file_path
37+
return site_recipes_file_path.is_file()

0 commit comments

Comments
 (0)