|
1 | | -# ADIOS4DOLFINx - A framework for checkpointing in DOLFINx |
| 1 | +# io4dolfinx - A framework for reading and writing data to various mesh formats |
2 | 2 |
|
3 | | - |
4 | | -[](https://anaconda.org/conda-forge/adios4dolfinx) |
| 3 | +**io4dolfinx** is an extension for [DOLFINx](https://github.com/FEniCS/dolfinx/) that provides advanced input/output capabilities. It focuses on **N-to-M checkpointing** (writing data on N processors, reading on M processors) and supports reading/writing various mesh formats using interchangeable backends. |
5 | 4 |
|
6 | | -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/). |
7 | | - |
8 | | -The code uses the ADIOS2 Python-wrappers to write DOLFINx objects to file, supporting N-to-M (_recoverable_) and N-to-N (_snapshot_) checkpointing. |
9 | | -See: [Checkpointing in DOLFINx - FEniCS 23](https://jsdokken.com/checkpointing-presentation/#/) or the examples in the [Documentation](https://jsdokken.com/adios4dolfinx/) for more information. |
10 | | - |
11 | | -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. |
12 | | - |
13 | | -## Statement of Need |
14 | | - |
15 | | -As the usage of high performance computing clusters increases, more and more large-scale, long-running simulations are deployed. |
16 | | -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. |
17 | | -Having a checkpoint of related variables, such as the solutions to partial differential equations (PDEs) is therefore essential. |
18 | | -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. |
19 | 5 |
|
20 | 6 | ## Installation |
21 | 7 |
|
22 | | -Compatibility with DOLFINx: |
23 | | - |
24 | | -- ADIOS4DOLFINx v0.10.0 is compatible with DOLFINx v0.10.x |
25 | | -- ADIOS4DOLFINx v0.9.6 is compatible with DOLFINx v0.9.x |
26 | | -- ADIOS4DOLFINx v0.8.1 is compatible with DOLFINx v0.8.x |
27 | | -- ADIOS4DOLFINx v0.7.3 is compatible with DOLFINx v0.7.x |
28 | | - |
29 | | -### Dependencies |
30 | | - |
31 | | -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). |
32 | | -Therefore `ADIOS2` should not be install through PYPI/pip, but has to be installed through Conda, Spack or from source. |
33 | | - |
34 | | -> [!IMPORTANT] |
35 | | -> ADIOS2<2.10.2 does not work properly with `numpy>=2.0.0`. Everyone is advised to use the newest version of ADIOS2. |
36 | | -> This is for instance available through `conda` or the `ghcr.io/fenics/dolfinx/dolfinx:nightly` Docker-image. |
37 | | -
|
38 | | -### Spack |
39 | | - |
40 | | -ADIOS4DOLFINx is a [spack package](https://packages.spack.io/package.html?name=py-adios4dolfinx) |
41 | | -which can be installed with |
42 | | - |
43 | | -```bash |
44 | | -spack add py-adios4dolfinx ^py-fenics-dolfinx+petsc4py+slepc4py |
45 | | -spack concretize |
46 | | -spack install |
47 | | -``` |
48 | | - |
49 | | -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). |
50 | | -To ensure that the spack packages are up to date, please call |
| 8 | +The library is compatible with the DOLFINx nightly release, v0.10.0, and v0.9.0. |
51 | 9 |
|
52 | 10 | ```bash |
53 | | -spack repo update builtin |
| 11 | +python3 -m pip install io4dolfinx |
54 | 12 | ``` |
55 | 13 |
|
56 | | -prior to concretizing. |
| 14 | +For specific backend requirements (like ADIOS2 or H5PY), see the [Installation Guide](./docs/installation.md). |
57 | 15 |
|
58 | | -### Docker |
59 | 16 |
|
60 | | -An MPI build of ADIOS2 is installed in the official DOLFINx containers, and thus there are no additional dependencies required to install `adios4dolfinx` |
61 | | -on top of DOLFINx in these images. |
| 17 | +## Quick Start |
62 | 18 |
|
63 | | -Create a Docker container, named for instance `dolfinx-checkpoint`. |
64 | | -Use the `nightly` tag to get the main branch of DOLFINx, or `stable` to get the latest stable release |
| 19 | +Here is a minimal example of saving and loading a simulation state (Checkpointing). |
65 | 20 |
|
66 | | -```bash |
67 | | -docker run -ti -v $(pwd):/root/shared -w /root/shared --name=dolfinx-checkpoint ghcr.io/fenics/dolfinx/dolfinx:nightly |
68 | | -``` |
| 21 | +```python |
| 22 | +from pathlib import Path |
| 23 | +from mpi4py import MPI |
| 24 | +import dolfinx |
| 25 | +import io4dolfinx |
69 | 26 |
|
70 | | -For the latest version compatible with nightly (with the ability to run the test suite), use |
71 | | - |
72 | | -```bash |
73 | | -python3 -m pip install adios4dolfinx[test]@git+https://github.com/jorgensd/adios4dolfinx@main |
74 | | -``` |
| 27 | +# 1. Create a mesh and function |
| 28 | +comm = MPI.COMM_WORLD |
| 29 | +mesh = dolfinx.mesh.create_unit_square(comm, 10, 10) |
| 30 | +V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) |
| 31 | +u = dolfinx.fem.Function(V) |
| 32 | +u.interpolate(lambda x: x[0] + x[1]) |
| 33 | +u.name = "my_function" |
75 | 34 |
|
76 | | -If you are using the `stable` image, you can install `adios4dolfinx` from [PYPI](https://pypi.org/project/adios4dolfinx/) with |
| 35 | +# 2. Write checkpoint |
| 36 | +# The mesh must be written before the function |
| 37 | +filename = Path("checkpoint.bp") |
| 38 | +io4dolfinx.write_mesh(filename, mesh) |
| 39 | +io4dolfinx.write_function(filename, u, time=0.0) |
77 | 40 |
|
78 | | -```bash |
79 | | -python3 -m pip install adios4dolfinx[test] |
80 | | -``` |
81 | | - |
82 | | -This docker container can be opened with |
83 | | - |
84 | | -```bash |
85 | | -docker container start -i dolfinx-checkpoint |
| 41 | +# 3. Read checkpoint |
| 42 | +# This works even if the number of MPI processes changes (N-to-M) |
| 43 | +mesh_new = io4dolfinx.read_mesh(filename, comm) |
| 44 | +V_new = dolfinx.fem.functionspace(mesh_new, ("Lagrange", 1)) |
| 45 | +u_new = dolfinx.fem.Function(V_new) |
| 46 | +io4dolfinx.read_function(filename, u_new, time=0.0, name="my_function") |
86 | 47 | ``` |
87 | 48 |
|
88 | | -at a later instance |
89 | | - |
90 | | -### Conda |
91 | 49 |
|
92 | | -> [!NOTE] |
93 | | -> Conda supports the stable release of DOLFINx, and thus the appropriate version should be installed, see the section above for more details. |
| 50 | +## Features and Backends |
94 | 51 |
|
95 | | -Following is a minimal recipe of how to install adios4dolfinx, given that you have conda installed on your system. |
| 52 | +`io4dolfinx` supports custom user backends. You can switch backends by passing `backend="name"` to IO functions. |
96 | 53 |
|
97 | | -```bash |
98 | | -conda create -n dolfinx-checkpoint python=3.10 |
99 | | -conda activate dolfinx-checkpoint |
100 | | -conda install -c conda-forge adios4dolfinx |
101 | | -``` |
| 54 | +### Checkpointing (N-to-M) |
| 55 | +Many finite element applications requires storage of functions that cannot be associated with the nodes or cells of the mesh. Therefore, we have implemented our own, native checkpointing format that supports N-to-M checkpointing (write data on N processors, read in on M) through the following backends: |
102 | 56 |
|
103 | | -> [!NOTE] |
104 | | -> Remember to download the appropriate version of `adios4dolfinx` from Github [adios4dolfinx: Releases](https://github.com/jorgensd/adios4dolfinx/releases) |
| 57 | +- [h5py](./docs/backends/h5py.rst): Requires HDF5 with MPI support to work, but can store, meshes, partitioning info, meshtags, function data and more. |
| 58 | +- [adios2](./docs/backends/adios2.rst): Requires [ADIOS 2](https://adios2.readthedocs.io/en/latest/) compiled with MPI support and Python bindings. Supports the same set of operations as the `h5py` backend. |
105 | 59 |
|
106 | | -To run the test suite, you should also install `ipyparallel`, `pytest` and `coverage`, which can all be installed with conda |
| 60 | +The code uses the ADIOS2/Python-wrappers and h5py module to write DOLFINx objects to file, supporting N-to-M (_recoverable_) and N-to-N (_snapshot_) checkpointing. |
| 61 | +See: [Checkpointing in DOLFINx - FEniCS 23](https://jsdokken.com/checkpointing-presentation/#/) or the examples in the [Documentation](https://jsdokken.com/io4dolfinx/) for more information. |
107 | 62 |
|
108 | | -```bash |
109 | | -conda install -c conda-forge ipyparallel pytest coverage |
110 | | -``` |
| 63 | +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. |
111 | 64 |
|
112 | | -## Functionality |
113 | 65 |
|
114 | | -### DOLFINx |
| 66 | +### Mesh IO (Import/Export) |
| 67 | +Most meshing formats supports associating data with the nodes of the mesh (the mesh can be higher order) and the cells of the mesh. The node data can be read in as P-th order Lagrange functions (where P is the order of the grid), while the cell data can be read in as piecewise constant (DG-0) functions. |
115 | 68 |
|
116 | | -- Reading and writing meshes, using `adios4dolfinx.read/write_mesh` |
117 | | -- Reading and writing meshtags associated to meshes `adios4dolfinx.read/write_meshtags` |
118 | | -- Reading checkpoints for any element (serial and parallel, arbitrary number of functions and timesteps per file). Use `adios4dolfinx.read/write_function`. |
119 | | -- Writing standalone function checkpoints relating to "original meshes", i.e. meshes read from `XDMFFile`. Use `adios4dolfinx.write_function_on_input_mesh` for this. |
120 | | -- Store mesh partitioning and re-read the mesh with this information, avoiding calling SCOTCH, Kahip or Parmetis. |
| 69 | +- [VTKHDF](./docs/backends/vtkhdf.rst): The new scalable format from VTK, called [VTKHDF](https://docs.vtk.org/en/latest/vtk_file_formats/vtkhdf_file_format/index.html) is supported by the `vtkhdf` backend. |
| 70 | +- [XDMF](./docs/backends/xdmf.rst) (eXtensible Model Data Format): `.xdmf`. The `xdmf` backend supports the `HDF5` encoding, to ensure performance in parallel. |
| 71 | +- [PyVista](./docs/backends/pyvista.rst) (IO backend is meshio): The [pyvista](https://pyvista.org/) backend uses {py:func}`pyvista.read` to read in meshes, point data and cell data. `pyvista` relies on [meshio](https://github.com/nschloe/meshio) for most reading operations (including the XDMF ascii format). |
121 | 72 |
|
122 | | -> [!IMPORTANT] |
123 | | -> For checkpoints written with `write_function` to be valid, you first have to store the mesh with `write_mesh` to the checkpoint file. |
124 | 73 |
|
125 | | -> [!IMPORTANT] |
126 | | -> A checkpoint file supports multiple functions and multiple time steps, as long as the functions are associated with the same mesh |
127 | 74 |
|
128 | | -> [!IMPORTANT] |
129 | | -> Only one mesh per file is allowed |
| 75 | +## Advanced Usage |
130 | 76 |
|
131 | | -## Example Usage |
| 77 | +The repository contains detailed documented examples in the `docs` folder: |
132 | 78 |
|
133 | | -The repository contains many documented examples of usage, in the `docs`-folder, including |
| 79 | +* [Reading and writing mesh checkpoints](./docs/writing_mesh_checkpoint.py) |
| 80 | +* [Storing mesh partitioning data](./docs/partitioned_mesh.py) (Avoid re-partitioning when restarting) |
| 81 | +* [Writing mesh-tags](./docs/meshtags.py) |
| 82 | +* [Writing function checkpoints](./docs/writing_functions_checkpoint.py) |
| 83 | +* [Checkpoint on input mesh](./docs/original_checkpoint.py) |
134 | 84 |
|
135 | | -- [Reading and writing mesh checkpoints](./docs/writing_mesh_checkpoint.py) |
136 | | -- [Storing mesh partitioning data](./docs/partitioned_mesh.py) |
137 | | -- [Writing mesh-tags to a checkpoint](./docs/meshtags.py) |
138 | | -- [Reading and writing function checkpoints](./docs/writing_functions_checkpoint.py) |
139 | | -- [Checkpoint on input mesh](./docs/original_checkpoint.py) |
140 | | - Further examples can be found at [ADIOS4DOLFINx examples](https://jsdokken.com/adios4dolfinx/) |
| 85 | +For a full API reference and backend details, see the [Documentation](https://jsdokken.com/io4dolfinx/). |
141 | 86 |
|
142 | | -### Backwards compatibility |
| 87 | +### Legacy DOLFIN Support |
| 88 | +`io4dolfinx` can read checkpoints created by the legacy version of DOLFIN (Lagrange or DG functions). |
| 89 | +* Reading meshes from DOLFIN HDF5File-format. |
| 90 | +* Reading checkpoints from DOLFIN HDF5File and XDMFFile. |
143 | 91 |
|
144 | | -> [!WARNING] |
145 | | -> If you are using v0.7.2, you are advised to upgrade to v0.7.3, as it contains som crucial fixes for openmpi. |
| 92 | +## Project Background |
146 | 93 |
|
147 | | -### Legacy DOLFIN |
| 94 | +### Relation to adios4dolfinx |
| 95 | +This library is an evolution of [adios4dolfinx](https://doi.org/10.21105/joss.06451). It includes all functionality of the original library but has been refactored to support multiple IO backends (not just ADIOS2), making it easier to interface with different meshing formats while keeping the library structure sane. |
148 | 96 |
|
149 | | -Only checkpoints for `Lagrange` or `DG` functions are supported from legacy DOLFIN |
| 97 | +### Statement of Need |
| 98 | +As large-scale, long-running simulations on HPC clusters become more common, the need to store intermediate solutions is crucial. If a system crashes or a computational budget is exceeded, checkpoints allow the simulation to resume without restarting from scratch. `io4dolfinx` extends DOLFINx with this essential functionality. |
150 | 99 |
|
151 | | -- Reading meshes from the DOLFIN HDF5File-format |
152 | | -- Reading checkpoints from the DOLFIN HDF5File-format (one checkpoint per file only) |
153 | | -- Reading checkpoints from the DOLFIN XDMFFile-format (one checkpoint per file only, and only uses the `.h5` file) |
| 100 | +## Contributing |
154 | 101 |
|
155 | | -See the [API](./docs/api) for more information. |
| 102 | +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. |
156 | 103 |
|
157 | 104 | ## Testing |
158 | 105 |
|
159 | | -This library uses `pytest` for testing. |
160 | | -To execute the tests, one should first install the library and its dependencies, as listed above. |
161 | | -Then, can execute all tests by calling |
162 | | - |
163 | | -```bash |
164 | | -python3 -m pytest . |
165 | | -``` |
166 | | - |
167 | | -### Testing against data from legacy dolfin |
168 | | - |
169 | | -Some tests check the capability of reading data created with the legacy version of DOLFIN. |
170 | | -To create this dataset, start a docker container with legacy DOLFIN, for instance: |
171 | | - |
172 | | -```bash |
173 | | -docker run -ti -v $(pwd):/root/shared -w /root/s |
174 | | -hared --rm ghcr.io/scientificcomputing/fenics:2024-02-19 |
175 | | -``` |
176 | | - |
177 | | -Then, inside this container, call |
178 | | - |
179 | | -```bash |
180 | | -python3 ./tests/create_legacy_data.py --output-dir=legacy |
181 | | -``` |
182 | | - |
183 | | -### Testing against data from older versions of ADIOS4DOLFINx |
184 | | - |
185 | | -Some tests check the capability to read data generated by `adios4dolfinx<0.7.2`. |
186 | | -To generate data for these tests use the following commands: |
187 | | - |
188 | | -```bash |
189 | | -docker run -ti -v $(pwd):/root/shared -w /root/shared --rm ghcr.io/fenics/dolfinx/dolfinx:v0.7.3 |
190 | | -``` |
191 | | - |
192 | | -Then, inside the container, call |
193 | | - |
194 | | -```bash |
195 | | -python3 -m pip install adios4dolfinx==0.7.1 |
196 | | -python3 ./tests/create_legacy_checkpoint.py --output-dir=legacy_checkpoint |
197 | | -``` |
| 106 | +`io4dolfinx` includes a comprehensive test suite that ensures functionality across different backends and compatibility with legacy data formats, see the [Testing Guide](./docs/testing.md) for details. |
198 | 107 |
|
199 | | -## Long term plan |
200 | 108 |
|
201 | | -The long term plan is to get this library merged into DOLFINx (rewritten in C++ with appropriate Python-bindings). |
| 109 | +## LICENSE |
| 110 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments