Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/guide/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ The next two functions depend on the version of ADIOS2 and PyVista, not on DOLFI
(fn-resolve-adios-scope)=
## `resolve_adios_scope`

```{versionchanged} 0.7.0
Added `require_mpi`.
```

```python
fenicsx_compat.resolve_adios_scope(adios2) -> module
fenicsx_compat.resolve_adios_scope(adios2, require_mpi=True) -> module
```

Returns the namespace that holds ADIOS2's low-level Python bindings ({py:class}`ADIOS<adios2.bindings.ADIOS>`, `Mode`, ...). Raises `ImportError` if ADIOS2 was built without MPI.
Returns the namespace that holds ADIOS2's low-level Python bindings ({py:class}`ADIOS<adios2.bindings.ADIOS>`, `Mode`, ...). Raises `ImportError` if ADIOS2 was built without MPI, unless `require_mpi=False`. Pass `require_mpi=False` from code that also supports ADIOS2 without MPI, such as the wheels on PyPI, and handle that case itself.

| ADIOS2 | Low-level bindings |
|---|---|
Expand All @@ -47,7 +51,7 @@ adios2 = fenicsx_compat.resolve_adios_scope(fenicsx_compat.require_module("adios
adios = adios2.ADIOS(MPI.COMM_WORLD)
```

The MPI check uses `is_built_with_mpi`, which ADIOS2 2.9 does not have, so in practice it needs ADIOS2 2.10 or newer.
The MPI check uses `is_built_with_mpi`, which ADIOS2 2.9 does not have, so with the default `require_mpi=True` it needs ADIOS2 2.10 or newer.

(fn-pyvista-allow-snake-case)=
## `pyvista_allow_snake_case`
Expand Down
18 changes: 15 additions & 3 deletions src/fenicsx_compat/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,22 @@ def vtk_cell_type(cell_type: dolfinx.mesh.CellType, num_nodes: int) -> int:
return get_vtk_cell_type(cell_type, dolfinx.mesh.cell_dim(cell_type))


def resolve_adios_scope(adios2):
"""Resolve the ADIOS2 Python module scope, across the `adios2.bindings` submodule split."""
def resolve_adios_scope(adios2, require_mpi: bool = True):
"""Resolve the ADIOS2 Python module scope, across the `adios2.bindings` submodule split.

Args:
adios2: The imported `adios2` module.
require_mpi: Raise if ADIOS2 is built without MPI. Pass `False` for code
that also supports ADIOS2 without MPI.

Returns:
`adios2.bindings` if it exists, else `adios2`.

Raises:
ImportError: If `require_mpi` is `True` and ADIOS2 is built without MPI.
"""
scope = adios2.bindings if hasattr(adios2, "bindings") else adios2
if not scope.is_built_with_mpi:
if require_mpi and not scope.is_built_with_mpi:
raise ImportError("ADIOS2 must be built with MPI support")
return scope

Expand Down
11 changes: 11 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class FakeAdios2:
resolve_adios_scope(FakeAdios2())


def test_resolve_adios_scope_without_mpi_when_not_required():
class FakeScope:
is_built_with_mpi = False

class FakeAdios2:
bindings = FakeScope()

adios2 = FakeAdios2()
assert resolve_adios_scope(adios2, require_mpi=False) is adios2.bindings


def test_pyvista_allow_snake_case_sets_new_style_attribute():
class FakePyvista:
_VTK_SNAKE_CASE_STATE = "forbid"
Expand Down