Skip to content

Integration-point variables on a rank with no cells - #1222

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/integration-point-variable-empty-rank
Nov 16, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/integration-point-variable-empty-rank

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member

Integration-point variables on a rank with no cells

What changed and why

An integration-point variable (an IntegrationPointVariable, a swarm variable with proxy_location="integration_points", the integration-point semi-Lagrangian history, or a material swarm's level sets) could not be created when any rank held no cells. _BaseIntegrationPointVariable._create_petsc_fe built the element's reference cell from the type of the rank's first local cell. A rank without cells has none, so PETSc returned DM_POLYTOPE_UNKNOWN and refused to build a reference cell (error 62) on that rank alone. The ranks with cells went on into the next collective (DMClone inside createSubDM) and waited there. Either the job hung, or it aborted when the failing rank's exit met their allreduce.

The parallel review desk found this on development 35ac139, on a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH). Its fix brief is in the campaigns record. Proxies at nodes and at cells were not affected, because they build their element from mesh.isSimplex.

The reference cell now comes from facts every rank agrees on: the mesh dimension and the reconciled mesh.isSimplex (#1189), from which the integration rule itself is already built. Every rank builds the same element and enters the same collectives. No rank-local branch is added.

On a mesh where every rank has cells nothing changes: the map gives the same polytope as the local cell type on 2-D simplex and quadrilateral boxes and on 3-D simplex and hexahedral boxes (checked serially, by script).

What a user's run can now do

Create any of the four integration-point variables above on a mesh where some rank holds no cells. Before, it aborted or hung. On the empty rank the variable holds zero integration points and zero values, and its cell view is (0, Nq, ncomp).

Test

tests/parallel/test_1222_integration_point_variable_on_an_empty_rank_parallel.py, level_1, tier_b. It uses the empty-rank triangle of empty_rank_fixtures; at np 2 the fixture keeps a rank empty only with a one-cell mesh. Each of its four cases checks every rank creates the variable and that the shapes of integration_points, data and cell_data match the rank's own cell count. data is read on purpose, since the brief asks that it be zero-length on the empty rank. The cases:

  • an IntegrationPointVariable created directly, and a second one through the clone path;
  • a swarm variable with an integration-point proxy;
  • IntegrationPointSemiLagrangian's history;
  • a MaterialSwarm's level sets.

scripts/test.sh runs the file at np 2 with the other parallel files, and at np 3 always, for two populated ranks beside an empty one (cells per rank [8, 8, 0]).

What was run (this machine, the same build, under scripts/mpi_supervisor.py)

Run Development 35ac139 This PR
New file, serial 4 passed 4 passed
New file, np 2 all 4 fail: "Cannot create reference cell for cell type unknown", job aborts (exit 63) 4 passed on both ranks
New file, np 3 all 4 fail, same error, abort (exit 142) 4 passed on every rank
New file, np 4 not run 4 passed on every rank

Also on this branch:

  • 13 neighbouring serial files (integration-point variables and proxies, the integration-point semi-Lagrangian scheme, material swarms, swarms): 137 passed.
  • 21 parallel files at np 2 (every empty-rank, swarm, integration-point and material file in tests/parallel/): all exit 0.
  • test_0065, test_0066, test_0067, test_0072 (serial files) launched under mpirun at np 2: all pass on every rank.
  • At np 3, under mpirun, five cases of test_0066 and test_0067 fail on some ranks. The same five fail identically on development with this fix removed and rebuilt: they are serial tests whose exact checks assume one rank, and this change does not touch them.
  • Collective guard scan: 6 passed. Coverage: all 482 test files reachable. Deprecated-pattern check: no new patterns. It also reports a stale allowlist entry for rotated_bc.py:except-pass, which is not this PR's.

Not run

Above np 4; 3-D or quadrilateral meshes with an empty rank (the fixture is a triangle mesh; the map for those cell types was checked serially); the full suite; macOS.

Reviewer: the parallel review desk.

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9)
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4)
  • Every exception swallow states its sanctioned failure mode in a comment (S4): not applicable, none added
  • New data access uses .array / mesh.X.coords (S7): the test reads data and cell_data of integration-point variables, which is what is under test
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • No mesh entity or rank identified by coordinates; any remaining tolerance is named, relative and says what it bounds (S12)
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Underworld development team with AI support from Claude Code

Four cases on the empty-rank triangle: a direct IntegrationPointVariable (and a
second one, through the clone path), a swarm variable with an integration-point
proxy, the integration-point semi-Lagrangian history, and a material swarm's
level sets. On development all four fail at np 2 and np 3: the rank without
cells cannot build the element, and the job aborts. np 3 line in test.sh.

Underworld development team with AI support from Claude Code
…reconciled isSimplex

_create_petsc_fe asked the type of the rank's first local cell. A rank with no
cells has none: PETSc returned DM_POLYTOPE_UNKNOWN, refused to build a reference
cell on that rank alone, and the other ranks waited in the next collective. The
polytope now comes from facts every rank agrees on, as the rule does.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 16, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on head 53a2f69: ready to merge on green from this review.

The fix does what it should. An integration-point variable now builds the same element on every rank, a rank with no cells included. Before this PR it took the cell type from the rank's own first cell. The new polytope is the same as the old one wherever the old one was defined. The two findings below are small and do not block.

