Repository navigation
The monotone clamp bounds a value by the cell it was interpolated in (#682, #994) - #1153
Conversation
|
READY with conditions at e65b9b6. The fix does what it says: a clamped linear field is exact at every rank count, the bound matches an independent containing-cell bound exactly, and values at interior points are bit-identical from np 1 to np 8. The conditions are two small edits to the PR body and docstrings, listed at the end. One of them covers a case the PR does not mention: a point that lies exactly on a face shared by two cells. Reviewed by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). This is the parallel half and the evidence check. W1 (integration) checks the locator plumbing separately. Head e65b9b6, base development 116fc45, both prebuilt. Every MPI job ran under 1. The #682 probeSetup:
Calls: Seed 5, the probe in #682 and the PR's test. Clamped P1 scalar, points wrong by more than 1e-10, and the largest error:
The base numbers match H1's comment on #682 exactly. The vector's entry 0 gives the same counts. Seed 682, all fields. Head, all ranks at np 1, 2, 4 and 8:
Base at the same seed:
2. The PR's tests
3. The failing-first table in the body
The MATRIX row was probably measured on d66c7da and changed before 116fc45. The fix holds either way. Cost, 4. Free surface: the one default that changes
Case: the Crameri Case-2 plume from
Enclosed-area drift after 3 steps (relative to the start):
What this shows:
5. Seams, faces, vertices and points outsideSame mesh, P1 linear
Partitions: default, and a shell partitioner (
Base under Outside the domain, values differ from serial by up to 0.16 ( A point exactly on a shared face, not at a node. Points at 0.3 along every interior edge, P2 front:
The unclamped values agree to 2e-15. P1 Example: point (0.356, 0.968), unclamped 1.0083, serial clamp 0.99615, one rank at np 4 ( This matters little in practice:
Even so, the PR claims "the same bound at any rank count" and "partition-independent", and this case contradicts it. See condition 1. 6. Semi-Lagrangian remap and
|
| comparison | P2 front, max diff | P1 field, max diff |
|---|---|---|
| head, clamp on, np 1 vs np 2 and np 4 | 1.63e-3 | 4.3e-4 |
| head, clamp off, np 1 vs np 2 and np 4 | 1.63e-3 | 4.3e-4 |
| base, clamp off, np 1 vs np 2 | 1.63e-3 | n/a |
| head, np 2 vs np 4, clamp on / off | 1.57e-5 / 1.57e-5 | n/a |
| base, clamp on, np 1 vs np 4 | 0.77 | 0.125 |
The clamp's own effect (on minus off) at np 2 and 4 matches serial to 1.9e-5 at the 1460 points where it acts. So the clamp adds nothing to the partition dependence.
The 1.6e-3 difference between serial and parallel without the clamp is the same on base. It is not this PR. It is probably the nodal-history difference #682 records as fixed on #800 [read]. As a result, "same as serial to round-off" cannot be shown with this case: the unclamped path is not serial-equal either.
Remap. remesh_with_field_transfer with a smooth interior move of 1% of the box, REMESH_MONOTONE=clamp. Completes at np 1, 2 and 4. Head: np 1 vs np 4 identical (0), np 2 within 7.5e-13. The clamp does not act (on minus off is 0), and the P1 linear field is exact to 1.3e-15. Base at np 4: off by 7.2e-2 (front) and 1.8e-2 (linear).
7. A rank with no cells
Every run completed with no hang:
- shell layout leaving the last rank empty, at np 2 ([162, 0]), np 3 ([87, 75, 0]) and np 4 ([62, 49, 51, 0]);
- a coarse mesh (cellSize 0.5, 14 cells) at np 8 with the default partition ([0, 3, 2, 2, 0, 3, 2, 2]);
- the same coarse mesh at np 4 with one rank empty.
Clamped values at vertices and edge midpoints equal serial to 1e-15 on every rank. That includes np 2, which the PR's own no-cells case skips.
8. Attribution and coverage
- One commit, authored as
Claude <noreply@anthropic.com>. There is no Co-Authored-By trailer, and the message ends with the team line. Six of the last 30 commits on development carry the same author. - The body ends with "Underworld development team with AI support from Claude Code".
- The coverage gate passes, and
scripts/test.shadds the new file to batch 3.
Code read [read]
DMPlexCellClosureFieldRange_UWreads the field's DOFs byPetscSectionGetFieldDof/Offsetover the closure, usingk = d % nc(node-major, components interleaved). That matches PETSc's layout, and the P2 results above confirm it.- An unlocated point (
-1) is left alone. Those points come from the RBF rung, and the outside points above show the clamp does not act there. - Eligibility is decided before any collective, through
_monotone_source_variable, so a refusal is the same on every rank. remap_var_setstill catches theValueErrorand falls back to plain evaluation. On head that refusal is raised before the collective, so the fallback is rank-consistent.
Conditions
- Point on a face. In the register row, the
evaluate/global_evaluatedocstring and thescripts/test.shcomment, say that the bound is partition-independent at points interior to a cell. At a point exactly on a face shared by two cells, the bound comes from whichever cell the evaluating rank located, so a P2 or higher value there can differ between ranks. Measured above: up to 3.0e-3 on a ±1 front. A deterministic tie-break, or a halo-aware union of the face's cells, can be a follow-up issue. It is not needed for this merge. - Body corrections.
- The MATRIX row's "refuses one entry" does not happen at the base this branch sits on. At 116fc45 the entries come back wrong (5.2e-2 serial, 10.8 at np 2) and are not refused.
- The "has not been measured" note on the free surface can be replaced by section 4: about 4e-4 in composition and 0.1% in enclosed area over 3 steps of Case-2. Partition dependence drops from 2.3e-3 to 4.4e-5, the level of the clamp-off control.
- "np above 4" is now covered, at np 5 and 8 (oversubscribed).
Underworld development team with AI support from Claude Code
…682, #994) monotone="clamp" clipped each value into the range of the dim + 1 DOFs nearest the point, from a kd-tree over the asking rank's nodes. Those nodes need not enclose the point: a P1 field linear in x and y, which the clamp must leave alone, was clipped at 5 of 400 interior points in serial. In parallel they are the wrong rank's nodes for a point another rank owns: 48 and 74 of 400 wrong at np 2, by up to 0.61. On a rank with fewer than dim + 1 DOFs the query failed on that rank alone (#994). The bound is now the per-component min and max of the source variable's DOFs in the closure of the cell the value was interpolated in, P2 and higher edge, face and cell DOFs included. The cell is the evaluator's own: DMInterpolationGetCells_UW copies out the cells DMInterpolationEvaluate_UW takes the closure of, petsc_interpolate returns them, and evaluate_nd applies a `limit` callback with them on the rank that evaluated the points, in every pass of global_evaluate_nd. DMPlexCellClosureFieldRange_UW reads the range from mesh.lvec, the vector the evaluator interpolates from. Nothing is located twice and no distance is used. A point no cell owns keeps its inverse-distance value, a convex combination, which is bounded already. Whether the expression can be clamped is decided from the expression before any evaluation, so a refusal is the same on every rank. "pick" is unchanged. UW_MONOTONE_CLAMP_BOUND=nearest restores the earlier bound. Tests: tests/parallel/test_0682_clamp_by_containing_cell_parallel.py (serial in batch 3 and under --p N): H6's linear P1 probe, a Q1 and Q2 bound against the structured cell's nodes, a 2x3 MATRIX entry by entry, P2 edge DOFs, a rank with no query points, a rank with no cells, and #994's one-cell DG0 rank. On development 2, 6 and 7 of 8 fail at np 1, 2 and 4, and np 2 and 4 hang; all pass here. test_0760's clamp oracle is now the containing cell, and the switch back is tested against the nearest-DOF bound. Underworld development team with AI support from Claude Code
e65b9b6 to
1133926
Compare
|
Re-check of #1153 at 1133926: READY. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), following up its review at e65b9b6. Rebase onto #1142.
Runs on this head (built from source):
Text. The three points from the first review are met:
One small inconsistency in the body, not blocking: "Not tested: ... np above 4" sits beside "H1's review also ran the file at np 5, and a P1 linear field and a P2 front at np 8". It could read "np above 4 in this branch's own runs". Not re-run: the first review's np 5 and np 8 runs, the free-surface case, and the 3-D and cost checks. The compiled code those exercised is unchanged. Underworld development team with AI support from Claude Code |
…cell-682 # Conflicts: # docs/developer/CHANGELOG.md
Fixes #682. Fixes #994 (the limiter's rank-local failure on a rank with few DOFs).
monotone="clamp"now bounds each value by the source variable's DOFs in the closure of the cell the value was interpolated in, on the rank that evaluated it. Louis approved this design on 2026-11-13.The defect.
evaluateandglobal_evaluatewithmonotone="clamp"(orTrue) clipped each value into the range of thedim + 1source DOFs nearest the point. The nearest DOFs came from a kd-tree over the asking rank's own nodes. Two things go wrong:dim + 1DOFs, the query also failed on that rank alone (Remesh limiter fails on a rank with too few DOFs, and that rank alone keeps its old values #994).The first case below is the probe from H6, the review desk for curved walls. Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH):
The fix.
petsc_tools.c):DMInterpolationGetCells_UWcopies out the cellsDMInterpolationEvaluate_UWtakes the closure of: the hint it was given, or the cellDMLocatePointsfound.DMPlexCellClosureFieldRange_UWcomputes, per cell, the per-component min and max of one field over the cell's closure. It readsmesh.lvec, the vector the evaluator interpolates from. Every closure point that carries the field's DOFs counts, so P2 and higher edge, face and cell DOFs are included.CachedDMInterpolationInfokeeps the located cells.petsc_interpolate(..., return_cells=True)returns them.evaluate_ndtakes alimit(values, cells)callback and applies it after interpolation, before any packing.global_evaluate_ndpasses it to every pass, so the bound is applied on the rank that evaluated the point, where the cell and its closure are local.functions_unit_system.py):_containing_cell_clamp(expr)builds the callback. Whether the expression can be clamped (one MeshVariable, or one entry of one) is decided before any evaluation, from the expression alone, so a refusal is the same on every rank. A MATRIX entry is mapped to its stored column through_data_layout."pick"is unchanged.Callers whose clamped values change.
uw.function.evaluate(..., monotone="clamp" | True)anduw.function.global_evaluate(...), called directly.SemiLagrangianDDt withmonotone_mode="clamp"(systems/ddt.py, the trace-back sample), andIntegrationPointSemiLagrangian(its per-component history writer).AdvDiffusionSLCN(..., monotone_mode=)passes the option through.systems/free_surface.pyturnsmonotone_mode="clamp"on for its composition transport, so free-surface results change. This is the one place the clamp is on by default. The free-surface test files pass (28). H1 measured the change in its review, on the plume case (case 2), over 3 steps: the composition changes by 4e-4 and its area by 0.1 %. Its partition dependence drops from 2.3e-3 to 4.4e-5, the same as with the clamp off.UW_MONOTONE_CLAMP_BOUND=nearestgives development's values back to 1e-13.discretisation/remesh.pywithREMESH_MONOTONE=clamp, which is off by default. Since remap_var_set: skip a variable on every rank or none; stop swallowing a rank-local raise (#960) #1142 the limiter is used only where_limiter_appliessays it applies, decided before the evaluation.rbf_interpolate(monotone=)on mesh and swarm variables (ckdtree.pyx). That is a separate stencil limiter.Register row (changes to solver defaults).
monotone="clamp"inevaluate/global_evaluate; on by default in the free-surface solver's composition transportdim + 1nearest DOFs on the asking rankUW_MONOTONE_CLAMP_BOUND=nearest(tested in test_0760)Partition independence: for points inside a cell. A point inside a cell has the same bound at any rank count. A point exactly on a face that two cells share, not at a node, takes the bound of whichever cell the evaluating rank's locator found. H1 measured P2 values there differing between ranks by up to 3.0e-3 on a ±1 front (random layout, np 4). Settling such ties by the mesh is part of the locator rework ("ties settled by the mesh"), which is in progress; it is not a new issue.
Tests.
tests/parallel/test_0682_clamp_by_containing_cell_parallel.py, tier B, run serially in batch 3 and under--p N. Its oracle does not use the library's locator: on a structured quad mesh the containing cell isfloor(x·n), and a Q2 cell's nodes are at known coordinates. Eight cases:Results:
test_0760's clamp oracle is now the containing cell (all 16 nodes of a Q3 cell); development fails it. A new test checks the switch back against the nearest-DOF bound.Also run:
Cost.
global_evaluateof a P2 field at 200,000 points, 1/64 box, serial: 1.82 s clamped against 1.73 s unclamped. Development: 1.91 s against 1.67 s.Merge order.
limitercase patched_apply_monotone_limit, which the default clamp no longer calls. The case now forces the failure where a limited evaluation returns, on rank 1, after its collectives. test_0791 passes, 5 of 5.Not tested: 3-D meshes; np above 4; how much the free-surface composition changes in a long run.
Reviews: H1 (the review desk) reviews; W1 (integration) checks the locator plumbing.
Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)
level_*andtier_*markers (S8)maybe_/try_/do_) and no commented-out code (S3, S4).array/mesh.X.coords— nowith ....access(...), nomesh.data(S7)pixi.toml/pixi.lockor other dependency changes riding in an unrelated PRUnderworld development team with AI support from Claude Code