| 1 |
# ADIOS4DOLFINx - A framework for checkpointing in DOLFINx |
| 2 |
|
| 3 |
 |
| 4 |
[](https://doi.org/10.21105/joss.06451) |
| 5 |
[](https://anaconda.org/conda-forge/adios4dolfinx) |
| 6 |
|
| 7 |
ADIOS4DOLFINx is an extension for [DOLFINx](https://github.com/FEniCS/dolfinx/) to checkpoint meshes, meshtags and functions using [ADIOS 2](https://adios2.readthedocs.io/en/latest/). |
| 8 |
|
| 9 |
The code uses the ADIOS2 Python-wrappers to write DOLFINx objects to file, supporting N-to-M (_recoverable_) and N-to-N (_snapshot_) checkpointing. |
| 10 |
See: [Checkpointing in DOLFINx - FEniCS 23](https://jsdokken.com/checkpointing-presentation/#/) or the examples in the [Documentation](https://jsdokken.com/adios4dolfinx/) for more information. |
| 11 |
|
| 12 |
For scalability, the code uses [MPI Neighbourhood collectives](https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node200.htm) for communication across processes. |
| 13 |
|
| 14 |
## Statement of Need |
| 15 |
|
| 16 |
As the usage of high performance computing clusters increases, more and more large-scale, long-running simulations are deployed. |
| 17 |
The need for storing intermediate solutions from such simulations are crucial, as the HPC system might crash, or the simulation might crash or exceed the alloted computational budget. |
| 18 |
Having a checkpoint of related variables, such as the solutions to partial differential equations (PDEs) is therefore essential. |
| 19 |
The `adios4dolfinx` library extends the [DOLFINx](https://github.com/FEniCS/dolfinx/) computational framework for solving PDEs with checkpointing functionality, such that immediate solutions and mesh information can be stored and re-used in another simulation. |
| 20 |
|
| 21 |
## Installation |
| 22 |
|
| 23 |
Compatibility with DOLFINx: |
| 24 |
|
| 25 |
- ADIOS4DOLFINx v0.10.0 is compatible with DOLFINx v0.10.x |
| 26 |
- ADIOS4DOLFINx v0.9.6 is compatible with DOLFINx v0.9.x |
| 27 |
- ADIOS4DOLFINx v0.8.1 is compatible with DOLFINx v0.8.x |
| 28 |
- ADIOS4DOLFINx v0.7.3 is compatible with DOLFINx v0.7.x |
| 29 |
|
| 30 |
### Dependencies |
| 31 |
|
| 32 |
The library depends on the Python-interface of [DOLFINx](https://github.com/) and an MPI-build of [ADIOS2](https://adios2.readthedocs.io/en/latest/setting_up/setting_up.html#as-package). |
| 33 |
Therefore `ADIOS2` should not be install through PYPI/pip, but has to be installed through Conda, Spack or from source. |
| 34 |
|
| 35 |
> [!IMPORTANT] |
| 36 |
> ADIOS2<2.10.2 does not work properly with `numpy>=2.0.0`. Everyone is advised to use the newest version of ADIOS2. |
| 37 |
> This is for instance available through `conda` or the `ghcr.io/fenics/dolfinx/dolfinx:nightly` Docker-image. |
| 38 |
|
| 39 |
### Spack |
| 40 |
|
| 41 |
ADIOS4DOLFINx is a [spack package](https://packages.spack.io/package.html?name=py-adios4dolfinx) |
| 42 |
which can be installed with |
| 43 |
|
| 44 |
```bash |
| 45 |
spack add py-adios4dolfinx ^py-fenics-dolfinx+petsc4py+slepc4py |
| 46 |
spack concretize |
| 47 |
spack install |
| 48 |
``` |
| 49 |
|
| 50 |
once you have downloaded spack and set up a new environment, as described in [Spack: Installation notes](https://github.com/spack/spack?tab=readme-ov-file#installation). |
| 51 |
To ensure that the spack packages are up to date, please call |
| 52 |
|
| 53 |
```bash |
| 54 |
spack repo update builtin |
| 55 |
``` |
| 56 |
|
| 57 |
prior to concretizing. |
| 58 |
|
| 59 |
### Docker |
| 60 |
|
| 61 |
An MPI build of ADIOS2 is installed in the official DOLFINx containers, and thus there are no additional dependencies required to install `adios4dolfinx` |
| 62 |
on top of DOLFINx in these images. |
| 63 |
|
| 64 |
Create a Docker container, named for instance `dolfinx-checkpoint`. |
| 65 |
Use the `nightly` tag to get the main branch of DOLFINx, or `stable` to get the latest stable release |
| 66 |
|
| 67 |
```bash |
| 68 |
docker run -ti -v $(pwd):/root/shared -w /root/shared --name=dolfinx-checkpoint ghcr.io/fenics/dolfinx/dolfinx:nightly |
| 69 |
``` |
| 70 |
|
| 71 |
For the latest version compatible with nightly (with the ability to run the test suite), use |
| 72 |
|
| 73 |
```bash |
| 74 |
python3 -m pip install adios4dolfinx[test]@git+https://github.com/jorgensd/adios4dolfinx@main |
| 75 |
``` |
| 76 |
|
| 77 |
If you are using the `stable` image, you can install `adios4dolfinx` from [PYPI](https://pypi.org/project/adios4dolfinx/) with |
| 78 |
|
| 79 |
```bash |
| 80 |
python3 -m pip install adios4dolfinx[test] |
| 81 |
``` |
| 82 |
|
| 83 |
This docker container can be opened with |
| 84 |
|
| 85 |
```bash |
| 86 |
docker container start -i dolfinx-checkpoint |
| 87 |
``` |
| 88 |
|
| 89 |
at a later instance |
| 90 |
|
| 91 |
### Conda |
| 92 |
|
| 93 |
> [!NOTE] |
| 94 |
> Conda supports the stable release of DOLFINx, and thus the appropriate version should be installed, see the section above for more details. |
| 95 |
|
| 96 |
Following is a minimal recipe of how to install adios4dolfinx, given that you have conda installed on your system. |
| 97 |
|
| 98 |
```bash |
| 99 |
conda create -n dolfinx-checkpoint python=3.10 |
| 100 |
conda activate dolfinx-checkpoint |
| 101 |
conda install -c conda-forge adios4dolfinx |
| 102 |
``` |
| 103 |
|
| 104 |
> [!NOTE] |
| 105 |
> Remember to download the appropriate version of `adios4dolfinx` from Github [adios4dolfinx: Releases](https://github.com/jorgensd/adios4dolfinx/releases) |
| 106 |
|
| 107 |
To run the test suite, you should also install `ipyparallel`, `pytest` and `coverage`, which can all be installed with conda |
| 108 |
|
| 109 |
```bash |
| 110 |
conda install -c conda-forge ipyparallel pytest coverage |
| 111 |
``` |
| 112 |
|
| 113 |
## Functionality |
| 114 |
|
| 115 |
### DOLFINx |
| 116 |
|
| 117 |
- Reading and writing meshes, using `adios4dolfinx.read/write_mesh` |
| 118 |
- Reading and writing meshtags associated to meshes `adios4dolfinx.read/write_meshtags` |
| 119 |
- Reading checkpoints for any element (serial and parallel, arbitrary number of functions and timesteps per file). Use `adios4dolfinx.read/write_function`. |
| 120 |
- Writing standalone function checkpoints relating to "original meshes", i.e. meshes read from `XDMFFile`. Use `adios4dolfinx.write_function_on_input_mesh` for this. |
| 121 |
- Store mesh partitioning and re-read the mesh with this information, avoiding calling SCOTCH, Kahip or Parmetis. |
| 122 |
|
| 123 |
> [!IMPORTANT] |
| 124 |
> For checkpoints written with `write_function` to be valid, you first have to store the mesh with `write_mesh` to the checkpoint file. |
| 125 |
|
| 126 |
> [!IMPORTANT] |
| 127 |
> A checkpoint file supports multiple functions and multiple time steps, as long as the functions are associated with the same mesh |
| 128 |
|
| 129 |
> [!IMPORTANT] |
| 130 |
> Only one mesh per file is allowed |
| 131 |
|
| 132 |
## Example Usage |
| 133 |
|
| 134 |
The repository contains many documented examples of usage, in the `docs`-folder, including |
| 135 |
|
| 136 |
- [Reading and writing mesh checkpoints](./docs/writing_mesh_checkpoint.py) |
| 137 |
- [Storing mesh partitioning data](./docs/partitioned_mesh.py) |
| 138 |
- [Writing mesh-tags to a checkpoint](./docs/meshtags.py) |
| 139 |
- [Reading and writing function checkpoints](./docs/writing_functions_checkpoint.py) |
| 140 |
- [Checkpoint on input mesh](./docs/original_checkpoint.py) |
| 141 |
Further examples can be found at [ADIOS4DOLFINx examples](https://jsdokken.com/adios4dolfinx/) |
| 142 |
|
| 143 |
### Backwards compatibility |
| 144 |
|
| 145 |
> [!WARNING] |
| 146 |
> If you are using v0.7.2, you are advised to upgrade to v0.7.3, as it contains som crucial fixes for openmpi. |
| 147 |
|
| 148 |
### Legacy DOLFIN |
| 149 |
|
| 150 |
Only checkpoints for `Lagrange` or `DG` functions are supported from legacy DOLFIN |
| 151 |
|
| 152 |
- Reading meshes from the DOLFIN HDF5File-format |
| 153 |
- Reading checkpoints from the DOLFIN HDF5File-format (one checkpoint per file only) |
| 154 |
- Reading checkpoints from the DOLFIN XDMFFile-format (one checkpoint per file only, and only uses the `.h5` file) |
| 155 |
|
| 156 |
See the [API](./docs/api) for more information. |
| 157 |
|
| 158 |
## Testing |
| 159 |
|
| 160 |
This library uses `pytest` for testing. |
| 161 |
To execute the tests, one should first install the library and its dependencies, as listed above. |
| 162 |
Then, can execute all tests by calling |
| 163 |
|
| 164 |
```bash |
| 165 |
python3 -m pytest . |
| 166 |
``` |
| 167 |
|
| 168 |
### Testing against data from legacy dolfin |
| 169 |
|
| 170 |
Some tests check the capability of reading data created with the legacy version of DOLFIN. |
| 171 |
To create this dataset, start a docker container with legacy DOLFIN, for instance: |
| 172 |
|
| 173 |
```bash |
| 174 |
docker run -ti -v $(pwd):/root/shared -w /root/s |
| 175 |
hared --rm ghcr.io/scientificcomputing/fenics:2024-02-19 |
| 176 |
``` |
| 177 |
|
| 178 |
Then, inside this container, call |
| 179 |
|
| 180 |
```bash |
| 181 |
python3 ./tests/create_legacy_data.py --output-dir=legacy |
| 182 |
``` |
| 183 |
|
| 184 |
### Testing against data from older versions of ADIOS4DOLFINx |
| 185 |
|
| 186 |
Some tests check the capability to read data generated by `adios4dolfinx<0.7.2`. |
| 187 |
To generate data for these tests use the following commands: |
| 188 |
|
| 189 |
```bash |
| 190 |
docker run -ti -v $(pwd):/root/shared -w /root/shared --rm ghcr.io/fenics/dolfinx/dolfinx:v0.7.3 |
| 191 |
``` |
| 192 |
|
| 193 |
Then, inside the container, call |
| 194 |
|
| 195 |
```bash |
| 196 |
python3 -m pip install adios4dolfinx==0.7.1 |
| 197 |
python3 ./tests/create_legacy_checkpoint.py --output-dir=legacy_checkpoint |
| 198 |
``` |
| 199 |
|
| 200 |
## Long term plan |
| 201 |
|
| 202 |
The long term plan is to get this library merged into DOLFINx (rewritten in C++ with appropriate Python-bindings). |