io4dolfinx 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. {io4dolfinx-2.2.0/src/io4dolfinx.egg-info → io4dolfinx-2.3.0}/PKG-INFO +17 -2
  2. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/README.md +16 -1
  3. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/pyproject.toml +2 -2
  4. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf/backend.py +8 -5
  5. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/checkpointing.py +2 -3
  6. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/comm_helpers.py +1 -1
  7. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/utils.py +21 -14
  8. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0/src/io4dolfinx.egg-info}/PKG-INFO +17 -2
  9. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_checkpointing.py +41 -0
  10. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_numpy_vectorization.py +56 -1
  11. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_vtkhdf_compression.py +37 -2
  12. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/LICENSE +0 -0
  13. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/setup.cfg +0 -0
  14. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/__init__.py +0 -0
  15. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/ascii_helpers.py +0 -0
  16. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/__init__.py +0 -0
  17. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/__init__.py +0 -0
  18. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/backend.py +0 -0
  19. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/helpers.py +0 -0
  20. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2_serial/__init__.py +0 -0
  21. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2_serial/backend.py +0 -0
  22. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/exodus/__init__.py +0 -0
  23. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/exodus/backend.py +0 -0
  24. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/gmsh/__init__.py +0 -0
  25. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/gmsh/backend.py +0 -0
  26. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/__init__.py +0 -0
  27. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/backend.py +0 -0
  28. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/storage.py +0 -0
  29. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py_serial/__init__.py +0 -0
  30. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py_serial/backend.py +0 -0
  31. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/med/__init__.py +0 -0
  32. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/med/backend.py +0 -0
  33. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/__init__.py +0 -0
  34. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/backend.py +0 -0
  35. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/helpers.py +0 -0
  36. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/__init__.py +0 -0
  37. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/backend.py +0 -0
  38. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/helpers.py +0 -0
  39. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/__init__.py +0 -0
  40. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/backend.py +0 -0
  41. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/helpers.py +0 -0
  42. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/__init__.py +0 -0
  43. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/backend.py +0 -0
  44. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/helpers.py +0 -0
  45. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/serial.py +0 -0
  46. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtk_cell_types.py +0 -0
  47. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf/__init__.py +0 -0
  48. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf_serial/__init__.py +0 -0
  49. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf_serial/backend.py +0 -0
  50. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/xdmf/__init__.py +0 -0
  51. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/xdmf/backend.py +0 -0
  52. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/converter.py +0 -0
  53. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/format.py +0 -0
  54. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/original_checkpoint.py +0 -0
  55. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/py.typed +0 -0
  56. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/readers.py +0 -0
  57. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/snapshot.py +0 -0
  58. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/structures.py +0 -0
  59. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/submesh.py +0 -0
  60. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx/writers.py +0 -0
  61. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/SOURCES.txt +0 -0
  62. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/dependency_links.txt +0 -0
  63. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/entry_points.txt +0 -0
  64. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/requires.txt +0 -0
  65. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/top_level.txt +0 -0
  66. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_attributes.py +0 -0
  67. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_backends.py +0 -0
  68. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_checkpointing_vector.py +0 -0
  69. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_converter.py +0 -0
  70. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_exodus.py +0 -0
  71. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_format_version.py +0 -0
  72. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_geometry_dofmap_reconstruction.py +0 -0
  73. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_gmsh.py +0 -0
  74. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_h5py_compression.py +0 -0
  75. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_legacy_readers.py +0 -0
  76. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_med.py +0 -0
  77. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_mesh_writer.py +0 -0
  78. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_meshtags.py +0 -0
  79. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_nastran.py +0 -0
  80. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_opencarp.py +0 -0
  81. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_openfoam.py +0 -0
  82. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_original_checkpoint.py +0 -0
  83. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_pyvista.py +0 -0
  84. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_snapshot_checkpoint.py +0 -0
  85. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_submesh.py +0 -0
  86. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_version.py +0 -0
  87. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_vtkhdf.py +0 -0
  88. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_write_data_input_order.py +0 -0
  89. {io4dolfinx-2.2.0 → io4dolfinx-2.3.0}/tests/test_xdmf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: io4dolfinx
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Checkpointing functionality for DOLFINx meshes/functions with ADIOS2
5
5
  Author-email: "Jørgen S. Dokken" <dokken@simula.no>, "Henrik N.T. Finsberg" <henriknf@simula.no>
