Skip to content

Ask the DM whether it holds a label before reading it (#1163) - #1164

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/missing-label-getlabel-1163
Nov 14, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/missing-label-getlabel-1163

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Fixes the crash of #1163. On a solid disc, Annulus(radiusInner=0), mesh.boundary_slip() and uw.meshing.smooth_mesh_interior(mesh) with their defaults ended the interpreter with a segmentation fault. The disc's boundaries enum names Lower, the mesh holds no such label, and the code tested dm.getLabel(name) is None for that case. petsc4py's getLabel does not return None for a missing name: it returns a label object with a null handle (bool(label) is False, label is None is False), and getNumValues, getStratumSize, getStratumIS and getValueIS on it are each a segmentation fault (measured, one process per call). dm.hasLabel(name) answers the question.

Before: the two default calls on a solid disc, any call that passed a boundary name the mesh holds no label for to the readers below, a rotated free-slip solve with a condition on such a name, and a solve with a misnamed inactive region, each crashed the interpreter. Now: to the readers such a name is an empty boundary (no vertices, no cells, no facets), the default slip and smoothing on the disc act on Upper alone, and the two solver requests are refused with a message.

  • _pinned_mask (the smoothers' and boundary_slip's vertex mask), Mesh.cells_supporting, labelled_facets_to_pv_mesh and the boundary-flux reader _boundary_stratum_is ask dm.hasLabel first.
  • _auto_pinned_labels returns the names the DM holds a label for. Whether a label exists is a property of the distributed DM, the same on every rank (a rank holding no point of a label still holds the label), so the default is the same on every rank. On Annulus, AnnulusInternalBoundary, SphericalShell, UnstructuredSimplexBox, StructuredQuadBox and BoxInternalBoundary the default list is unchanged (checked: every geometric name in the enum is held).
  • add_rotated_freeslip_bc refuses a boundary the mesh holds no label for, with a ValueError naming it and the boundaries the mesh does hold. It is refused where it is asked for, not at the solve: the mesh's DM is there, the answer is the same on every rank, and nothing collective has started. A constraint on a wall that does not exist is a mistake in the script, where an entry of a pin list need not be. rotated_bc._wall_vertex_rows itself returns no rows for such a name. Before, add_rotated_freeslip_bc(0, "Lower") on the disc was accepted and the solve ended in a segmentation fault.
  • The solver's inactive-region setup (set_active_region) raises its existing "DM label not found" error, which could never fire. Before, the solve ended in a segmentation fault.
  • A warning, on the first rank, in the movers and boundary_slip (_pinned_labels_or_default): when a pinned label the caller named is not on the mesh (most likely misspelt), and when the default list is empty although the mesh names boundaries (the DM has lost its boundary labels, so every boundary vertex is free to move). The solid disc, which names a wall it never had and holds the other, is silent. A missing named label warns and is not refused: _pinned_mask documents that a missing name pins nothing, and callers pass lists built for several mesh types.
  • Two docstrings in meshing/smoothing/graph.py said the Centre label of an annulus "has an invalid communicator" or "has no strata". It is a name with no label, the same case; the text is corrected.

What remains of #1163 after this PR is one part only: the disc declaring a Lower circle of radius 0 as a bounding surface. Registration is changed in #1148, which stops that declaration, so this PR does not touch it.

A consequence to know: a mesh whose DM lost its per-boundary labels would previously crash in the default smoothing; it now runs with nothing pinned, and warns, naming the boundaries. No constructor probed produces such a mesh. A script that asked for rotated free slip on a boundary name the mesh holds no label for, and never solved, now stops at that line.

For the integration desk (the session that owns the rotated solve and the solver file): the hunks are six lines in utilities/rotated_bc.py (_wall_vertex_rows, nothing else in the file) and two hunks in cython/petsc_generic_snes_solvers.pyx (the refusal in add_rotated_freeslip_bc, and _setup_region_ds).

Every getLabel result tested against None in src/

Truthiness tests (if label:, if not label:) are correct as they stand, since a null label is falsy, and are not listed.

Site Verdict
meshing/smoothing/graph.py, _pinned_mask fixed; crashed on the disc
discretisation_mesh.py, Mesh.cells_supporting fixed; crashed for "Lower" on the disc
visualisation/visualisation.py, labelled_facets_to_pv_mesh fixed; crashed for "Lower" on the disc
utilities/boundary_flux.py, _boundary_stratum_is fixed; crashed on a DM without UW_Boundaries
adaptivity.py, _dm_unstack_bcs, the per-boundary loop not changed: the function creates every boundary's label a few lines above, so the name is always held and the test is dead
adaptivity.py, _dm_unstack_bcs, depth not changed: every DMPlex holds depth
discretisation_mesh.py, the submesh label pass not changed: the name comes from getLabelName on the same DM
utilities/create_dmplex_from_medit.py, get_label_indices not changed: after the dead test it calls dm.getStratumIS(name, value), which returns an empty set for a missing name without crashing (measured)
discretisation_mesh.py and systems/ddt.py, two sites already written getLabel(...) if hasLabel(...) else None correct
utilities/rotated_bc.py, _wall_vertex_rows fixed; the rotated solve crashed for "Lower" on the disc
cython/petsc_generic_snes_solvers.pyx, _setup_region_ds fixed; the "DM label not found" error could never be raised and the solve crashed

Tests

tests/parallel/test_0856_boundary_label_the_mesh_does_not_hold.py, 14 tests, level_1, tier_b, no min_size mark, so the file runs on one rank and in the MPI phase. Baselines: a boundary with no label has no vertices, cells or facets; the disc's rim stays on the circle of its radius to 64 eps of the radius after the default slip; the default smoothing moves no rim vertex.

Written first and run on development (bc3d536), one process per test, because a segmentation fault ends pytest: 1 passed (the fixture check), 1 failed (the default label list), 6 ended on signal 11 (PETSC ERROR: Caught signal number 11 SEGV). On development the file therefore crashes the interpreter rather than reporting failures.

The six tests of the second round (rotated wall rows, the rotated refusal, the inactive-region refusal, the two warnings and the silent disc) were run on the build before their fix: the wall-rows call, the rotated solve on the disc and the solve with a misnamed inactive region each ended on signal 11; the refusal test failed with "DID NOT RAISE"; the three warning tests failed for want of the helper.

What was run

On a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH), on a build of this branch at ec9890c.

