Skip to content

Commit 260e5cf

Browse files
authored
Merge pull request #72 from cseptesting/68-improve-report-module
Updated documentation with tutorials using docker and parallel execution
2 parents 889021d + 2c9eed9 commit 260e5cf

40 files changed

+460
-154
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
html_theme = "sphinx_rtd_theme"
7171
html_static_path = ["_static"]
7272
html_theme_options = {
73-
"display_version": True,
7473
"prev_next_buttons_location": "both",
7574
"sticky_navigation": True,
7675
"collapse_navigation": True,

docs/guide/model_config.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ Here you can find a comprehensive list of parameters used to configure models
159159
* - **forecast_unit** (required)
160160
- All
161161
- Specifies the time unit for the forecast. Use **years** for time-independent models and **days** for time-dependent models.
162-
* - **store_db** (optional)
163-
- All
164-
- If the model consists on only files, this is a boolean (true/false) specifying whether to store the forecast in a database (HDF5).
165162
* - **flavours** (optional)
166163
- All
167164
- A set of parameter variations to generate multiple model variants (e.g., different settings for the same model).

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Quickstart
6464
| | - :ref:`case_f` |
6565
| |api| **API Reference** | - :ref:`case_g` |
6666
| | - :ref:`case_h` |
67+
| | - :ref:`case_i` |
68+
| | - :ref:`case_j` |
6769
+--------------------------------------------------+-------------------------------------+
6870

6971
What is floatCSEP
@@ -158,6 +160,8 @@ Collaborators
158160
tutorials/case_f.rst
159161
tutorials/case_g.rst
160162
tutorials/case_h.rst
163+
tutorials/case_i.rst
164+
tutorials/case_j.rst
161165

162166

163167
.. toctree::

docs/intro/installation.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ Having installed the binary dependencies of **pyCSEP** (see `Installing pyCSEP <
105105
Or downloaded manually from the `latest release <https://github.com/cseptesting/floatcsep/releases>`_.
106106

107107

108+
.. _docker-install:
109+
110+
Docker (Model Containerization & Parallel Run)
111+
----------------------------------------------
112+
113+
Some tutorials and experiments **containerize models with Docker**, and the engine can use Docker
114+
for **parallel** execution. To use these features, please install Docker and (on Linux) perform the
115+
post-installation steps:
116+
117+
- Docker install guide: https://docs.docker.com/engine/install/
118+
- Linux post-installation (non-root usage and add your user to the `docker` group):
119+
https://docs.docker.com/engine/install/linux-postinstall/
120+
121+
.. tip::
122+
After installing, verify Docker works:
123+
124+
.. code-block:: console
125+
126+
$ docker run --rm hello-world
127+
108128
109129
For Developers
110130
--------------

docs/tutorials/case_e.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
E - A Time-Independent Experiment
44
=================================
55

6-
This example shows how to run a realistic testing experiment (based on :ref:`Schorlemmer et al. 2010<References>`) while summarizing the concepts from the previous tutorials.
6+
This example shows how to run a realistic testing experiment (based on :ref:`Schorlemmer et al. 2010<case_e_references>`) while summarizing the concepts from the previous tutorials.
77

88
.. currentmodule:: floatcsep
99

@@ -139,6 +139,8 @@ Plot command
139139
and re-run with the ``plot`` command. A forecast figure will re-appear in ``results/{window}/forecasts`` with a different colormap. Additional forecast and catalog plotting options can be found in the :func:`csep.utils.plots.plot_spatial_dataset` and :func:`csep.utils.plots.plot_catalog` ``pycsep`` functions.
140140

141141

142+
.. _case_e_references:
143+
142144
References
143145
----------
144146

docs/tutorials/case_f.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The source files can be found in the ``tutorials/case_e`` folder or in `the Git
4949
Model
5050
-----
5151

52-
The time-dependency of a model is manifested here by the provision of different forecasts, i.e., statistical descriptions of seismicity, for different time-windows. In this example, the forecasts were created from an external model https://github.com/lmizrahi/etas (:ref:`Mizrahi et al. 2021<References>`_), with which the experiment has no interface. This means that we use **only the forecast files** and no source code. We leave the handling of a model source code for subsequent tutorials.
52+
The time-dependency of a model is manifested here by the provision of different forecasts, i.e., statistical descriptions of seismicity, for different time-windows. In this example, the forecasts were created from an external `ETAS model <https://github.com/lmizrahi/etas>`_ (:ref:`Mizrahi et al. 2021 <case_f_references>`), with which the experiment has no interface. This means that we use **only the forecast files** and no source code. We leave the handling of a model source code for subsequent tutorials.
5353

5454

5555

@@ -120,6 +120,8 @@ Running the experiment
120120
This will automatically set all the calculation paths (testing catalogs, evaluation results, figures) and will create a summarized report in ``results/report.md``.
121121

122122

123+
.. _case_f_references:
124+
123125
References
124126
----------
125127

docs/tutorials/case_g.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Here, we set up a time-dependent model from its **source code** for an experimen
1414
$ floatcsep run config.yml
1515
1616
After the calculation is complete, the results will be summarized in ``results/report.md``.
17+
For troubleshooting, run the experiment with:
1718

19+
.. code-block:: console
20+
21+
$ floatcsep run config.yml --debug
1822
1923
.. currentmodule:: floatcsep
2024

docs/tutorials/case_h.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Here, we run an experiment that accesses, containerizes and executes multiple **
1414
$ floatcsep run config.yml
1515
1616
After the calculation is complete, the results will be summarized in ``results/report.md``.
17+
For troubleshooting, run the experiment with:
18+
19+
.. code-block:: console
20+
21+
$ floatcsep run config.yml --debug
1722
1823
.. currentmodule:: floatcsep
1924

docs/tutorials/case_i.rst

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
.. _case_i:
2+
3+
I — Containerizing a Model with Docker
4+
======================================
5+
6+
**Goal.** Show how to containerize a forecasting model with **Docker** and run it inside
7+
the floatCSEP engine, producing catalog forecasts and evaluating them with an N-test.
8+
This case uses simple mock models as examples.
9+
10+
.. warning::
11+
12+
**Docker is required** to containerize models and (optionally) to run in parallel.
13+
Please install Docker and complete the Linux post-installation steps if applicable.
14+
See :ref:`docker-install` in the Installation guide.
15+
16+
.. admonition:: **TL; DR**
17+
18+
In a terminal, navigate to ``floatcsep/tutorials/case_i`` and type:
19+
20+
.. code-block:: console
21+
22+
$ floatcsep run config.yml
23+
24+
After the calculation is complete, the results will be summarized in ``results/report.md``.
25+
For troubleshooting, run the experiment with:
26+
27+
.. code-block:: console
28+
29+
$ floatcsep run config.yml --debug
30+
31+
.. currentmodule:: floatcsep
32+
33+
.. contents:: Contents
34+
:local:
35+
36+
37+
38+
Experiment layout
39+
-----------------
40+
41+
The experiment input files are:
42+
43+
::
44+
45+
case_i
46+
└── pymock
47+
└── pymock # src code
48+
| ...
49+
├── Dockerfile # Docker image build instructions
50+
└── setup.cfg # Python build configuration
51+
└── pymock_slow # Same as pymock, but slower (to test cpu and DAG usage)
52+
| ...
53+
├── catalog.csep
54+
├── config.yml
55+
├── tests.yml
56+
└── models.yml
57+
58+
59+
60+
Configuration
61+
-------------
62+
63+
``config.yml``
64+
^^^^^^^^^^^^^^
65+
66+
.. code-block:: yaml
67+
68+
name: case_i
69+
70+
time_config:
71+
start_date: 2012-5-23T00:00:00
72+
end_date: 2012-8-23T00:00:00
73+
horizon: 7days
74+
exp_class: td
75+
76+
region_config:
77+
region: italy_csep_region
78+
mag_min: 3.5
79+
mag_max: 8.0
80+
mag_bin: 0.5
81+
depth_min: 0
82+
depth_max: 70
83+
84+
run_mode: parallel
85+
force_rerun: True
86+
catalog: catalog.csv
87+
model_config: models.yml
88+
test_config: tests.yml
89+
90+
postprocess:
91+
plot_forecasts: false
92+
93+
**Notes**
94+
95+
- ``exp_class: td`` declares a time-dependent experiment with rolling windows of length ``horizon``.
96+
- ``run_mode: parallel`` enables parallel solving (if resources allow).
97+
- ``force_rerun: True`` forces regeneration of forecasts even if files exist.
98+
99+
100+
``models.yml``
101+
^^^^^^^^^^^^^^
102+
103+
.. code-block:: yaml
104+
105+
- pymock:
106+
path: pymock
107+
func: pymock
108+
func_kwargs:
109+
n_sims: 1000
110+
mag_min: 3.5
111+
build: docker
112+
113+
- pymock_slow:
114+
path: pymock_slow
115+
func: pymock
116+
prefix: pymock
117+
func_kwargs:
118+
n_sims: 1000
119+
mag_min: 3.5
120+
build: docker
121+
122+
**Notes**
123+
124+
- ``build: docker`` tells floatCSEP to **build a Docker image** for the model located at ``path``.
125+
- ``func`` is the entry-point used **inside** the container to run the forecasts (defined in ``setup.cfg``)
126+
- ``func_kwargs`` are passed to ``model/input/args`` **inside** the container. They are stored and can be visualized in ``results/{time_window/input/{model}``.
127+
- You can add the options ``force_build`` to rebuild the Docker image.
128+
129+
130+
How containerization works here
131+
-------------------------------
132+
133+
- For each model block marked ``build: docker``, floatCSEP:
134+
135+
1. Builds a Docker image from the model directory at ``path`` (expects a valid Dockerfile and the model’s code/config there).
136+
2. Runs the container, mounting standard I/O folders used by the model (e.g., an ``input/`` and a model ``forecasts/`` directory), and executes your model’s entry-point (``func``).
137+
3. Collects the produced forecast files and proceeds with evaluations.
138+
139+
140+
**Checklist to Dockerize your own model**
141+
142+
- Add a **Dockerfile** in your model folder (``path``).
143+
- Ensure your entry-point can be invoked by the engine (e.g., a Python module or script that maps to ``func`` and accepts ``func_kwargs``).
144+
- The model should be able to read input data (catalog and args) from ``{model_basedir}/input``
145+
- Write outputs to the expected location (e.g., a ``{model_basedir}/forecasts/`` directory).
146+
- (Optional): Avoid writing to root-owned paths inside the container; keep everything under the mounted work basedir.
147+
- Test your image locally with a dry run:
148+
149+
150+
from the ``{model_basedir}``
151+
152+
.. code-block:: console
153+
154+
$ docker build \
155+
--build-arg USERNAME=$USER \
156+
--build-arg USER_UID=$(id -u) \
157+
--build-arg USER_GID=$(id -g) \
158+
-t {model_name} .
159+
160+
$ docker run --rm --volume $PWD:/usr/src/pymock:rw model_pymock python run.py input/args.txt
161+
162+
163+
What happens under the hood
164+
---------------------------
165+
166+
1. Controller parses rolling time windows from ``start_date`` to ``end_date`` with a 7-day horizon.
167+
2. For each Dockerized model (``pymock``, ``pymock_slow``), the controller builds an image and launches
168+
containers with the appropriate inputs/arguments.
169+
3. Forecasts are written to each model’s ``forecasts/`` directory (or central output).
170+
4. The **Catalog N-test** runs on the collected forecasts and generates diagnostic plots.
171+
172+
173+
Outputs
174+
-------
175+
176+
You should find:
177+
178+
- Weekly gridded forecasts in each model’s ``forecasts/`` folder.
179+
- N-test results (tables/JSON) in ``results/{time_window}/evaluations``.
180+
- Markdown and PDF reports summarizing the experiment results in ``results/report.md``.
181+
182+
183+
Running the experiment
184+
----------------------
185+
186+
From the ``tutorials/case_i`` folder, run:
187+
188+
.. code-block:: console
189+
190+
$ floatcsep run config.yml
191+
192+
This will build the Docker images (if needed), run the containers for each time window and model,
193+
perform the evaluations, and create a summarized report in ``results/report.md``.
194+
195+
196+
Troubleshooting
197+
---------------
198+
199+
- Run in debug mode with ``floatcsep run config.yml --debug``, or add ``--log`` to output a log file ``results/log``
200+
- **Docker not found / permission denied**:
201+
- Ensure Docker is installed and your user can run containers (Linux: add to ``docker`` group).
202+
- See :ref:`docker-install`.
203+
- **Model image fails to build**:
204+
- Check a clean installation (without Docker) and running using its entry-point.
205+
- Check the Dockerfile, base image, and that all runtime deps are installed in the image.
206+
- Try building manually with ``docker build`` for clearer error messages.
207+
- Adapt one of the provided Dockerfiles in the model folders.
208+
- **No forecasts produced**:
209+
- Confirm your model writes to the expected ``forecasts/`` directory.
210+
- Verify that the code actually reads from ``input/args.txt`` (or ``.yml`` or ``.json``).
211+
- **Plots not generated**:
212+
- Inspect logs under ``results/`` for tracebacks.
213+

0 commit comments

Comments
 (0)