From e6f9af77ac3e59276ac646fb311e9e1ba1ea9baa Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 6 Oct 2026 17:49:54 +0000 Subject: [PATCH 1/4] Index to dest ranks APi update post https://github.com/FEniCS/dolfinx/pull/4573 --- src/scifem/compat.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/scifem/compat.py b/src/scifem/compat.py index b6e236d..27753ae 100644 --- a/src/scifem/compat.py +++ b/src/scifem/compat.py @@ -149,6 +149,29 @@ def topology(comm, cell_type, tdim, vertex_map, cell_map, c_to_v, v_to_v, origin return dolfinx.cpp.mesh.Topology(*args) +def index_to_dest_ranks( + imap: dolfinx.common.IndexMap | dolfinx.cpp.common.IndexMap, tag: int +) -> tuple[npt.NDArray[np.int32], npt.NDArray[np.int32]]: + """Get the destination ranks for each index in an index map, across DOLFINx versions. + + Args: + imap: The index map to query. + tag: MPI tag for the consensus exchange, the same on every process and not in use + by another exchange in flight. + + Returns: + (Sharing-rank data, offsets). Ranks sharing local + index `i` occupy `[offsets[i], offsets[i + 1])`. For an owned + index, these are the ranks that ghost it; for a ghost index, its + owner and the other ranks that ghost it. The caller is excluded. + """ + signature_inputs = inspect.signature(imap.index_to_dest_ranks).parameters + if "tag" in signature_inputs: + return imap.index_to_dest_ranks(tag) # type: ignore[call-arg] + else: + return imap.index_to_dest_ranks() + + def ghosting_ranks(index_map, tag: int): """The ranks that ghost each owned index of `index_map`, flat and with offsets. @@ -164,7 +187,7 @@ def ghosting_ranks(index_map, tag: int): ``(ranks, offsets)``: the ghosting ranks of owned index ``i`` are ``ranks[offsets[i]:offsets[i + 1]]``. Collective. """ - dest = index_map.index_to_dest_ranks(tag) + dest = index_to_dest_ranks(index_map, tag) ranks, offsets = (dest.array, dest.offsets) if hasattr(dest, "array") else dest return np.asarray(ranks, dtype=np.int32), np.asarray(offsets, dtype=np.int64) From a715503e6dfa9143b29ba529ed5c375700cb93ca Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 6 Oct 2026 17:55:10 +0000 Subject: [PATCH 2/4] Fix compat --- src/scifem/compat.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scifem/compat.py b/src/scifem/compat.py index 27753ae..7aa6108 100644 --- a/src/scifem/compat.py +++ b/src/scifem/compat.py @@ -166,10 +166,15 @@ def index_to_dest_ranks( owner and the other ranks that ghost it. The caller is excluded. """ signature_inputs = inspect.signature(imap.index_to_dest_ranks).parameters - if "tag" in signature_inputs: + if len(signature_inputs) == 2: return imap.index_to_dest_ranks(tag) # type: ignore[call-arg] - else: + elif len(signature_inputs) == 0: return imap.index_to_dest_ranks() + else: + raise RuntimeError( + f"Unexpected signature for index_to_dest_ranks: {signature_inputs}. " + "Please report this to the io4dolfinx developers." + ) def ghosting_ranks(index_map, tag: int): From 52d5f59d672cba4a32d6a82d65589cf1735248f1 Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 6 Oct 2026 17:57:59 +0000 Subject: [PATCH 3/4] Fix text in compat --- src/scifem/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scifem/compat.py b/src/scifem/compat.py index 7aa6108..a7bcd10 100644 --- a/src/scifem/compat.py +++ b/src/scifem/compat.py @@ -173,7 +173,7 @@ def index_to_dest_ranks( else: raise RuntimeError( f"Unexpected signature for index_to_dest_ranks: {signature_inputs}. " - "Please report this to the io4dolfinx developers." + "Please report this to the scifem developers." ) From 4f55dd158d866b76a2fc8e97522af659d1000174 Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 6 Oct 2026 18:18:02 +0000 Subject: [PATCH 4/4] Try fixing ghosting rnaks --- src/scifem/compat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/scifem/compat.py b/src/scifem/compat.py index a7bcd10..a2f4209 100644 --- a/src/scifem/compat.py +++ b/src/scifem/compat.py @@ -193,7 +193,10 @@ def ghosting_ranks(index_map, tag: int): ``ranks[offsets[i]:offsets[i + 1]]``. Collective. """ dest = index_to_dest_ranks(index_map, tag) - ranks, offsets = (dest.array, dest.offsets) if hasattr(dest, "array") else dest + if isinstance(dest, tuple): + ranks, offsets = dest + else: + ranks, offsets = (dest.array, dest.offsets) # type: ignore return np.asarray(ranks, dtype=np.int32), np.asarray(offsets, dtype=np.int64)