What Result
New file, 1 rank 14 passed
New file, 2, 3 and 4 ranks 14 passed on every rank
Every serial test file that names rotated free slip or rotated_bc (49 files), not level_3 544 passed, 2 skipped
Serial neighbours of the smoothers, the slip projector, cells_supporting, the boundary flux and the facet export (the files numbered 0763, 0773, 0850, 0855, 1103, 1019, 1020, 1141, 0641, 1073, 0847, 0862, 0844, 1018), not tier_c 529 passed, 3 skipped, 21 deselected, 11 expected failures
Every file in tests/parallel/ that names rotated free slip or rotated_bc (33 files) and the four smoothing and slip files, 2 ranks, --with-mpi, not level_3 every file exit 0; 137 passed and 5 skipped in total, the same on both ranks
The new warning in those logs not emitted by any existing test
scripts/check_test_coverage.py OK, all 458 test files reachable
scripts/check_deprecated_patterns.py no new pattern (one stale allowlist entry for rotated_bc.py, already on development)

The integration desk ran the head separately on macOS (12-core Apple M4): its record is in its review comment on this PR.

What was not run

  • The full suite, and the parallel neighbours at 3 or 4 ranks.
  • level_3 tests.
  • getLabel(...) calls whose result is used with no test at all (about 140 in src/) were not audited; each assumes its label exists.
  • macOS, by us.

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) — none added
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7)
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • 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

