Skip to content

Commit ee96424

Browse files
committed
Update docs to include cached outputs
1 parent 10017b3 commit ee96424

File tree

4 files changed

+173
-7
lines changed

4 files changed

+173
-7
lines changed

docs/developers_guide/api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ run
9090
run_step
9191

9292

93+
cache
94+
~~~~~
95+
96+
.. currentmodule:: compass.cache
97+
98+
.. autosummary::
99+
:toctree: generated/
100+
101+
update_cache
102+
103+
93104
Base Classes
94105
^^^^^^^^^^^^
95106

docs/developers_guide/command_line.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,57 @@ Would both accomplish the same thing in this example -- skipping the
276276
over the config option.
277277

278278
See :ref:`dev_run` for more about the underlying framework.
279+
280+
.. _dev_compass_cache:
281+
282+
compass cache
283+
-------------
284+
285+
``compass`` supports caching outputs from any step in a special database
286+
called ``compass_cache`` (see :ref:`dev_step_input_download`). Files in this
287+
database have a directory structure similar to the work directory (but without
288+
the MPAS core subdirectory, which is redundant). The files include a date stamp
289+
so that new revisions can be added without removing older ones (supported by
290+
older compass versions). See :ref:`dev_step_cached_output` for more details.
291+
292+
A new command, ``compass cache`` has been added to aid in updating the file
293+
``cached_files.json`` within an MPAS core. This command is only available on
294+
Anvil and Chrysalis, since developers can only copy files from a compass work
295+
directory onto the LCRC server from these two machines. Developers run
296+
``compass cache`` from the base work directory, giving the relative paths of
297+
the step whose outputs should be cached:
298+
299+
.. code-block:: bash
300+
301+
compass cache -i ocean/global_ocean/QU240/mesh/mesh \
302+
ocean/global_ocean/QU240/PHC/init/initial_state
303+
304+
This will:
305+
306+
1. copy the output files from the steps directories into the appropriate
307+
``compass_cache`` location on the LCRC server and
308+
309+
2. add these files to a local ``ocean_cached_files.json`` that can then be
310+
copied to ``compass/ocean`` as part of a PR to add a cached version of a
311+
step.
312+
313+
The resulting ``ocean_cached_files.json`` will look something like:
314+
315+
.. code-block:: json
316+
317+
{
318+
"ocean/global_ocean/QU240/mesh/mesh/culled_mesh.nc": "global_ocean/QU240/mesh/mesh/culled_mesh.210803.nc",
319+
"ocean/global_ocean/QU240/mesh/mesh/culled_graph.info": "global_ocean/QU240/mesh/mesh/culled_graph.210803.info",
320+
"ocean/global_ocean/QU240/mesh/mesh/critical_passages_mask_final.nc": "global_ocean/QU240/mesh/mesh/critical_passages_mask_final.210803.nc",
321+
"ocean/global_ocean/QU240/PHC/init/initial_state/initial_state.nc": "global_ocean/QU240/PHC/init/initial_state/initial_state.210803.nc",
322+
"ocean/global_ocean/QU240/PHC/init/initial_state/init_mode_forcing_data.nc": "global_ocean/QU240/PHC/init/initial_state/init_mode_forcing_data.210803.nc"
323+
}
324+
325+
An optional flag ``--date_string`` lets the developer set the date string to
326+
a date they choose. The default is today's date.
327+
328+
The flag ``--dry_run`` can be used to sanity check the resulting ``json`` file
329+
and the list of files printed to stdout without actually copying the files to
330+
the LCRC server.
331+
332+
See :ref:`dev_cache` for more about the underlying framework.

docs/developers_guide/framework.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ from individual steps are stored in log files ``<step>.log`` in the test case's
9999
work directory. The results of validation (if any) are displayed in the final
100100
stage of running the test case.
101101

102+
.. _dev_cache:
103+
104+
cache module
105+
~~~~~~~~~~~~
106+
107+
The :py:func:`compass.cache.update_cache()` function is used by
108+
``compass cache`` to copy step outputs to the ``compass_cache`` database on
109+
the LCRC server and to update ``<mpas_core>_cached_files.json`` files that
110+
contain a mapping between these cached files and the original outputs. This
111+
functionality enables running steps with :ref:`dev_step_cached_output`, which
112+
can be used to skip time-consuming initialization steps for faster development
113+
and debugging.
114+
102115
.. _dev_config:
103116

104117
Config files

docs/developers_guide/organization.rst

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,6 @@ As was the case for test cases, the base class :py:class:`compass.Step` has a
815815
large number of attributes that are useful at different stages (init, setup and
816816
run) of the step.
817817

818-
logger : logging.Logger
819-
A logger for output from the step
820-
821-
log_filename : str
822-
At run time, the name of a log file where output/errors from the step
823-
are being logged, or ``None`` if output is to stdout/stderr
824-
825818
Some attributes are available after calling the base class' constructor
826819
``super().__init__()``. These include:
827820

@@ -857,6 +850,10 @@ Some attributes are available after calling the base class' constructor
857850
``self.threads``
858851
the number of threads the step will use
859852