Findings

  1. Low: the create_delta_fe docstring is now out of date.
    In src/underworld3/cython/petsc_quadrature_fe.pyx, the polytope parameter is still described as "The reference cell type (dm.getCellType(cStart))". That is the pattern this PR removes. Suggest: "the reference cell type, the same on every rank (the caller derives it from the dimension and the mesh's reconciled isSimplex)". This is a .pyx file, but a docstring-only change needs no rebuild to test.

  2. Low (informational, no change asked): cell types other than tri, quad, tet and hex.

    • The map from dimension and isSimplex is right for every cell type the mesh constructors build. No constructor in meshing/ makes prisms, pyramids or mixed meshes, and extrude_sheet makes tetrahedra.
    • A user-supplied gmsh or medit file could carry prisms, which the medit reader lists. On such a mesh the new code would choose HEXAHEDRON where the old code read the first cell's type.
    • That is no regression. The mesh integration rule and every Lagrange element are already built from isSimplex, so such a mesh was never supported. The new choice at least agrees with the rule the element is built on.
    • If you want a clear message instead of a wrong result, one option is a reduced check (populated ranks only) that the local cell types match the mapped polytope. It would have to be collective. I am not asking for it in this PR.

Confirmed correct

  • The original reproducer passes on the branch. This is the reproducer from the bug brief: a SwarmVariable with proxy_location="integration_points" on the empty-rank triangle fixture.

    • At np 2 (cells [0, 1]) and np 3 (cells [8, 8, 0]) it completes, exit 0.
    • On development 35ac139 the same script aborts with "Cannot create reference cell for cell type unknown" (exit 63 at np 2, 142 at np 3).
    • The hold variant keeps the failing rank alive. At np 3 on development the supervisor reported a hang, with the other ranks in DMClone inside createSubDM. On the branch it completes at np 3.
  • Shapes on the empty rank. Checked at np 2 and np 3 on the branch:

    • integration_points is (0, 6, 2), data is (0, 1) and cell_data is (0, 6, 1), with Nq = 6 for qdegree 2, the same as on the populated ranks.
    • The next collective is reached: an allreduce of the data rows (6 at np 2, 96 at np 3) returns on every rank.
    • A second, 2-component IntegrationPointVariable (the _setup_ds clone path) is then created on every rank, with shape (0, 2) on the empty rank.
  • The map, checked serially. I compared the old polytope (the type of local cell 0) with the new one on five meshes. They are identical in every case, and the cell type is uniform on each mesh:

    Mesh Polytope Integration points
    2-D simplex box TRIANGLE (14, 6, 2)
    3-D simplex box TETRAHEDRON (100, 14, 3)
    2-D quad box QUADRILATERAL (4, 9, 2)
    3-D hex box HEXAHEDRON (8, 27, 3)
    2-D annulus TRIANGLE
  • Inputs to the map. dim is the DM's topological dimension. mesh.isSimplex is the value Mesh.__init__ reconciles with an allgather over the populated ranks, which is also what mesh.integration_rule is built from. Element and rule therefore always agree.

  • No other site breaks the same way. No other code reads getCellType on local cell 0.

    • Mesh._test_if_points_in_cells_internal in discretisation_mesh.py calls getConeSize(cStart) without a guard. It is rank-local, and on an empty rank it loops over zero query points, so it is harmless.
    • meshing/smoothing/api.py already guards with if cEnd > cStart.
    • The Mesh(..., simplex=dm.isSimplex()) call sites pass a rank-local value. The constructor reconciles it over the populated ranks, so they are unaffected.
  • test_1222.

    • It passes serially and at np 2, 3 and 4 (4 passed at each, no supervisor reports).
    • On development 35ac139 all four cases fail at np 2 and at np 3, one case per job. Exit codes: np 2 gave 59 for the direct variable and 63 for the other three; np 3 gave 142 for all four.
    • Serially on development it passes, as expected.
  • test.sh. The new np 3 line matches the pattern of the other empty-rank files. The file also runs in the enumerated tests/parallel batches at the default rank count.

Run and not run

  • Run: the reproducer, the hold variant and a shape check at np 2 and 3, on the branch and on development. The polytope comparison serially. test_1222 serially and at np 2, 3 and 4 on the branch, and at np 2 and 3 plus serially on development.
  • Neighbours, serially on the branch: 167 tests across test_0064 to 0067, 0071 to 0073, 0857, 1052, 1053, 1056, 1057, 1059 and 1060. 166 passed. The remaining one is the 15-minute level_2 characterisation in test_1060, which my 300 s per-test limit stopped. I then ran that test alone, side by side on the branch and on development 35ac139, two cores each. Both were still running at my 25-minute outer limit, so it is unresolved on both. It shows no difference between them, but it was not run to completion here. Serially the polytope is identical to development's, so this PR cannot change that test's result.
  • Neighbours at np 2: test_0065, test_0067 and test_0072. Branch and development give the same result, 32 passed and 1 skipped on each rank, with no supervisor report. These meshes have no empty rank, so this checks that the change does not affect the ordinary parallel path.
  • Not run: the rest of the neighbour files at np 2, and the slow test_1060 characterisation to completion.
  • Build: the PR changes only .py files and test.sh. The compiled sources of development 35ac139 (the merge base) match the build used, so the branch's .py files were laid over that install.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit f3861d5 into development Nov 16, 2026
10 checks passed
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…on and isSimplex

The docstring still told callers to pass dm.getCellType(cStart), which is
UNKNOWN on a rank with no cells; the integration-point variables stopped
doing that in underworldcode#1222.

Underworld development team with AI support from Claude Code
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.

3 participants