diff --git a/src/io4dolfinx/backends/__init__.py b/src/io4dolfinx/backends/__init__.py index d9702f4..8f2726d 100644 --- a/src/io4dolfinx/backends/__init__.py +++ b/src/io4dolfinx/backends/__init__.py @@ -75,7 +75,7 @@ def get_default_backend_args(self, arguments: dict[str, Any] | None) -> dict[str def write_attributes( self, filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None, @@ -93,7 +93,7 @@ def write_attributes( def read_attributes( self, filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dict[str, Any]: @@ -112,7 +112,7 @@ def read_attributes( def read_timestamps( self, filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -131,7 +131,7 @@ def read_timestamps( def write_mesh( self, filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None, mode: FileMode, @@ -152,7 +152,7 @@ def write_mesh( def write_meshtags( self, filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None, ): @@ -168,7 +168,7 @@ def write_meshtags( def read_mesh_data( self, filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, read_from_partition: bool, backend_args: dict[str, Any] | None, @@ -189,7 +189,7 @@ def read_mesh_data( def read_meshtags_data( self, filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> MeshTagsData: @@ -208,7 +208,7 @@ def read_meshtags_data( def read_dofmap( self, filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dolfinx.graph.AdjacencyList: @@ -227,7 +227,7 @@ def read_dofmap( def read_dofs( self, filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -248,7 +248,7 @@ def read_dofs( """ def read_cell_perms( - self, comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + self, comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -267,7 +267,7 @@ def read_cell_perms( def write_function( self, filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -285,7 +285,7 @@ def write_function( """ def read_legacy_mesh( - self, filename: Path | str, comm: MPI.Intracomm, group: str + self, filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -320,7 +320,7 @@ def snapshot_checkpoint( def read_hdf5_array( self, - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None, @@ -344,7 +344,7 @@ def read_point_data( self, filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -362,7 +362,7 @@ def read_point_data( ... def read_function_names( - self, filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + self, filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -380,7 +380,7 @@ def read_cell_data( self, filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -403,7 +403,7 @@ def write_data( self, filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/adios2/backend.py b/src/io4dolfinx/backends/adios2/backend.py index 0f547bd..a4024cd 100644 --- a/src/io4dolfinx/backends/adios2/backend.py +++ b/src/io4dolfinx/backends/adios2/backend.py @@ -50,7 +50,7 @@ def convert_file_mode(mode: FileMode) -> adios2.Mode: # type: ignore[override] def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None = None, @@ -86,7 +86,7 @@ def write_attributes( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None, ) -> dict[str, np.ndarray]: @@ -122,7 +122,7 @@ def read_attributes( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None = None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -169,7 +169,7 @@ def read_timestamps( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None = None, mode: FileMode = FileMode.write, @@ -277,7 +277,7 @@ def write_mesh( def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None = 0.0, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None, @@ -409,7 +409,7 @@ def read_mesh_data( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None = None, ): @@ -462,7 +462,7 @@ def write_meshtags( def read_meshtags_data( - filename: str | Path, comm: MPI.Intracomm, name: str, backend_args: dict[str, Any] | None = None + filename: str | Path, comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None ) -> MeshTagsData: """Read mesh tags from file. @@ -600,7 +600,7 @@ def read_meshtags_data( def read_dofmap( - filename: str | Path, comm: MPI.Intracomm, name: str, backend_args: dict[str, Any] | None = None + filename: str | Path, comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None ) -> dolfinx.graph.AdjacencyList: """Read the dofmap of a function with a given name. @@ -641,7 +641,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None = None, @@ -698,7 +698,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None = None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None = None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -733,7 +733,7 @@ def read_cell_perms( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None = None, @@ -758,7 +758,7 @@ def read_hdf5_array( def write_function( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float = 0.0, mode: FileMode = FileMode.append, @@ -854,7 +854,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -970,7 +970,7 @@ def snapshot_checkpoint( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -988,7 +988,7 @@ def read_function_names( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -1010,7 +1010,7 @@ def read_point_data( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -1033,7 +1033,7 @@ def read_cell_data( def write_data( filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/adios2/helpers.py b/src/io4dolfinx/backends/adios2/helpers.py index 9f7909f..be2b912 100644 --- a/src/io4dolfinx/backends/adios2/helpers.py +++ b/src/io4dolfinx/backends/adios2/helpers.py @@ -12,12 +12,11 @@ from mpi4py import MPI import adios2 -import dolfinx.cpp.graph import dolfinx.graph import numpy as np import numpy.typing as npt -from io4dolfinx.utils import compute_local_range, valid_function_types +from ...utils import compute_local_range, valid_function_types def resolve_adios_scope(adios2): @@ -60,7 +59,7 @@ def ADIOSFile( engine: str, mode: adios2.Mode, io_name: str, - comm: MPI.Intracomm | None = None, + comm: MPI.Comm | None = None, ): io = adios.DeclareIO(io_name) io.SetEngine(engine) @@ -118,7 +117,7 @@ def check_variable_exists( def read_adjacency_list( adios: adios2.ADIOS, - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, data_name: str, offsets_name: str, @@ -221,7 +220,7 @@ def read_array( filename: Path | str, array_name: str, engine: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float = 0.0, time_name: str = "", legacy: bool = False, diff --git a/src/io4dolfinx/backends/exodus/backend.py b/src/io4dolfinx/backends/exodus/backend.py index ab2e4df..06a7e5e 100644 --- a/src/io4dolfinx/backends/exodus/backend.py +++ b/src/io4dolfinx/backends/exodus/backend.py @@ -95,7 +95,7 @@ def convert_file_mode(mode: FileMode) -> str: def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None = None, @@ -114,7 +114,7 @@ def write_attributes( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None, ) -> dict[str, Any]: @@ -149,7 +149,7 @@ def snapshot_checkpoint( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None, @@ -173,7 +173,7 @@ def read_hdf5_array( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None = None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -194,7 +194,7 @@ def read_timestamps( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None = None, mode: FileMode = FileMode.write, @@ -273,7 +273,7 @@ def _extract_connectivity_data( def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None = 0.0, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None, @@ -371,7 +371,7 @@ def read_mesh_data( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None = None, ): @@ -388,7 +388,7 @@ def write_meshtags( def read_meshtags_data( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None, ) -> MeshTagsData: @@ -506,7 +506,7 @@ def read_meshtags_data( def read_dofmap( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dolfinx.graph.AdjacencyList: @@ -526,7 +526,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -549,7 +549,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -570,7 +570,7 @@ def read_cell_perms( def write_function( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -591,7 +591,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -613,7 +613,7 @@ def read_legacy_mesh( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -669,7 +669,7 @@ def read_point_data( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -738,7 +738,7 @@ def read_cell_data( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -762,7 +762,7 @@ def read_function_names( def write_data( filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/h5py/backend.py b/src/io4dolfinx/backends/h5py/backend.py index 31c56c7..aa8e4bc 100644 --- a/src/io4dolfinx/backends/h5py/backend.py +++ b/src/io4dolfinx/backends/h5py/backend.py @@ -79,7 +79,7 @@ def convert_file_mode(mode: FileMode) -> str: def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None = None, @@ -105,7 +105,7 @@ def write_attributes( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None, ) -> dict[str, Any]: @@ -128,7 +128,7 @@ def read_attributes( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None = None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -155,7 +155,7 @@ def read_timestamps( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None = None, mode: FileMode = FileMode.write, @@ -237,7 +237,7 @@ def write_mesh( def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None = 0.0, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None, @@ -319,7 +319,7 @@ def read_mesh_data( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None = None, ): @@ -366,7 +366,7 @@ def write_meshtags( def read_meshtags_data( - filename: str | Path, comm: MPI.Intracomm, name: str, backend_args: dict[str, Any] | None = None + filename: str | Path, comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None = None ) -> MeshTagsData: """Read mesh tags from file. @@ -415,7 +415,7 @@ def read_meshtags_data( def read_dofmap( - filename: str | Path, comm: MPI.Intracomm, name: str, backend_args: dict[str, Any] | None + filename: str | Path, comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None ) -> dolfinx.graph.AdjacencyList: """Read the dofmap of a function with a given name. @@ -470,7 +470,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -515,7 +515,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -545,7 +545,7 @@ def read_cell_perms( def write_function( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -625,7 +625,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -677,7 +677,7 @@ def read_legacy_mesh( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None = None, @@ -739,7 +739,7 @@ def snapshot_checkpoint( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -767,7 +767,7 @@ def read_function_names( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -789,7 +789,7 @@ def read_point_data( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -812,7 +812,7 @@ def read_cell_data( def write_data( filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/pyvista/backend.py b/src/io4dolfinx/backends/pyvista/backend.py index 0dcf0b7..261c47a 100644 --- a/src/io4dolfinx/backends/pyvista/backend.py +++ b/src/io4dolfinx/backends/pyvista/backend.py @@ -117,7 +117,7 @@ def get_default_backend_args(arguments: dict[str, Any] | None) -> dict[str, Any] def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None = None, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None, @@ -197,7 +197,7 @@ def read_mesh_data( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -255,7 +255,7 @@ def read_point_data( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -301,7 +301,7 @@ def read_cell_data( def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None, @@ -320,7 +320,7 @@ def write_attributes( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dict[str, Any]: @@ -340,7 +340,7 @@ def read_attributes( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -359,7 +359,7 @@ def read_timestamps( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -394,7 +394,7 @@ def read_function_names( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None, mode: FileMode, @@ -416,7 +416,7 @@ def write_mesh( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None, ): @@ -433,7 +433,7 @@ def write_meshtags( def read_meshtags_data( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> MeshTagsData: @@ -453,7 +453,7 @@ def read_meshtags_data( def read_dofmap( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dolfinx.graph.AdjacencyList: @@ -473,7 +473,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -496,7 +496,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -516,7 +516,7 @@ def read_cell_perms( def write_function( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -537,7 +537,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -574,7 +574,7 @@ def snapshot_checkpoint( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None, @@ -599,7 +599,7 @@ def read_hdf5_array( def write_data( filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/vtkhdf/backend.py b/src/io4dolfinx/backends/vtkhdf/backend.py index e0c4b76..e4f1737 100644 --- a/src/io4dolfinx/backends/vtkhdf/backend.py +++ b/src/io4dolfinx/backends/vtkhdf/backend.py @@ -126,7 +126,7 @@ def _get_time_index(hdf: h5py.Group, time: float | str, filename: str | Path) -> def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, read_from_partition: bool, backend_args: dict[str, Any] | None, @@ -236,7 +236,7 @@ def read_mesh_data( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -285,7 +285,7 @@ def read_point_data( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -335,7 +335,7 @@ def read_cell_data( def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None, @@ -354,7 +354,7 @@ def write_attributes( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dict[str, Any]: @@ -374,7 +374,7 @@ def read_attributes( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -417,7 +417,7 @@ def read_timestamps( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -497,7 +497,7 @@ def _compute_append_slice( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None, mode: FileMode, @@ -744,7 +744,7 @@ def write_mesh( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None, ): @@ -946,7 +946,7 @@ def write_meshtags( def read_meshtags_data( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> MeshTagsData: @@ -985,7 +985,7 @@ def read_meshtags_data( def read_dofmap( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dolfinx.graph.AdjacencyList: @@ -1005,7 +1005,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -1028,7 +1028,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -1048,7 +1048,7 @@ def read_cell_perms( def write_function( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -1069,7 +1069,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -1106,7 +1106,7 @@ def snapshot_checkpoint( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None, @@ -1131,7 +1131,7 @@ def read_hdf5_array( def write_data( filename: Path | str, array_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/backends/xdmf/backend.py b/src/io4dolfinx/backends/xdmf/backend.py index 8c4148e..1192240 100644 --- a/src/io4dolfinx/backends/xdmf/backend.py +++ b/src/io4dolfinx/backends/xdmf/backend.py @@ -59,7 +59,7 @@ def get_default_backend_args(arguments: dict[str, Any] | None) -> dict[str, Any] def read_mesh_data( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, read_from_partition: bool, backend_args: dict[str, Any] | None, @@ -94,7 +94,7 @@ def read_mesh_data( def read_point_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: float | str | None, backend_args: dict[str, Any] | None, ) -> tuple[np.ndarray, int]: @@ -151,7 +151,7 @@ def read_point_data( def read_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dict[str, Any]: @@ -171,7 +171,7 @@ def read_attributes( def read_timestamps( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, function_name: str, backend_args: dict[str, Any] | None, ) -> npt.NDArray[np.float64 | str]: # type: ignore[type-var] @@ -201,7 +201,7 @@ def read_timestamps( def write_attributes( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, attributes: dict[str, np.ndarray], backend_args: dict[str, Any] | None, @@ -220,7 +220,7 @@ def write_attributes( def write_mesh( filename: Path | str, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh: MeshData, backend_args: dict[str, Any] | None, mode: FileMode, @@ -242,7 +242,7 @@ def write_mesh( def write_meshtags( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, data: MeshTagsData, backend_args: dict[str, Any] | None, ): @@ -259,7 +259,7 @@ def write_meshtags( def read_meshtags_data( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> MeshTagsData: @@ -279,7 +279,7 @@ def read_meshtags_data( def read_dofmap( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, backend_args: dict[str, Any] | None, ) -> dolfinx.graph.AdjacencyList: @@ -299,7 +299,7 @@ def read_dofmap( def read_dofs( filename: str | Path, - comm: MPI.Intracomm, + comm: MPI.Comm, name: str, time: float, backend_args: dict[str, Any] | None, @@ -322,7 +322,7 @@ def read_dofs( def read_cell_perms( - comm: MPI.Intracomm, filename: Path | str, backend_args: dict[str, Any] | None + comm: MPI.Comm, filename: Path | str, backend_args: dict[str, Any] | None ) -> npt.NDArray[np.uint32]: """ Read cell permutation from file with given communicator, @@ -342,7 +342,7 @@ def read_cell_perms( def write_function( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float, mode: FileMode, @@ -363,7 +363,7 @@ def write_function( def read_legacy_mesh( - filename: Path | str, comm: MPI.Intracomm, group: str + filename: Path | str, comm: MPI.Comm, group: str ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.floating], str | None]: """Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file. @@ -400,7 +400,7 @@ def snapshot_checkpoint( def read_hdf5_array( - comm: MPI.Intracomm, + comm: MPI.Comm, filename: Path | str, group: str, backend_args: dict[str, Any] | None, @@ -423,7 +423,7 @@ def read_hdf5_array( def read_function_names( - filename: Path | str, comm: MPI.Intracomm, backend_args: dict[str, Any] | None + filename: Path | str, comm: MPI.Comm, backend_args: dict[str, Any] | None ) -> list[str]: """Read all function names from a file. @@ -455,7 +455,7 @@ def read_function_names( def read_cell_data( filename: Path | str, name: str, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, backend_args: dict[str, Any] | None, ) -> tuple[npt.NDArray[np.int64], np.ndarray]: @@ -545,7 +545,7 @@ def read_cell_data( def write_data( filename: Path | str, point_data: ArrayData, - comm: MPI.Intracomm, + comm: MPI.Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None, diff --git a/src/io4dolfinx/checkpointing.py b/src/io4dolfinx/checkpointing.py index 30d1bd1..a128ef6 100644 --- a/src/io4dolfinx/checkpointing.py +++ b/src/io4dolfinx/checkpointing.py @@ -168,6 +168,7 @@ def write_meshtags( local_values = meshtags.values[: len(local_tag_entities)] num_saved_tag_entities = len(local_tag_entities) + assert isinstance(mesh.comm, MPI.Intracomm) local_start = mesh.comm.exscan(num_saved_tag_entities, op=MPI.SUM) local_start = local_start if mesh.comm.rank != 0 else 0 global_num_tag_entities = mesh.comm.allreduce(num_saved_tag_entities, op=MPI.SUM) @@ -376,8 +377,9 @@ def read_function( unique_owners, owner_count = np.unique(owners, return_counts=True) # FIXME: In C++ use NBX to find neighbourhood + assert isinstance(V.mesh.comm, MPI.Intracomm) sub_comm = V.mesh.comm.Create_dist_graph( - [V.mesh.comm.rank], [len(unique_owners)], unique_owners, reorder=False + [V.mesh.comm.rank], [len(unique_owners)], unique_owners.tolist(), reorder=False ) source, dest, _ = sub_comm.Get_dist_neighbors() sub_comm.Free() @@ -605,7 +607,7 @@ def write_function( dofmap_range=dofmap_imap.local_range, global_dofs_in_dofmap=dofmap_imap.size_global, values=values[:num_dofs_local].copy(), - dof_range=local_dof_range, + dof_range=(local_dof_range[0], local_dof_range[1]), num_dofs_global=num_dofs_global, name=name or u.name, ) diff --git a/src/io4dolfinx/comm_helpers.py b/src/io4dolfinx/comm_helpers.py index cf954aa..8a4b62e 100644 --- a/src/io4dolfinx/comm_helpers.py +++ b/src/io4dolfinx/comm_helpers.py @@ -29,7 +29,7 @@ def send_dofmap_and_recv_values( - comm: MPI.Intracomm, + comm: MPI.Comm, source_ranks: npt.NDArray[np.int32], dest_ranks: npt.NDArray[np.int32], output_owners: npt.NDArray[np.int32], @@ -78,6 +78,7 @@ def send_dofmap_and_recv_values( # Send sizes to create data structures for receiving from NeighAlltoAllv recv_size = np.zeros(len(source_ranks), dtype=np.int32) + assert isinstance(comm, MPI.Intracomm) mesh_to_data_comm = comm.Create_dist_graph_adjacent( source_ranks.tolist(), dest_ranks.tolist(), reorder=False ) @@ -132,7 +133,7 @@ def send_and_recv_cell_perm( cells: npt.NDArray[np.int64], perms: npt.NDArray[np.uint32], cell_owners: npt.NDArray[np.int32], - comm: MPI.Intracomm, + comm: MPI.Comm, ) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.uint32]]: """ Send global cell index and permutation to corresponding entry in `dest_ranks`. @@ -146,7 +147,7 @@ def send_and_recv_cell_perm( dest_ranks, _dest_size = np.unique(cell_owners, return_counts=True) dest_size = _dest_size.astype(np.int32) del _dest_size - + assert isinstance(comm, MPI.Intracomm) mesh_to_data = comm.Create_dist_graph( [comm.rank], [len(dest_ranks)], dest_ranks.tolist(), reorder=False ) @@ -189,7 +190,7 @@ def send_and_recv_cell_perm( def send_dofs_and_recv_values( input_dofmap: npt.NDArray[np.int64], dofmap_owners: npt.NDArray[np.int32], - comm: MPI.Intracomm, + comm: MPI.Comm, input_array: npt.NDArray[valid_function_types], array_start: int, ): @@ -207,6 +208,7 @@ def send_dofs_and_recv_values( dest_size = _dest_size.astype(np.int32) del _dest_size + assert isinstance(comm, MPI.Intracomm) dofmap_to_values = comm.Create_dist_graph( [comm.rank], [len(dest_ranks)], dest_ranks.tolist(), reorder=False ) diff --git a/src/io4dolfinx/original_checkpoint.py b/src/io4dolfinx/original_checkpoint.py index 45d7e94..fe3631b 100644 --- a/src/io4dolfinx/original_checkpoint.py +++ b/src/io4dolfinx/original_checkpoint.py @@ -52,6 +52,7 @@ def create_original_mesh_data(mesh: dolfinx.mesh.Mesh) -> MeshData: cell_destinations, _send_cells_per_proc = np.unique(output_cell_owner, return_counts=True) send_cells_per_proc = _send_cells_per_proc.astype(np.int32) del _send_cells_per_proc + assert isinstance(mesh.comm, MPI.Intracomm) cell_to_output_comm = mesh.comm.Create_dist_graph( [mesh.comm.rank], [len(cell_destinations)], @@ -232,6 +233,7 @@ def create_function_data_on_original_mesh( cell_destinations, _send_cells_per_proc = np.unique(output_cell_owner, return_counts=True) send_cells_per_proc = _send_cells_per_proc.astype(np.int32) del _send_cells_per_proc + assert isinstance(mesh.comm, MPI.Intracomm) cell_to_output_comm = mesh.comm.Create_dist_graph( [mesh.comm.rank], [len(cell_destinations)], @@ -290,6 +292,7 @@ def create_function_data_on_original_mesh( # Convert imap index to global index imap_global = dofmap.index_map.local_to_global(dmap_loc) dofmap_global = (imap_global * index_map_bs + dmap_rem).reshape(unrolled_dofmap.shape) + assert len(dofmap_global.shape) >= 2 num_dofs_per_cell = dofmap_global.shape[1] dofmap_insert_position = unroll_insert_position(cell_insert_position, num_dofs_per_cell) diff --git a/src/io4dolfinx/readers.py b/src/io4dolfinx/readers.py index 0252d8e..0de359a 100644 --- a/src/io4dolfinx/readers.py +++ b/src/io4dolfinx/readers.py @@ -60,7 +60,7 @@ def map_dofmap(dofmap: dolfinx.graph.AdjacencyList, bs: int | np.int64) -> npt.N def send_cells_and_receive_dofmap_index( filename: pathlib.Path, - comm: MPI.Intracomm, + comm: MPI.Comm, source_ranks: npt.NDArray[np.int32], dest_ranks: npt.NDArray[np.int32], dest_size: npt.NDArray[np.int32], @@ -80,6 +80,7 @@ def send_cells_and_receive_dofmap_index( check_file_exists(filename) recv_size = np.zeros(len(source_ranks), dtype=np.int32) + assert isinstance(comm, MPI.Intracomm) mesh_to_data_comm = comm.Create_dist_graph_adjacent( source_ranks.tolist(), dest_ranks.tolist(), reorder=False ) @@ -148,7 +149,7 @@ def send_cells_and_receive_dofmap_index( def read_mesh_from_legacy_h5( filename: pathlib.Path, - comm: MPI.Intracomm, + comm: MPI.Comm, group: str, cell_type: str = "tetrahedron", backend: str | None = None, @@ -224,7 +225,7 @@ def read_mesh_from_legacy_h5( def read_function_from_legacy_h5( filename: pathlib.Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: dolfinx.fem.Function, group: str = "mesh", step: typing.Optional[int] = None, @@ -279,8 +280,9 @@ def read_function_from_legacy_h5( unique_owners, owner_count = np.unique(owners, return_counts=True) # FIXME: In C++ use NBX to find neighbourhood + assert isinstance(mesh.comm, MPI.Intracomm) _tmp_comm = mesh.comm.Create_dist_graph( - [mesh.comm.rank], [len(unique_owners)], unique_owners, reorder=False + [mesh.comm.rank], [len(unique_owners)], unique_owners.tolist(), reorder=False ) source, dest, _ = _tmp_comm.Get_dist_neighbors() _tmp_comm.Free() diff --git a/src/io4dolfinx/utils.py b/src/io4dolfinx/utils.py index ef410cd..17731cc 100644 --- a/src/io4dolfinx/utils.py +++ b/src/io4dolfinx/utils.py @@ -112,7 +112,7 @@ def unroll_insert_position( return unrolled_ip -def compute_local_range(comm: MPI.Intracomm, N: int | np.int64): +def compute_local_range(comm: MPI.Comm, N: int | np.int64): """ Divide a set of `N` objects into `M` partitions, where `M` is the size of the MPI communicator `comm`. @@ -134,7 +134,7 @@ def compute_local_range(comm: MPI.Intracomm, N: int | np.int64): def index_owner( - comm: MPI.Intracomm, indices: npt.NDArray[np.int64], N: int | np.int64 + comm: MPI.Comm, indices: npt.NDArray[np.int64], N: int | np.int64 ) -> npt.NDArray[np.int32]: """ Find which rank (local to comm) which owns an `index`, given that diff --git a/src/io4dolfinx/writers.py b/src/io4dolfinx/writers.py index f7f0cda..67d8131 100644 --- a/src/io4dolfinx/writers.py +++ b/src/io4dolfinx/writers.py @@ -117,7 +117,7 @@ def prepare_meshdata_for_storage(mesh: dolfinx.mesh.Mesh, store_partition_info: def write_mesh( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, mesh_data: MeshData, time: float = 0.0, mode: FileMode = FileMode.write, @@ -143,7 +143,7 @@ def write_mesh( def write_function( filename: Path, - comm: MPI.Intracomm, + comm: MPI.Comm, u: FunctionData, time: float = 0.0, mode: FileMode = FileMode.append,