Repository navigation
test_0052: a guard that reads the rank is always rank-local (#874) - #1236
Conversation
C1 and H1 on #1225: mpi.rank and comm.rank were in UNIFORM_TOKENS, so the scan took the rank for uniform and never reported a collective (or an agreement point) under `if comm.rank == 0:`, the classic hang it exists to catch. None of `comm.rank == 1`, `comm.rank`, `uw.mpi.rank == last`, `mpi.rank < 2`, `comm.rank == comm.size - 1` was flagged, and `comm.getRank() == 0` passed when comm was a parameter. - The rank tokens leave UNIFORM_TOKENS (the size stays). - RANK_TOKENS (mpi.rank, comm.rank, .rank, getRank(), Get_rank()) and a bare `rank` name make a guard "rank", checked before the uniform tokens (hasattr, mpi.size) and before the argument rule, and reported as the local-data guards are. - Self-tests: each of H1's plants (and the getRank / Get_rank / bare rank / hasattr / size-and-rank forms) under an agree() is reported; in a _build_body snippet a planted rank guard is flagged beside the accepted guard keys. Tree triage: with the change the scan reports no collective or agreement point under a rank guard anywhere in src (0 findings), so no whitelist entry is needed (the scan reports guarded collectives only, never prints or writes). A skim of the 144 rank-guarded blocks for helper calls that are collective inside found 11 candidates, all safe (listed in the PR). Underworld development team with AI support from Claude Code
|
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)) Verdict at 40603cd: ready to merge on green from this review. The scan change is right and its tests pass. One of the eleven blocks in the triage table that the PR body marks safe is a real hang: the visualisation helpers (finding 1). The bug was already in the source before this PR, so it can be fixed separately, but the table's row should be corrected. The diff
The scan
Findings
Spot-checks of the triage
Not run
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
Addresses #874: the rank-guard gap in
test_0052's collective guard scan, from the reviews of #1225 by C1 (the development hub) and H1 (review and parallel test runs on a 96-thread Linux workstation). Review: H1. Test-only.#1225 is merged and development is merged in: the diff is
tests/test_0052_collective_guard_scan.pyalone.The gap
mpi.rankandcomm.rankwere inUNIFORM_TOKENS, so the scan treated the rank as the same on every rank. It therefore never reported a collective, or an agreement point, underif comm.rank == 0:, which is the classic hang the scan exists to catch. H1's raw scan showed:agree(), even in_build_body:comm.rank == 1,comm.rank,uw.mpi.rank == last,mpi.rank < 2,comm.rank == comm.size - 1;comm.getRank() == 0also passed whencommwas a parameter, through the argument rule.The fix
UNIFORM_TOKENS. The size tokens stay."rank"and reported, as the local-data guards are. It reads the rank if it containsmpi.rank,comm.rank,.rank,getRank()orGet_rank(), or a bare namerank.hasattr,mpi.size) and before the argument rule. Souw.mpi.size > 1 and comm.rank == 0,hasattr(comm, "rank") and comm.rank == 0, and a parametercommare all reported.Self-tests
agree()is reported. The plants are H1's, plus thegetRank()/Get_rank(), bare-rank,hasattrand size-and-rank forms (test_a_rank_guard_is_never_taken_for_uniform, 10 cases)._build_bodysnippet, a plantedcomm.rank == comm.size - 1guard around anagree()is flagged beside the accepted guard keys of custom_mg.build agrees on failure: the set-up phase and the per-level loop body (#874) #1225.Tree triage
The scan: with the change, it reports no collective or agreement point under a rank guard anywhere in
src/underworld3: 0 findings. No whitelist entry is needed, because the scan reports guarded collectives only, never a rank-0 print or write.A wider skim: the scan can't see a collective inside a called helper. So I also skimmed the 144 rank-guarded blocks in the tree for calls that are collective inside: a save or write, a view, a barrier, a global-to-local scatter, an evaluate, a solve or an agreement. That found 11 candidates: 7 safe, and the 4 visualisation helpers a real hang (corrected after H1's review; see the first row):
visualisation/parallel.py, 4 helpersuw.mpi.rank == viz_rankelsebranch as making the sameglobal_evaluatecall with empty points; I did not run it. H1 did. When the field is a sympy expression, the non-plotting ranks raiseAttributeErroronfield.meshbuilding the empty points, so they never reach the collectiveglobal_evaluateand the plotting rank waits in it:parallel_line_plothangs at np 2 and 3. The scan does not see it, because the collective is reached through a helper. Fixed separately by H6.utilities/place_surface.py, 4 sitescomm.rank == targettrywhose failure is caught intofailureand agreed after the blockswarm.py:5177uw.mpi.rank == 0utilities/boundary_flux.py:423,postprocessing/geoid.py:936comm.rank == 0gathered; the body reads data already gatheredApart from the visualisation helpers, which are a real hang through a helper and are fixed separately by H6, there is nothing to fix here.
Results
tests/test_0052_collective_guard_scan.py: 20 passed (the whole-tree scan included).Underworld development team with AI support from Claude Code