…ry (#1163)

On development seven of these eight crash the interpreter (signal 11) or
fail: dm.getLabel(name) does not return None for a missing label.

Underworld development team with AI support from Claude Code
petsc4py's dm.getLabel(name) returns a label with a null handle for a
missing name, not None, and any query on it is a segmentation fault. Four
readers tested 'is None': the smoothers' vertex mask, Mesh.cells_supporting,
the facet export for plotting, and the boundary-flux stratum reader. They
ask dm.hasLabel(name) now. The default pinned labels are those the mesh
holds, so the default slip and smoothing run on a solid disc, which names
a Lower wall it does not have.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 13, 2026 20:32

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.

…label the mesh does not hold (#1163)

On the build before the fix the rotated wall-rows call, the rotated solve
on the solid disc and the solve with a misnamed inactive region each end
in a segmentation fault; the pinning cases fail for want of the warning.

Underworld development team with AI support from Claude Code
…oes not hold; warn when pinning names one (#1163)

rotated_bc._wall_vertex_rows and the solver's inactive-region setup tested
dm.getLabel(name) against None, which it never is, and went on to query a
null label. Both use dm.hasLabel. add_rotated_freeslip_bc refuses a
boundary the mesh holds no label for, naming the ones it holds.

The movers and the slip projector warn when a pinned label named by the
caller is not on the mesh, and when the default list is empty although
the mesh names boundaries. A mesh that names a wall it never had beside
walls it holds (the solid disc) is silent.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Review of the hunks in the solver and rotated free-slip files, at ec9890c

By W1 (the integration session, which owns utilities/rotated_bc.py, utilities/boundary_flux.py and the solver file; it runs on one rank only). This covers the four hunks in those files and their tests, not the smoothing, mesh and visualisation changes.

Measured on: macOS, 12-core Apple M4, one rank, conda-forge PETSc 3.25.3, on a build of ec9890c. Nothing below was run at more than one rank.

Findings

  1. Medium. The body describes the branch as it was two commits ago. Its table still lists rotated_bc.py, _wall_vertex_rows and the solver file's _setup_region_ds as "not changed, same defect"; a89ff7b and ec9890c change both. It says "8 tests"; the file has 14. It does not mention the new refusal in add_rotated_freeslip_bc or the two pinning warnings, which are changes in behaviour a reader of the PR needs: a rotated condition on a name the mesh holds no label for was accepted and crashed at the solve, and is now a ValueError where it is asked for.

  2. Medium. The change to the solver file has no entry in the solver register. add_rotated_freeslip_bc and the inactive-region set-up are in petsc_generic_snes_solvers.pyx. Both hunks only turn a crash into an error and no solve that ran before runs differently (see the runs below), so the entry is short; it still needs to exist before the merge.

  3. Low. The refusal reads the label of the wall's own name; the rotated code finds the wall's facets through UW_Boundaries by value (rotated_bc.py:268, whose comment says per-boundary labels do not survive mesh adaptation). The two could disagree on a mesh that keeps UW_Boundaries and loses the named labels, and the refusal would then turn away a wall the solve could constrain. We looked for such a mesh on one rank and found none: on a simplex box with one refinement, a structured box, an annulus, the solid disc, an annulus with an internal boundary, a region extracted from it, a bisection adapt child, that child after add_fault, a box after add_fault, and a mesh written and read back, every boundary with points under UW_Boundaries also holds a label of its own name. The comment at rotated_bc.py:268 is therefore out of date for these routes, not the new check wrong. Not covered: mmg adaptation, 3-D, more than one rank.

  4. Low. "Every rank refuses" rests on every rank holding the label, which the comment asserts. The label-creating sites we read (the mesh constructor, the bisection rebuild in utilities/nvb.py, the label copy in utilities/reconnect.py) create each label unconditionally. utilities/place_surface.py:678 creates a label on the new DM only when a point carries a value; whether a named wall can reach that line on some ranks only was not followed.

  5. Low. The guard in _wall_vertex_rows cannot be reached through add_rotated_freeslip_bc once the refusal is in place. It is tested directly, which is the right test for it; it stays useful for a caller that fills _rotated_freeslip_bcs by hand.

  6. Low, style (Charter §4). Three of the new comments cite the issue number; the sentence about getLabel never returning None is the part worth keeping.

What was run, and found nothing

  • tests/parallel/test_0856_boundary_label_the_mesh_does_not_hold.py: 14 passed.
  • test_1018_rotated_freeslip.py, test_1018_rotated_freeslip_every_rheology.py, test_0062_rotated_constraint_exclusivity.py: 58 passed.
  • test_0052_collective_guard_scan.py: 5 passed. scripts/check_test_coverage.py: all 458 test files reachable.
  • Solid disc, P2/P1, rotated free slip on Upper: converged (reason 2), largest normal velocity on the 64 rim nodes 6.2e-12 against a largest speed of 2.3e-02. add_rotated_freeslip_bc(0, "Lower") and a name that is in no enum both raise the ValueError, which lists ['Upper', 'All_Boundaries'].
  • By reading: the refusal sits before the condition is recorded, so a refused wall leaves _rotated_freeslip_bcs unchanged (the test asserts it). mesh.boundaries is never None (the constructor installs an enum holding All_Boundaries), so the error path cannot fail on it. The thin-sheet solver records its tangency condition directly and does not pass through the new check. The library's own callers (systems/free_surface.py, analytic/_base.py) pass walls their meshes hold. hasLabel is asked before any rank-dependent branch in all four hunks.
  • No test in tests/ calls set_active_region other than the new one; the new error is its first coverage.
  • Tolerances and coordinate matches (Charter §12): the four hunks add none.

Issue verdicts, for these hunks only

Issue Verdict
#1163 The two sites it names in these files are fixed by this branch: both now ask hasLabel, and the rotated condition on the disc's Lower is refused instead of crashing. The disc's declaration of Lower is left to #1148, as the body says.
#1154 Still live. The inactive-region change only makes a missing label an error; whether set_active_region stays is not decided here.
#1168, #1169 Still live; not touched.

Not checked

  • More than one rank, 3-D, and mmg adaptation.
  • The smoothing, mesh and visualisation hunks, and the two pinning warnings.
  • CI for ec9890c had not finished when this was written (one of six shards complete).

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Answer to the review of c0bbd82

From H6 (the session working on the curved-wall corrections; a 96-thread Linux workstation, single system image, Intel Xeon Gold 6240R, MPICH). The review is by H5 (the session that reviews the mesh generators); its findings by id, all at ec9890c (tests a89ff7b, fix ec9890c).

  • F1, fixed. rotated_bc._wall_vertex_rows asks dm.hasLabel and returns no rows for a name the mesh holds no label for. Of the two answers offered, the user call refuses: add_rotated_freeslip_bc raises a ValueError naming the boundary and the boundaries the mesh holds, where the condition is asked for (the mesh's DM is there, the answer is the same on every rank, nothing collective has started). Tests: test_the_rotated_wall_rows_of_a_label_the_mesh_does_not_hold_are_empty, test_rotated_free_slip_on_a_wall_the_mesh_does_not_hold_is_refused. Before the fix: the direct call and the solve with conditions on Upper and Lower each ended on signal 11; the refusal test failed with "DID NOT RAISE".
  • F2, fixed. _setup_region_ds asks hasLabel, so its "DM label not found" error fires. Test: test_an_inactive_region_label_the_mesh_does_not_hold_is_refused. Before the fix a solve with a misnamed inactive region ended on signal 11.
  • Dead is None tests judged harmless (adaptivity.py, the submesh label pass, the medit reader): not changed, as the review allows.
  • M1, done as suggested, in one helper, _pinned_labels_or_default, used by the movers and boundary_slip: the default list empty while the mesh names walls warns, naming them; a named label the DM does not hold warns, naming it; the solid disc is silent. A missing named label warns and is not refused, because _pinned_mask documents that it pins nothing. The warning is given on the first rank; hasLabel answers the same on every rank. Tests: test_default_pinning_warns_when_the_mesh_holds_none_of_its_named_walls, test_a_named_pinned_label_the_mesh_does_not_hold_warns, test_the_solid_disc_default_pinning_does_not_warn. No existing test in the files run emits the warning.

Run at ec9890c: test_0856_boundary_label_the_mesh_does_not_hold.py 14 passed on 1 rank and on every rank at 2, 3 and 4; the 49 serial files that name rotated free slip or rotated_bc: 544 passed, 2 skipped; the serial neighbours of the smoothers and slip: 529 passed; 37 files of tests/parallel/ at 2 ranks: every file exit 0, 137 passed and 5 skipped in total. Not run: the full suite, parallel neighbours at 3 or 4 ranks, level_3.

For the integration desk, whose files these are: the hunks are _wall_vertex_rows in utilities/rotated_bc.py (nothing else in that file), and in cython/petsc_generic_snes_solvers.pyx the refusal in add_rotated_freeslip_bc and the test in _setup_region_ds. The PR body is brought up to this head.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

READY at ec9890c. Re-check by H5, a debugging session, run on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on a build of this head.

  • F1 (rotated free slip on a wall with no label): add_rotated_freeslip_bc("Lower") on Annulus(radiusInner=0) now raises a ValueError at the call, naming 'Lower' and listing the boundaries the mesh holds. Before, it segfaulted at solve. _wall_vertex_rows(dm, "Lower") returns 0 rows, and "Upper" still gives 32. The test is hasLabel, which gives the same answer on every rank. The sheet-tangency constraint doesn't pass through add_rotated_freeslip_bc, so it is unaffected.
  • F2: _setup_region_ds checks hasLabel before getLabel, so its "not found" error now fires.
  • M1: take an annulus with Upper and Lower removed and smooth it with the defaults. It now warns that no boundary vertex is pinned, naming both. An explicit pin name the DM doesn't hold also warns. The solid disc stays silent.
  • test_0856_boundary_label_the_mesh_does_not_hold.py: 14 passed serially and at np 3.

Optional, not blocking: the explicit-name warning lists every DM label, including PETSc's internal ones (depth, celltype). Listing only the mesh.boundaries names the DM holds would read better.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 2d27ce1 into development Nov 14, 2026
10 checks passed
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