Skip to content

test_1123 / test_1183: a sheared box that cannot tangle; the #1183 fallback tested directly (stacked on #1213) - #1214

Merged
lmoresi merged 5 commits into
developmentfrom
test/sheared-fixture-cannot-tangle
Nov 16, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
test/sheared-fixture-cannot-tangle

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1213: merge that first. This branch is rebased onto #1213's head (d106c7d); the change here is two test-only commits.

Why. test_1123's sheared fixture was gmsh's box under #1123's linear shear, plus sine terms of amplitude 0.03. gmsh builds differ: 1094 cells on macOS against 1086 on Linux (W1). On one macOS build the map turned a cell inside out, so the walk test missed 1110 of 2e5 points, because a tangled mesh has no right answer. test_points_near_interior_edges_are_exact used the same fixture, unguarded.

The fixture (tests/parallel/sheared_box_fixture.py, added by #1213):

  • gmsh-independent: a structured box of n³ cubes, each split into six tetrahedra along the axis-ordered corner-to-corner paths, so it is the same on every platform. A PETSc 3-D simplex box would need tetgen, which our PETSc does not have.
  • The same linear shear (det 0.196, smallest singular value 0.175), with the sine amplitude at 0.025. The sine terms' gradient is a scaled permutation matrix of norm 2π·0.025 = 0.157, below 0.175, so the map is invertible. On this 6³ box the worst cell keeps 0.082 of its volume ratio; 0.03 gave 0.027 on the Linux gmsh box.
  • A collective assertion that no cell turned over, so a future change fails loudly instead of silently.

test_1123 (serial and parallel) and test_1183 use it.

Regression power, measured on the new fixture.

test development before #1175 (222f820 base) before #1190 (d583072) now
test_1123, inside points near edges classified exterior, serial 116 to 125 per distance 0 0
test_1123 parallel, inside points owned by no rank 392, 47, 10 at np 1, 2, 4 0, 1 at np 2 0
test_1183, the fallback with the walk forced to miss (2e4 points) lost 1427, 1332, 1200 lost at np 1, 2, 4 0

The single point before #1190 at np 2 is points_in_domain's sign test, which #1213 fixes.

Why #1183's 2-per-million case cannot be kept. Those points sat in near-degenerate cells of one gmsh build: at amplitude 0.03 the worst cell kept a volume ratio of 0.027, and the same shear turns a cell over on another gmsh build. On every valid, non-tangling shear tried, the walk misses none of 1e6 sampled points (or 1, at one rank count): amplitudes 0.01 to 0.0275, on the gmsh box and on structured 5³ to 8³ boxes. So the fallback is tested directly: with the walk patched to miss every point, each contained point must still be found, in a cell that contains it. That is what #1190 added, and before it the 50-nearest-centroid search lost 1200 to 1427 of 2e4.

The walk's boundary-following rule (H1's review). On the structured fixture, the walk from the nearest control point's cell loses nothing even without that rule, so test_the_walk_finds_every_contained_point_on_a_non_convex_boundary now pins the guarantee but not the rule (its docstring says so). The new test_the_walk_from_boundary_cells_and_its_recovery starts each of 2e5 points at a random boundary cell and asserts:

  • the walk returns only cells that contain their point;
  • every point it loses left through the boundary (no cycling, no step limit), and it loses fewer than 0.1 %: 54 of 2e5;
  • the restarts and the exact fallback place all 54, each in a containing cell.

With the walk crossing the most violated face even when it is a boundary face (the rule before #1175's fix), it loses 1232 and the test fails; H1 measured 1189.

After #1213: points_in_domain is exact serially too, so test_1123's parallel swarm test no longer skips at np 1, and its docstring is updated.

Tests run. The three files, with #1213's, pass at np 1, 2 and 4 (12, 6 and 7 tests; the rest skip by rank count). The coverage gate passes. Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH). H1 reviews.

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)
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7)
  • Parallel safety considered (S11): the fixture's assertion is reduced over ranks; np 1, 2, 4 checked
  • 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

…claims agree with global_evaluate

