| 1 |
--- |
| 2 |
jupytext: |
| 3 |
formats: md:myst |
| 4 |
text_representation: |
| 5 |
extension: .md |
| 6 |
format_name: myst |
| 7 |
kernelspec: |
| 8 |
display_name: Python 3 |
| 9 |
language: python |
| 10 |
name: python3 |
| 11 |
--- |
| 12 |
|
| 13 |
# Migration Guide: Transitions to `io4dolfinx` |
| 14 |
|
| 15 |
|
| 16 |
This guide outlines the necessary steps to transition your code from {py:mod}`io4dolfinx` new API introduced in `io4dolfinx`. |
| 17 |
|
| 18 |
## Major Changes |
| 19 |
|
| 20 |
The library has undergone a major refactor to support multiple IO backends. |
| 21 |
**{py:mod}`io4dolfinx` now supports both [ADIOS2](https://adios2.readthedocs.io/en/latest/) and [h5py](https://docs.h5py.org/en/stable/) backends.** |
| 22 |
|
| 23 |
This allows users to choose between the high-performance, adaptable ADIOS2 framework and the standard HDF5 format via {py:class}`h5py.File`, all using the same high-level API. |
| 24 |
It also opens the door for new backends in the future. |
| 25 |
|
| 26 |
### Key API Updates |
| 27 |
|
| 28 |
1. **Backend Agnosticism**: You can now switch between {py:class}`adios2.ADIOS` (default) and {py:class}`h5py.File` by passing a `backend` argument. |
| 29 |
2. **Engine Configuration**: The explicit `engine` argument (e.g., "BP4", "HDF5", see ADIOS2 [Engine Types](https://adios2.readthedocs.io/en/latest/engines/engines.html)) has been removed from function signatures. It is now passed via a dictionary `backend_args`. This is because different backends may have different engine options. For example {py:class}`adios2.ADIOS` supports "BP4" and "HDF5", while `h5py` does not use engines. |
| 30 |
|
| 31 |
|
| 32 |
### Example Transition |
| 33 |
|
| 34 |
#### Writing a Mesh |
| 35 |
|
| 36 |
`````{tab-set} |
| 37 |
````{tab-item} Old API |
| 38 |
```python |
| 39 |
import io4dolfinx |
| 40 |
io4dolfinx.write_mesh("mesh.bp", mesh, engine="BP4") |
| 41 |
``` |
| 42 |
```` |
| 43 |
|
| 44 |
````{tab-item} New API (ADIOS2 Backend) |
| 45 |
```python |
| 46 |
import io4dolfinx |
| 47 |
io4dolfinx.write_mesh("mesh.bp", mesh, backend="adios2", backend_args={"engine": "BP4"}) |
| 48 |
``` |
| 49 |
```` |
| 50 |
|
| 51 |
````{tab-item} New API (h5py Backend) |
| 52 |
```python |
| 53 |
import io4dolfinx |
| 54 |
io4dolfinx.write_mesh("mesh.bp", mesh, backend="h5py") |
| 55 |
``` |
| 56 |
```` |
| 57 |
|
| 58 |
````` |
| 59 |
|
| 60 |
|
| 61 |
#### Writing a Function |
| 62 |
|
| 63 |
`````{tab-set} |
| 64 |
````{tab-item} Old API |
| 65 |
```python |
| 66 |
import io4dolfinx |
| 67 |
io4dolfinx.write_function("solution.bp", u, time=0.0, engine="BP4") |
| 68 |
``` |
| 69 |
```` |
| 70 |
````{tab-item} New API (ADIOS2 Backend) |
| 71 |
```python |
| 72 |
import io4dolfinx |
| 73 |
io4dolfinx.write_function("solution.bp", u, time=0.0, backend="adios2", backend_args={"engine": "BP4"}) |
| 74 |
``` |
| 75 |
```` |
| 76 |
````{tab-item} New API (h5py Backend) |
| 77 |
```python |
| 78 |
import io4dolfinx |
| 79 |
io4dolfinx.write_function("solution.bp", u, time=0.0, backend="h5py") |
| 80 |
``` |
| 81 |
```` |
| 82 |
````` |