6
6
  License: Copyright 2023 Jørgen S. Dokken, Henrik N.T. Finsberg and Simula Research Laboratory
@@ -153,6 +153,8 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
153
153
  ## Releasing
154
154
  Versions are managed with [bump-my-version](https://callowayproject.github.io/bump-my-version/), configured in `pyproject.toml`. Between releases the version is a development version, `X.Y.Z.devN`; a release drops the suffix. Each bump commits the version change, so start from a clean working tree.
155
155
 
156
+ ### Releasing the development version
157
+
156
158
  To release the current development version, e.g. `2.1.0.dev0`, and start the next one:
157
159
 
158
160
  ```bash
@@ -162,7 +164,20 @@ bump-my-version bump minor --no-tag # 2.1.0 -> 2.2.0.dev0
162
164
 
163
165
  For a patch release of 2.1, bump `patch` instead of `minor` (`2.1.0 -> 2.1.1.dev0`), then `release` (`2.1.1.dev0 -> 2.1.1`). `bump-my-version show-bump` previews what each bump gives.
164
166
 
165
- The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`) as `v2.1.0`, for instance by creating a GitHub release from it.
167
+ ### Patch release of the previous version
168
+
169
+ To release `main` as a patch of the previous release, e.g. `2.0.1` while `main` is at `2.1.0.dev0`, set the version directly and then restore the development version:
170
+
171
+ ```bash
172
+ bump-my-version bump --new-version 2.0.1 --no-tag # 2.1.0.dev0 -> 2.0.1
173
+ bump-my-version bump minor --no-tag # 2.0.1 -> 2.1.0.dev0
174
+ ```
175
+
176
+ This releases everything on `main`, so use it only if `main` holds nothing but fixes since `v2.0.0`. The first bump warns that `2.1.0.dev0` does not match the last tag, `v2.0.0`; this is expected, as development versions are not tagged.
177
+
178
+ ### Tagging
179
+
180
+ The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`, or `Bump version: 2.1.0.dev0 → 2.0.1`) as `v2.1.0` or `v2.0.1`, for instance by creating a GitHub release from it.
166
181
 
167
182
  Releasing a new minor version also adds it to `.github/docs-versions.toml`, which lists the versions on the documentation website, built in the DOLFINx image of the previous one; edit that image afterwards if a newer DOLFINx release should be used. A patch release needs no entry, as each minor version is built from its newest tag.
168
183
 
@@ -114,6 +114,8 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
114
114
  ## Releasing
115
115
  Versions are managed with [bump-my-version](https://callowayproject.github.io/bump-my-version/), configured in `pyproject.toml`. Between releases the version is a development version, `X.Y.Z.devN`; a release drops the suffix. Each bump commits the version change, so start from a clean working tree.
116
116
 
117
+ ### Releasing the development version
118
+
117
119
  To release the current development version, e.g. `2.1.0.dev0`, and start the next one:
118
120
 
119
121
  ```bash
@@ -123,7 +125,20 @@ bump-my-version bump minor --no-tag # 2.1.0 -> 2.2.0.dev0
123
125
 
124
126
  For a patch release of 2.1, bump `patch` instead of `minor` (`2.1.0 -> 2.1.1.dev0`), then `release` (`2.1.1.dev0 -> 2.1.1`). `bump-my-version show-bump` previews what each bump gives.
125
127
 
126
- The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`) as `v2.1.0`, for instance by creating a GitHub release from it.
128
+ ### Patch release of the previous version
129
+
130
+ To release `main` as a patch of the previous release, e.g. `2.0.1` while `main` is at `2.1.0.dev0`, set the version directly and then restore the development version:
131
+
132
+ ```bash
133
+ bump-my-version bump --new-version 2.0.1 --no-tag # 2.1.0.dev0 -> 2.0.1
134
+ bump-my-version bump minor --no-tag # 2.0.1 -> 2.1.0.dev0
135
+ ```
136
+
137
+ This releases everything on `main`, so use it only if `main` holds nothing but fixes since `v2.0.0`. The first bump warns that `2.1.0.dev0` does not match the last tag, `v2.0.0`; this is expected, as development versions are not tagged.
138
+
139
+ ### Tagging
140
+
141
+ The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`, or `Bump version: 2.1.0.dev0 → 2.0.1`) as `v2.1.0` or `v2.0.1`, for instance by creating a GitHub release from it.
127
142
 