853+
``self.cached``
854+
Whether to get all of the outputs for the step from the database of
855+
cached outputs for the MPAS core that this step belongs to
856+
860857
Another set of attributes is not useful until ``setup()`` is called by the
861858
``compass`` framework:
862859

@@ -897,6 +894,10 @@ framework:
897894
methods and functions that use the logger to write their output to the log
898895
file.
899896

897+
``self.log_filename``
898+
The name of a log file where output/errors from the step are being logged,
899+
or ``None`` if output is to stdout/stderr
900+
900901
The inputs and outputs should not be altered but they may be used to get file
901902
names to read or write.
902903

@@ -1544,6 +1545,93 @@ in the test case's :ref:`dev_test_case_init`.
15441545
The relative path in ``filename`` is with respect to the step's work directory,
15451546
and is converted to an absolute path internally before the step is run.
15461547

1548+
.. _dev_step_cached_output:
1549+
1550+
Cached output files
1551+
~~~~~~~~~~~~~~~~~~~
1552+
1553+
Many ``compass`` test cases and steps are expensive enough that it can become
1554+
time consuming to run full workflows to produce meshes and initial conditions
1555+
in order to test simulations. Therefore, ``compass`` provides a mechanism for
1556+
caching the outputs of each step in a database so that they can be downloaded
1557+
and symlinked rather than being computed each time.
1558+
1559+
Cached output files are be stored in the ``compass_cache`` database within each
1560+
MPAS core's space on that LCRC server (see :ref:`dev_step_input_download`).
1561+
If the "cached" version of a step is selected, as we will describe below, each
1562+
of the test case's outputs will have a corresponding "input" file added with
1563+
the ``target`` being a cache file on the LCRC server and the ``filename`` being
1564+
the output file. ``compass`` uses the ``cached_files.json`` database to know
1565+
which cache files correspond to which step outputs.
1566+
1567+
A developer can indicate that ``compass`` test suite includes steps with cached
1568+
outputs in two ways. First, if all steps in a test case should have cached
1569+
output, the following notation should be used:
1570+
1571+
.. code-block:: none
1572+
1573+
ocean/global_ocean/QU240/mesh
1574+
cached
1575+
ocean/global_ocean/QU240/PHC/init
1576+
cached
1577+
1578+
That is, the word ``cached`` should appear after the test case on its own line.
1579+
The indentation is for visual clarity and is not required.
1580+
1581+
1582+
Second, ff only some steps in a test case should have cached output, they need
1583+
to be listed explicitly, as follows:
1584+
1585+
.. code-block:: none
1586+
1587+
ocean/global_ocean/QUwISC240/mesh
1588+
cached: mesh
1589+
ocean/global_ocean/QUwISC240/PHC/init
1590+
cached: initial_state ssh_adjustment
1591+
1592+
The line can be indented for visual clarity, but must begin with ``cached:``,
1593+
followed by a list of steps separated by a single space.
1594+
1595+
Similarly, a user setting up test cases has two mechanisms for specifying which
1596+
test cases and steps should have cached outputs. If all steps in a test case
1597+
should have cached outputs, the suffix ``c`` can be added to the test number:
1598+
1599+
.. code-block:: none
1600+
1601+
compass setup -n 90c 91c 92 ...
1602+
1603+
In this example, test cases 90 and 91 (``mesh`` and ``init`` test cases from
1604+
the ``SOwISC12to60`` global ocean mesh, in this case) are set up with cached
1605+
outputs in all steps and 92 (``performance_test``) is not. This approach is
1606+
efficient but does not provide any control of which steps use cached outputs
1607+
and which do not.
1608+
1609+
A much more verbose approach is required if some steps use cached outputs and
1610+
others do not within a given test case. Each test case must be set up on its
1611+
own with the ``-t`` and ``--cached`` flags as follows:
1612+
1613+
1614+
.. code-block:: none
1615+
1616+
compass setup -t ocean/global_ocean/QU240/mesh --cached mesh ...
1617+
compass setup -t ocean/global_ocean/QU240/PHC/init --cached initial_state ...
1618+
...
1619+
1620+
Cache files should be generated by first running the test case as normal, then
1621+
running the :ref:`dev_compass_cache` command-line tool at the base of the work
1622+
directory, providing the names of the steps whose outputs should be added to
1623+
the cache. The resulting ``<mpas_core>_cached_files.json`` should be copied
1624+
to ``compass/<mpas_core>/cached_files.json`` in a ``compass`` branch.
1625+
1626+
Calls to ``compass cache`` must be made on Chrysalis or Anvil. If outputs were
1627+
produced on another machine, they must be transferred to one of these two
1628+
machines before calling ``compass cache``. File can be added manually to the
1629+
LCRC server and the ``cached_files.json`` databases but this is not
1630+
recommended.
1631+
1632+
More details on cached outputs are available in the design document
1633+
:ref:`design_doc_cached_outputs`.
1634+
15471635
.. _dev_step_namelists_and_streams:
15481636

15491637
Adding namelist and streams files

0 commit comments

Comments
 (0)