io4dolfinx 2.2.1__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.
- {io4dolfinx-2.2.1/src/io4dolfinx.egg-info → io4dolfinx-2.3.0}/PKG-INFO +1 -1
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/pyproject.toml +2 -2
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/checkpointing.py +2 -3
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/comm_helpers.py +1 -1
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/utils.py +21 -14
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0/src/io4dolfinx.egg-info}/PKG-INFO +1 -1
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_checkpointing.py +41 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_numpy_vectorization.py +56 -1
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/LICENSE +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/README.md +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/setup.cfg +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/ascii_helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2/helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2_serial/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/adios2_serial/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/exodus/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/exodus/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/gmsh/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/gmsh/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py/storage.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py_serial/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/h5py_serial/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/med/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/med/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/nastran/helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/opencarp/helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/openfoam/helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/pyvista/helpers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/serial.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtk_cell_types.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf_serial/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/vtkhdf_serial/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/xdmf/__init__.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/backends/xdmf/backend.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/converter.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/format.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/original_checkpoint.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/py.typed +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/readers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/snapshot.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/structures.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/submesh.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx/writers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/SOURCES.txt +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/dependency_links.txt +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/entry_points.txt +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/requires.txt +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/src/io4dolfinx.egg-info/top_level.txt +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_attributes.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_backends.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_checkpointing_vector.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_converter.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_exodus.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_format_version.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_geometry_dofmap_reconstruction.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_gmsh.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_h5py_compression.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_legacy_readers.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_med.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_mesh_writer.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_meshtags.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_nastran.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_opencarp.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_openfoam.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_original_checkpoint.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_pyvista.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_snapshot_checkpoint.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_submesh.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_version.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_vtkhdf.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_vtkhdf_compression.py +0 -0
- {io4dolfinx-2.2.1 → io4dolfinx-2.3.0}/tests/test_write_data_input_order.py +0 -0
- {io4dolfinx-2.2.1 → 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.
|
|
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
|
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "io4dolfinx"
|
|
14
|
-
version = "2.
|
|
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.
|
|
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}"]
|
|
@@ -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)
|
|
@@ -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.
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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.
|
|
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
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|