Skip to content

Fix IndexError in _pic_swarm_in_mesh on MPI ranks with empty cell partition#5078

Merged
connorjward merged 6 commits intofiredrakeproject:releasefrom
Corintis:fix/pic-swarm-empty-rank
May 8, 2026
Merged

Fix IndexError in _pic_swarm_in_mesh on MPI ranks with empty cell partition#5078
connorjward merged 6 commits intofiredrakeproject:releasefrom
Corintis:fix/pic-swarm-empty-rank

Conversation

@hardik-corintis
Copy link
Copy Markdown

@hardik-corintis hardik-corintis commented May 4, 2026

Description

Fixes #5077.

In _pic_swarm_in_mesh, parent_cell_nums_local contains -1 sentinels for points not
owned by the current rank. On ranks with an empty cell partition, cell_closure has shape
(0, k) and NumPy rejects -1 as an axis-0 index, causing an IndexError when
interpolating from a Submesh onto its parent mesh in parallel.

Fix: index cell_closure only on visible_idxs (the non-sentinel entries), pre-filling
the rest with -1. The same issue exists in the extruded branch: _parent_extrusion_numbering
floor-divides parent_cell_nums_local, and -1 // N == -1 in Python, so sentinels pass
through into base_parent_cell_nums and cause the same crash. Both branches are fixed.

Two regression tests added in tests/firedrake/submesh/test_submesh_interpolate.py using
8 MPI ranks:

  • test_submesh_interpolate_3Dcell_2Dfacet_empty_rank_8_processes: interpolates from a
    Submesh of the x=1 face of UnitCubeMesh(2, 2, 2) onto the parent mesh.
  • test_submesh_interpolate_3Dcell_extruded_empty_rank_8_processes: interpolates from
    ExtrudedMesh(UnitSquareMesh(1, 1), layers=3) (6 cells) onto a UnitCubeMesh(2, 2, 2),
    guaranteeing at least two ranks own zero extruded cells.

@connorjward connorjward requested a review from leo-collins May 5, 2026 11:00
Comment thread tests/firedrake/submesh/test_submesh_interpolate.py Outdated
Copy link
Copy Markdown
Contributor

@leo-collins leo-collins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good. The same thing probably happens for the extruded case too - can you add a test for this (and a fix if necessary)?

Comment thread tests/firedrake/submesh/test_submesh_interpolate.py Outdated
Comment thread tests/firedrake/submesh/test_submesh_interpolate.py Outdated
Comment thread tests/firedrake/submesh/test_submesh_interpolate.py Outdated
Comment thread tests/firedrake/submesh/test_submesh_interpolate.py
@hardik-corintis
Copy link
Copy Markdown
Author

Thanks @leo-collins for the quick review. I have applied all the inline suggestions and added the test and fix for the extruded meshes.

leo-collins
leo-collins previously approved these changes May 8, 2026
@connorjward
Copy link
Copy Markdown
Contributor

Should this be going into release?

@hardik-corintis
Copy link
Copy Markdown
Author

Should this be going into release?

If this is a question for me, I am not sure, I would go with your recommendation. My understanding from the contribution guide is that bug fixes generally go into release, but I am happy to follow whatever is preferred here.

@connorjward
Copy link
Copy Markdown
Contributor

connorjward commented May 8, 2026

Unless this is somehow relying on features that only exist in main then I think that this should go into release. To set that up I'd recommend rebasing, force pushing and then changing the target branch of this PR. Just changing the target branch of the PR leads to conflicts.

@hardik-corintis hardik-corintis force-pushed the fix/pic-swarm-empty-rank branch from aa18a4d to 59d9202 Compare May 8, 2026 14:44
@hardik-corintis hardik-corintis changed the base branch from main to release May 8, 2026 14:45
@hardik-corintis
Copy link
Copy Markdown
Author

Done — rebased onto release and retargeted the PR!

@connorjward connorjward enabled auto-merge (squash) May 8, 2026 15:56
@connorjward
Copy link
Copy Markdown
Contributor

Thanks!

@connorjward connorjward merged commit e0f14cb into firedrakeproject:release May 8, 2026
12 of 24 checks passed
@hardik-corintis hardik-corintis deleted the fix/pic-swarm-empty-rank branch May 8, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: IndexError in _pic_swarm_in_mesh on MPI ranks with empty cell partition

3 participants