points_in_domain, which a swarm's migration reads, decided a point far from the local
boundary by a boundary-face sign test standing in for containment (Style Charter
section 12). On #1123's sheared mesh it called contained points exterior: serially 449
of 3825 near-edge points, and at np 2 one inside point owned by no rank, whose
particle a swarm then lost, while global_evaluate's ownership (the exact locator,
#1175) had it. On a straight-sided simplex mesh a point is now in a rank's domain
when a local cell contains it; a point no local cell contains takes the face
tolerance development applied near the boundary (the evaluation tolerance in
parallel, the cell-wall test's own serially), and only within 2 max_radius^2 of the
local boundary, as before.

Claims change only by contained points: on unsheared 2-D and 3-D boxes and an
annulus, the strict claims (migration's) are identical to development at np 1, 2
and 4, and serially every variant is. A swarm in solid rotation on an annulus keeps
all 15200 particles over 20 steps at np 1, 2 and 4, as on development.

tests/parallel/test_1209_points_in_domain_exact_parallel.py (with the structured
sheared box, tests/parallel/sheared_box_fixture.py): development leaves 449 and 1
inside points in no domain at np 1 and 2; none here, and a swarm keeps every one.

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

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.

… mean on a simplex mesh (W1's review)

Underworld development team with AI support from Claude Code
@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 8e36b64: changes requested. This asks for one small change. The fixture is sound, the mesh is the same at every np, and the regression power claimed for #1175 and #1190 reproduces exactly. One test, however, has silently lost all its power on the new fixture: test_the_walk_finds_every_contained_point_on_a_non_convex_boundary. The PR gives #1183's case a direct test instead, and this case needs the same treatment.

Build. The PR's library code is #1213's, so the head ran on the same overlay used for #1213: the eccae6d-matched build with the branch's .py files. The tests came from 8e36b64. Every run used 4 cores, with at most 4 ranks, under the MPI supervisor and an outer timeout.

1. The diff and the stack

2. The fixture

Invertibility. The map is Y = A X + W (sin 2πy, sin 2πz, sin 2πx).

quantity value
singular values of A 1.77263, 0.63006, 0.17549
det A 0.196
2π W (W = 0.025) 0.15708

The sine terms' Jacobian is a permutation pattern with entries of magnitude at most 2πW. Its 2-norm is therefore at most 0.157, below σmin(A) = 0.175, so A + D is never singular and the continuous map is injective on the box.

The argument also carries over to the discrete mesh, which the docstring does not say but is worth a sentence. Each Kuhn tetrahedron's three path edges are axis-aligned steps. Each sine component depends on one coordinate, so the P1 interpolant's gradient of that component is exactly (0, Δ/h, 0), or its permutation. By the mean value theorem |Δ/h| ≤ 2πW. Every cell's affine Jacobian is therefore A + D_cell with the same bound, so no cell can turn over. The construction guarantees it, not only the check.

The no-turnover assertion is collective. flipped is an allreduce(SUM) of each rank's local count, and every rank asserts on the same reduced value. kuhn_box builds on rank 0 and distributes with a collective createFromCellList on COMM_WORLD.

Same mesh at every np. The values below are gathered from every rank, with cells deduplicated by centroid:

np cells Σ abs(vol) vol checksum (sorted by centroid, weighted by rank in that order) centroid checksum min / max volume min shape quality
1 1296 0.196000000000000 127.106000000000 2916.0000000000 6.33e-5 / 1.95e-4 0.0041
2 1296 0.196000000000000 127.106000000000 2916.0000000000 6.33e-5 / 1.95e-4 0.0041
4 1296 0.196000000000000 127.106000000000 2916.0000000000 6.33e-5 / 1.95e-4 0.0041

The values are identical, and the volume sum equals det A. Shape quality here is volume over longest edge cubed, normalised to 1 for a regular tetrahedron. Its minimum of 0.0041 shows the cells are strongly sheared, as intended, but none is degenerate.

3. Regression power

Pre-#1175 is the first parent of #1175's merge on development's first-parent history (2bc779d^1 = 862fd35). Pre-#1190 is the same for #1190 (88d98ac^1 = d583072). For each, I overlaid every .py file of that commit on the eccae6d-matched build.

Both commits differ from that build in compiled code:

The pre-#1175 Python does not accept that keyword. For that overlay only, I added exact_location=False to its signature, unused, as the code was before #1175. With that one-line shim both overlays are valid for these tests.

test head 8e36b64, np 1 / 2 / 4 pre-#1175, np 1 / 2 / 4 pre-#1190, np 1 / 2 / 4
serial test_points_near_interior_edges_are_exact [1e-8, 1e-6, 1e-4] pass fail: 116, 125, 125 exterior pass
test_every_inside_point_is_owned_and_exact (parallel file) pass fail: 392 / 47 / 10 unowned pass / fail: 1 / pass
test_points_in_domain_and_a_swarm_keep_every_inside_point skip / pass / pass skip / fail: 49 / fail: 11 skip / fail: 1 / pass
test_the_fallback_finds_every_point_the_walk_misses (new) pass fail (no locator) fail: 1427 / 1332 / 1200 of 2e4
test_every_contained_point_is_owned_on_the_sheared_mesh (#1183) pass fail: 52774 / 24724 / 11382 pass / pass / pass
test_the_walk_finds_every_contained_point_on_a_non_convex_boundary pass fail (no locator) pass

The PR body's numbers reproduce exactly: 116 to 125 per distance, 392/47/10, and 1200 to 1427.

On development (eccae6d) at np 2, both parallel test_1123 cases fail with 1 inside point unowned. That is #1213's defect, so this PR depends on #1213, as its stacking already says. As the body says, the #1183 sampling test no longer separates pre-#1190 from the head. The new direct fallback test carries that regression, and does.

4. The test files

Against development's versions, no assertion is changed or loosened. Each test only swaps its inline gmsh mesh for sheared_box_fixture.sheared_box(), and the docstring numbers are updated. The one addition is the direct fallback test. It forces locate to miss, requires _robust_owning_cells to find every point, and checks the returned cell contains it (barycentric ≥ −1e-12). That is a sound way to test the fallback on its own.

Finding: the non-convex-boundary walk test has lost its power. I re-implemented the walk as it was before the boundary fix (cross the most violated face; leave if it has no neighbour). I ran it on the test's own 2e5 points with the test's nearest-centroid starts:

mesh current walk: lost old walk: lost
new structured fixture (0.025) 0 0
the old gmsh fixture (0.03), this machine's gmsh 0 7
annulus 1/16 0 0
spherical shell 0.15 0 0

On the new fixture the test passes with or without the fix. Its docstring still cites "lost 7 of 2e5 on the old gmsh fixture", which is true but no longer tested.

A direct test, like the one written for #1183, is within reach. On the new fixture, from random boundary-cell starts the old walk loses 1189 of 2e5 and the current walk 55; from random cell starts, 690 against 33. The current walk still loses some because a far start can be walled off or run out of steps; locate's restarts are there for that. A test could therefore:

  • either assert, from boundary-cell starts, that the boundary rule loses far fewer points than the old one;
  • or assert that locate with a nearest-centroid restart loses none from boundary-cell starts.

Either is enough. The minimum fix is to say in the docstring that the fixture no longer exercises the case.

Nit. In the parallel test_1123, test_points_in_domain_and_a_swarm_keep_every_inside_point still says "Serially points_in_domain keeps its boundary-sign test, which still loses some of these points: the swarm follow-up". It also skips serially because "the serial migration path is unchanged by #1175". After #1213 neither is true: serially the branch loses 0, and #1213's own test covers it. The test could now run at np 1 as well.

5. The gmsh-specific mesh

The old gmsh-built sheared box (cell 1/6, wave 0.03) is removed from all three files, not kept beside the new one. Development's versions had no gmsh or mesh-fingerprint skip, so there is none to remove or keep. The only remaining gmsh meshes in these files are unsheared: the 2-D vertex test in test_1123 and the graded box in test_1183, and neither depends on a build-specific tangle.

6. Neighbours

run result
test_0756, test_0760, test_0777, test_0786, test_0960, test_1076, test_1093, test_1175, test_1213 and test_0761 at np 2 51 passed, 8 skipped per rank, 0 failed
test_0761, test_0113, test_0784 serially 43 passed, 2 skipped
the three changed files, as in section 3 all pass at np 1, 2 and 4

Not run:

  • the full suites;
  • np 3, so test_a_rank_with_no_cells_locates_nothing_instead_of_raising ran only at np 4, where it passes;
  • macOS, so the new fixture's platform independence follows from the construction and is not measured.

All logs and scripts are kept by the reviewer.

Underworld development team with AI support from Claude Code

…fallback tested directly

The sheared fixture was gmsh's box with #1123's shear and sine terms of amplitude
0.03. gmsh builds differ (1094 cells on macOS against 1086 on Linux), and on one
macOS build a cell was turned over, so the locator tests had no right answer.

tests/parallel/sheared_box_fixture.py (from #1213): a structured box of cubes split
into six tetrahedra, independent of gmsh, with the sine amplitude at 0.025: the sine
gradient's norm (2 pi 0.025 = 0.157) is below the linear shear's smallest singular
value (0.175), so the map is invertible, and the fixture asserts, collectively, that
no cell turned over. test_1123 (serial and parallel) and test_1183 use it.

Regression power on it: before #1175, test_1123 fails at np 1, 2 and 4 (116 to 125
inside points classified exterior per distance; 392, 47 and 10 owned by no rank).
#1183's 2 per million lived in near-degenerate cells of one gmsh build and no valid
fixture reproduces them; test_1183 tests the fallback directly instead: with the walk
forced to miss every point, the fallback must find them all, which before #1190
loses 1200 to 1427 of 2e4.

Underworld development team with AI support from Claude Code
…el test runs serially too (H1's review)

On the structured fixture the walk from the nearest control point's cell loses no
point even without the boundary-following rule, so that test pins the guarantee but
no longer the rule. test_the_walk_from_boundary_cells_and_its_recovery starts every
point at a random boundary cell: the walk returns only containing cells, every point
it loses left through the boundary, it loses fewer than 0.1 % (54 of 2e5), and the
restarts and exact fallback place every one. With the walk crossing the most
violated face even when it is a boundary face (the rule before), it loses 1232 and
the test fails.

test_1123_exact_locator_parallel: since #1213 points_in_domain is exact serially too,
so the swarm test no longer skips at np 1; docstrings updated.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi force-pushed the test/sheared-fixture-cannot-tangle branch from 8e36b64 to 3e80819 Compare November 16, 2026 07:47
@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 3e80819: ready to merge on green from this review (parallel runs; the code review is the integration lead's). The one item I asked for is done: the boundary-following walk is now tested from far starts, and the test has power.

Stack. The branch sits on d106c7d, now in development through #1213's merge (1bd2b66). Against development the diff is test-only, in three files: tests/test_1123_exact_locator_simplex.py, tests/parallel/test_1123_exact_locator_parallel.py and tests/parallel/test_1183_contained_points_owned_parallel.py. Its src/ is identical to development's. Development's compiled sources are unchanged from the build used before, so the runs below use that build with development's .py files.

The new test, test_the_walk_from_boundary_cells_and_its_recovery. It is a serial test and skips at np > 1.

code result
head passes; the walk loses 54 of 2e5, all through the boundary, and all 54 are placed by _robust_owning_cells
the walk before the boundary rule (my own re-implementation, swapped in for SimplexLocator.walk on the class before pytest starts) fails: "1232 of 200000 lost"; the five other tests in the file still pass
before #1175 (overlay plus the one-line signature shim) fails, but only for lack of API (Mesh has no _simplex_locator), as the old walk test does
before #1190 passes, as expected: the boundary rule came with #1175, and the 54 are recovered there too

The mutant count matches the one in the PR. The test checks three things:

  • every cell the walk returns contains its point;
  • every lost point left through the boundary, ruling out cycling or the step limit;
  • every lost point is then placed in a containing cell.

These and the 0.1% bound are the right guarantees to pin.

Docstrings and assertions against 8e36b64.

  • No assertion is removed or loosened. The only change to an existing test is that test_points_in_domain_and_a_swarm_keep_every_inside_point no longer skips serially, so it now runs at np 1 as well. Against development before points_in_domain uses the exact locator on simplex meshes: a swarm's claims agree with global_evaluate #1213 it fails serially with "449 inside points owned by no rank", the number its docstring gives.
  • The old walk test's docstring now says what it pins (the nearest-start guarantee) and that it holds on the structured fixture without the boundary rule. That matches my earlier measurement: 0 of 2e5 lost either way.
  • Nit, not blocking: the new docstring quotes 1189 of 2e5 for a walk that leaves through the boundary. That was my measurement, from a different random set of boundary starts. With this test's own starts the old walk loses 1232. Either number is honest, but 1232 is the one the test reproduces.

Runs.

run result
the three changed files at np 1 11 passed, 1 skipped
at np 2 5 passed, 7 skipped per rank, 0 failed
at np 4 6 passed, 6 skipped per rank, 0 failed
neighbours at np 2 (test_0756, test_0760, test_0777, test_0786, test_0960, test_1076, test_1093, test_1175, test_1213, test_0761) 51 passed, 8 skipped per rank, 0 failed

At np 2 and 4 the skips are the serial-only tests. The earlier findings on the fixture still hold, since the fixture is unchanged: invertibility, the collective no-turnover check, and an identical mesh at np 1, 2 and 4. Not run: the full suites, np 3, and macOS. All logs and scripts are kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 1c3da53 into development Nov 16, 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