128
143
  Releasing a new minor version also adds it to `.github/docs-versions.toml`, which lists the versions on the documentation website, built in the DOLFINx image of the previous one; edit that image afterwards if a newer DOLFINx release should be used. A patch release needs no entry, as each minor version is built from its newest tag.
129
144
 
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
11
11
 
12
12
  [project]
13
13
  name = "io4dolfinx"
14
- version = "2.2.0"
14
+ version = "2.3.0"
15
15
  description = "Checkpointing functionality for DOLFINx meshes/functions with ADIOS2"
16
16
  authors = [
17
17
  { name = "Jørgen S. Dokken", email = "dokken@simula.no" },
@@ -141,7 +141,7 @@ tag = true
141
141
  sign_tags = false
142
142
  tag_name = "v{new_version}"
143
143
  tag_message = "Bump version: {current_version} → {new_version}"
144
- current_version = "2.2.0"
144
+ current_version = "2.3.0"
145
145
  # X.Y.Z.devN while developing, X.Y.Z when released
146
146
  parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>dev)(?P<pre_n>\d+))?'
147
147
  serialize = ["{major}.{minor}.{patch}.{release}{pre_n}", "{major}.{minor}.{patch}"]
@@ -45,6 +45,8 @@ _lagrange_variant_attr = "LagrangeVariant"
45
45
  #: first write share the data of the first write, and the offsets alone cannot tell at
46
46
  #: which step that was. The writer needs it to fill in steps written out of order.
47
47
  _written_steps = "Steps"
48
+ #: Chunk length of the per-step datasets (time stamps, offsets, written steps).
49
+ _step_chunk = 1024
48
50
 
49
51
 
50
52
  def _array_metadata_group(mesh_name: str, extension: str, name: str) -> str:
@@ -403,7 +405,7 @@ def _create_temporal_record(h5file: h5py.File, record: str, written_steps: np.nd
403
405
  h5file[record].resize(written_steps.shape)
404
406
  h5file[record][:] = written_steps
405
407
  else:
406
- h5file.create_dataset(record, data=written_steps, chunks=True, maxshape=(None,))
408
+ h5file.create_dataset(record, data=written_steps, chunks=(_step_chunk,), maxshape=(None,))
407
409
 
408
410
 
409
411
  def _get_time_index(hdf: h5py.Group, time: float | str, filename: str | Path) -> int:
@@ -772,15 +774,16 @@ def _create_dataset(
772
774
  Args:
773
775
  storage: Storage options of a bulk dataset, from
774
776
  :func:`io4dolfinx.backends.h5py.storage.storage_options`. A new bulk dataset
775
- is chunked by rows and filtered as these options say. Omitted for small
776
- bookkeeping datasets, which every rank writes independently and which must
777
- therefore stay unfiltered; they use h5py's automatic chunking.
777
+ is chunked by rows and filtered as these options say. Omitted for the
778
+ per-step datasets, which every rank writes independently and which must
779
+ therefore stay unfiltered; they are chunked by ``_step_chunk`` entries.
778
780
  """
779
781
  if name not in root.keys():
780
782
  mode = "w"
781
783
  if mode == "w":
782
784
  if storage is None:
783
- layout: dict[str, Any] = {"chunks": True}
785
+ assert len(shape) == 1, "Only per-step datasets are created without storage options"
786
+ layout: dict[str, Any] = {"chunks": (_step_chunk,)}
784
787
  else:
785
788
  layout = {
786
789
  "chunks": h5_storage.chunk_shape(storage, shape, dtype),
@@ -352,11 +352,11 @@ def read_function(
352
352
 
353
353
  # Compute mesh->input communicator
354
354
  # 1.1 Compute mesh->input communicator
355
+ num_cells_global = mesh.topology.index_map(mesh.topology.dim).size_global
355
356
  owners: npt.NDArray[np.int32]
356
357
  if backend_cls.read_mode == ReadMode.serial:
357
- owners = np.zeros(input_cells, dtype=np.int32)
358
+ owners = np.zeros(len(input_cells), dtype=np.int32)
358
359
  elif backend_cls.read_mode == ReadMode.parallel:
359
- num_cells_global = mesh.topology.index_map(mesh.topology.dim).size_global
360
360
  owners = index_owner(mesh.comm, input_cells, num_cells_global)
361
361
  else:
362
362
  raise NotImplementedError(f"{backend_cls.read_mode} not implemented")
@@ -424,7 +424,6 @@ def read_function(
424
424
  V = u.function_space
425
425
  local_cells, dof_pos = compute_dofmap_pos(V)
426
426
  input_cells = V.mesh.topology.original_cell_index[local_cells]
427
- num_cells_global = V.mesh.topology.index_map(V.mesh.topology.dim).size_global
428
427
 
429
428
  if backend_cls.read_mode == ReadMode.serial:
430
429
  owners = np.zeros(len(input_cells), dtype=np.int32)
@@ -347,7 +347,7 @@ def exchange_to_owners(
347
347
  npt.NDArray[np.int32],
348
348
  npt.NDArray[np.int32],
349
349
  npt.NDArray[np.int32],
350
- npt.NDArray[np.int32],
350
+ npt.NDArray[np.intp],
351
351
  ]:
352
352
  """Send each entry of ``arrays`` to the rank naming it in ``owners``.
353
353
 
@@ -99,7 +99,7 @@ def compute_insert_position(
99
99
  data_owner: npt.NDArray[np.int32],
100
100
  destination_ranks: npt.NDArray[np.int32],
101
101
  out_size: npt.NDArray[np.int32],
102
- ) -> npt.NDArray[np.int32]:
102
+ ) -> npt.NDArray[np.intp]:
103
103
  """
104
104
  Giving a list of ranks, compute the local insert position for each rank in a list
105
105
  sorted by destination ranks. This function is used for packing data from a
@@ -116,21 +116,28 @@ def compute_insert_position(
116
116
  insert_position = compute_insert_position(data_owner, destination_ranks, out_size)
117
117
 
118
118
  Insert position is then ``[1, 4, 5, 2, 0, 3]``
119
- """
120
- process_pos_indicator = data_owner.reshape(-1, 1) == destination_ranks
121
-
122
- # Compute offsets for insertion based on input size
123
- send_offsets = np.zeros(len(out_size) + 1, dtype=np.intc)
124
- send_offsets[1:] = np.cumsum(out_size)
125
- assert send_offsets[-1] == len(data_owner)
126
119
 
127
- # Compute local insert index on each process
128
- proc_row, proc_col = np.nonzero(process_pos_indicator)
129
- cum_pos = np.cumsum(process_pos_indicator, axis=0)
130
- insert_position = cum_pos[proc_row, proc_col] - 1
120
+ Entries with the same owner keep their relative order. Runs in O(n log n) time
121
+ and O(n) memory for ``n = len(data_owner)``, independently of the number of
122
+ destination ranks.
131
123
 
132
- # Add process offset for each local index
133
- insert_position += send_offsets[proc_col]
124
+ Raises:
125
+ ValueError: If an entry of ``data_owner`` is not in ``destination_ranks``.
126
+ """
127
+ assert np.sum(out_size) == len(data_owner)
128
+
129
+ # Position of each entry's owner in `destination_ranks`
130
+ sorter = np.argsort(destination_ranks)
131
+ sorted_pos = np.searchsorted(destination_ranks, data_owner, sorter=sorter)
132
+ owner_pos = sorter[np.minimum(sorted_pos, len(destination_ranks) - 1)]
133
+ if not np.array_equal(destination_ranks[owner_pos], data_owner):
134
+ raise ValueError("Every entry of data_owner must be in destination_ranks.")
135
+
136
+ # A stable sort by owner position orders the send buffer; its inverse is the
137
+ # insert position of each entry
138
+ order = np.argsort(owner_pos, kind="stable")
139
+ insert_position = np.empty(len(data_owner), dtype=np.intp)
140
+ insert_position[order] = np.arange(len(data_owner), dtype=np.intp)
134
141
  return insert_position
135
142
 
136
143
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: io4dolfinx
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Checkpointing functionality for DOLFINx meshes/functions with ADIOS2
5
5
  Author-email: "Jørgen S. Dokken" <dokken@simula.no>, "Henrik N.T. Finsberg" <henriknf@simula.no>
6
6
  License: Copyright 2023 Jørgen S. Dokken, Henrik N.T. Finsberg and Simula Research Laboratory
@@ -153,6 +153,8 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
153
153
  ## Releasing
154
154
  Versions are managed with [bump-my-version](https://callowayproject.github.io/bump-my-version/), configured in `pyproject.toml`. Between releases the version is a development version, `X.Y.Z.devN`; a release drops the suffix. Each bump commits the version change, so start from a clean working tree.
155
155
 
156
+ ### Releasing the development version
157
+
156
158
  To release the current development version, e.g. `2.1.0.dev0`, and start the next one:
157
159
 
158
160
  ```bash
@@ -162,7 +164,20 @@ bump-my-version bump minor --no-tag # 2.1.0 -> 2.2.0.dev0
162
164
 
163
165
  For a patch release of 2.1, bump `patch` instead of `minor` (`2.1.0 -> 2.1.1.dev0`), then `release` (`2.1.1.dev0 -> 2.1.1`). `bump-my-version show-bump` previews what each bump gives.
164
166
 
165
- The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`) as `v2.1.0`, for instance by creating a GitHub release from it.
167
+ ### Patch release of the previous version
168
+
169
+ To release `main` as a patch of the previous release, e.g. `2.0.1` while `main` is at `2.1.0.dev0`, set the version directly and then restore the development version:
170
+
171
+ ```bash
172
+ bump-my-version bump --new-version 2.0.1 --no-tag # 2.1.0.dev0 -> 2.0.1
173
+ bump-my-version bump minor --no-tag # 2.0.1 -> 2.1.0.dev0
174
+ ```
175
+
176
+ This releases everything on `main`, so use it only if `main` holds nothing but fixes since `v2.0.0`. The first bump warns that `2.1.0.dev0` does not match the last tag, `v2.0.0`; this is expected, as development versions are not tagged.
177
+
178
+ ### Tagging
179
+
180
+ The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`, or `Bump version: 2.1.0.dev0 → 2.0.1`) as `v2.1.0` or `v2.0.1`, for instance by creating a GitHub release from it.
166
181
 
167
182
  Releasing a new minor version also adds it to `.github/docs-versions.toml`, which lists the versions on the documentation website, built in the DOLFINx image of the previous one; edit that image afterwards if a newer DOLFINx release should be used. A patch release needs no entry, as each minor version is built from its newest tag.
168
183
 
@@ -11,6 +11,7 @@ import numpy as np
11
11
  import pytest
12
12
 
13
13
  import io4dolfinx
14
+ from io4dolfinx.backends import ReadMode
14
15
 
15
16
  dtypes = [np.float64, np.float32] # Mesh geometry dtypes
16
17
  write_comm = [MPI.COMM_SELF, MPI.COMM_WORLD] # Communicators for creating mesh
@@ -371,3 +372,43 @@ def test_writing_at_a_stored_time_names_the_time(mesh_2D, tmp_path, backend):
371
372
  io4dolfinx.write_function(filename, u, time=0.25, backend=backend)
372
373
  with pytest.raises(RuntimeError, match=r"Function 'u' has already been stored at time=0\.25"):
373
374
  io4dolfinx.write_function(filename, u, time=0.25, backend=backend)
375
+
376
+
377
+ @pytest.mark.parametrize(
378
+ "cell_type", [dolfinx.mesh.CellType.triangle, dolfinx.mesh.CellType.tetrahedron]
379
+ )
380
+ @pytest.mark.parametrize("family", ["Lagrange", "N1curl"])
381
+ def test_read_function_serial_read_mode(cell_type, family, tmp_path, backend, monkeypatch):
382
+ """Read a function with a backend that reads all data on the root rank.
383
+
384
+ Each rank reads on ``MPI.COMM_SELF``, so only single-rank serial reads are covered.
385
+ """
386
+ comm = MPI.COMM_SELF
387
+ suffix = ".bp" if backend.startswith("adios2") else ".h5"
388
+ filename = (tmp_path / f"serial_read_{MPI.COMM_WORLD.rank}").with_suffix(suffix)
389
+ if cell_type == dolfinx.mesh.CellType.triangle:
390
+ mesh = dolfinx.mesh.create_unit_square(comm, 5, 5, cell_type=cell_type)
391
+ else:
392
+ mesh = dolfinx.mesh.create_unit_cube(comm, 3, 3, 3, cell_type=cell_type)
393
+ gdim = mesh.geometry.dim
394
+
395
+ def f(x):
396
+ return np.vstack([x[i] + (i + 1) * x[(i + 1) % gdim] for i in range(gdim)])
397
+
398
+ shape = (gdim,) if family == "Lagrange" else None
399
+ el = basix.ufl.element(family, mesh.basix_cell(), 1, shape=shape)
400
+ u = dolfinx.fem.Function(dolfinx.fem.functionspace(mesh, el), name="u")
401
+ u.interpolate(f)
402
+ io4dolfinx.write_mesh(filename, mesh, backend=backend)
403
+ io4dolfinx.write_function(filename, u, backend=backend)
404
+
405
+ in_mesh = io4dolfinx.read_mesh(filename, comm, backend=backend)
406
+ V = dolfinx.fem.functionspace(in_mesh, el)
407
+ v = dolfinx.fem.Function(V, name="u")
408
+ monkeypatch.setattr(io4dolfinx.get_backend(backend), "read_mode", ReadMode.serial)
409
+ io4dolfinx.read_function(filename, v, backend=backend)
410
+
411
+ v_ex = dolfinx.fem.Function(V)
412
+ v_ex.interpolate(f)
413
+ tol = 10 * np.finfo(v.x.array.dtype).resolution
414
+ np.testing.assert_allclose(v.x.array, v_ex.x.array, atol=tol, rtol=tol)
@@ -1,4 +1,5 @@
1
1
  import itertools
2
+ import tracemalloc
2
3
  from typing import Tuple
3
4
 
4
5
  from mpi4py import MPI
@@ -9,7 +10,7 @@ import numpy as np
9
10
  import numpy.typing as npt
10
11
  import pytest
11
12
 
12
- from io4dolfinx.utils import compute_dofmap_pos, unroll_dofmap
13
+ from io4dolfinx.utils import compute_dofmap_pos, compute_insert_position, unroll_dofmap
13
14
 
14
15
  write_comm = [MPI.COMM_SELF, MPI.COMM_WORLD] # Communicators for creating mesh
15
16
  ghost_mode = [dolfinx.mesh.GhostMode.none, dolfinx.mesh.GhostMode.shared_facet]
@@ -162,3 +163,57 @@ def test_compute_send_sizes():
162
163
  process_pos_indicator = data_owners.reshape(-1, 1) == dest_ranks
163
164
  vectorized_out_size = np.count_nonzero(process_pos_indicator, axis=0)
164
165
  np.testing.assert_allclose(vectorized_out_size, out_size)
166
+
167
+
168
+ def test_compute_insert_position_docstring_example():
169
+ data_owner = np.array([0, 1, 1, 0, 2, 3], dtype=np.int32)
170
+ destination_ranks = np.array([2, 0, 3, 1], dtype=np.int32)
171
+ out_size = np.array([1, 2, 1, 2], dtype=np.int32)
172
+ insert_position = compute_insert_position(data_owner, destination_ranks, out_size)
173
+ np.testing.assert_array_equal(insert_position, [1, 4, 5, 2, 0, 3])
174
+
175
+
176
+ @pytest.mark.parametrize("num_data", [0, 1, 100])
177
+ def test_compute_insert_position(num_data):
178
+ rng = np.random.default_rng(42)
179
+ data_owners = rng.integers(0, 10, num_data).astype(np.int32)
180
+ # Destinations in unsorted order, including ranks that receive nothing
181
+ dest_ranks = rng.permutation(np.union1d(data_owners, [3, 10, 11])).astype(np.int32)
182
+ out_size = np.array([np.count_nonzero(data_owners == r) for r in dest_ranks], dtype=np.int32)
183
+
184
+ # Pack with loops: grouped by destination, original order within each group
185
+ reference = np.empty(num_data, dtype=np.int32)
186
+ position = 0
187
+ for rank in dest_ranks:
188
+ for i, owner in enumerate(data_owners):
189
+ if owner == rank:
190
+ reference[i] = position
191
+ position += 1
192
+
193
+ insert_position = compute_insert_position(data_owners, dest_ranks, out_size)
194
+ np.testing.assert_array_equal(insert_position, reference)
195
+
196
+
197
+ @pytest.mark.parametrize("missing_owner", [1, 5])
198
+ def test_compute_insert_position_owner_not_in_destinations(missing_owner):
199
+ data_owner = np.array([0, missing_owner, 2], dtype=np.int32)
200
+ destination_ranks = np.array([2, 0], dtype=np.int32)
201
+ out_size = np.array([2, 1], dtype=np.int32)
202
+ with pytest.raises(ValueError):
203
+ compute_insert_position(data_owner, destination_ranks, out_size)
204
+
205
+
206
+ def test_compute_insert_position_memory_independent_of_num_ranks():
207
+ """Memory must not scale with the number of destination ranks."""
208
+ rng = np.random.default_rng(42)
209
+ num_data = 100_000
210
+ num_ranks = 1_000
211
+ data_owners = rng.integers(0, num_ranks, num_data).astype(np.int32)
212
+ dest_ranks, out_size = np.unique(data_owners, return_counts=True)
213
+
214
+ tracemalloc.start()
215
+ compute_insert_position(data_owners, dest_ranks.astype(np.int32), out_size.astype(np.int32))
216
+ _, peak = tracemalloc.get_traced_memory()
217
+ tracemalloc.stop()
218
+ # A dense (num_data, num_ranks) array needs at least num_ranks bytes per entry
219
+ assert peak < 64 * num_data
@@ -492,9 +492,44 @@ def test_row_chunks(shared_tmp_path, chunk_bytes, backend):
492
492
  min(_rows_per_chunk(target, dataset), dataset.shape[0]),
493
493
  *dataset.shape[1:],
494
494
  )
495
- # Bookkeeping arrays keep h5py's automatic chunking.
496
- assert block["NumberOfPoints"].chunks is not None
495
+ assert block["NumberOfPoints"].chunks == (vtkhdf._step_chunk,)
497
496
 
498
497
  restored = io4dolfinx.read_mesh(filename, comm, time=1.0, backend="vtkhdf")
499
498
  v = io4dolfinx.read_point_data(filename, "u", restored, time=1.0, backend="vtkhdf")
500
499
  np.testing.assert_allclose(v.x.array, 1.0)
500
+
501
+
502
+ @pytest.mark.parametrize("backend", ["vtkhdf", "vtkhdf-serial"])
503
+ def test_step_datasets_share_chunks(shared_tmp_path, backend):
504
+ """Per-step datasets hold all time steps in one chunk."""
505
+ comm = MPI.COMM_WORLD
506
+ if backend == "vtkhdf" and comm.size > 1 and not h5py.get_config().mpi:
507
+ pytest.skip("Writing in parallel needs h5py with MPI")
508
+ filename = shared_tmp_path / "steps.vtkhdf"
509
+ mesh = create_unit_square(comm, 4, 4)
510
+ io4dolfinx.write_mesh(filename, mesh, backend=backend, backend_args={})
511
+ u = Function(functionspace(mesh, ("Lagrange", 1)), name="u")
512
+ num_steps = 5
513
+ for step in range(num_steps):
514
+ io4dolfinx.write_point_data(
515
+ filename,
516
+ u,
517
+ time=float(step),
518
+ mode=io4dolfinx.FileMode.append,
519
+ backend=backend,
520
+ backend_args={},
521
+ )
522
+
523
+ step_datasets = []
524
+
525
+ def collect(name, item):
526
+ if isinstance(item, h5py.Dataset) and item.shape == (num_steps,):
527
+ step_datasets.append(item)
528
+
529
+ with h5py.File(filename, "r") as hdf:
530
+ hdf.visititems(collect)
531
+ assert {"Values", "NumberOfPoints", "u", "Steps"} <= {
532
+ d.name.rsplit("/", 1)[1] for d in step_datasets
533
+ }
534
+ for dataset in step_datasets:
535
+ assert dataset.id.get_num_chunks() == 1, dataset.name
File without changes
File without changes
File without changes