Repository navigation
Mesh.remesh transfers past an empty rank, units included; global_evaluate no longer transposes - #1002
Conversation
…finement store every shape in its slot What was wrong. global_evaluate returned its result through a MATRIX swarm variable. The array view wrote by row and the read went through _data_layout, which stores a MATRIX by column, so every non-symmetric result came back transposed: [[1, 2], [3, 4]] read [[1, 3], [2, 4]]. Its RBF route, taken for a point no rank holds, read the column at the component's position in the symbol, which transposes a MATRIX too. Three users had come to rely on that transposition: - mesh.deform (remap_var_set) reshapes the result by row into storage; - the parallel route of _refine_prolongate and _refine_restrict does the same; - the monotone limiter takes bounds by stored column and applies them by row. Each was right for a square MATRIX only because the transpositions cancelled. Each was wrong for a non-square MATRIX, and the reshape raised on a symmetric tensor. The fix. - global_evaluate writes its result into storage by _data_layout. - rbf_evaluate reads the column the function records. - The reshape and the limiter follow _data_layout. - The layout is ddt._evaluated_in_storage_layout, split out of ddt._write_evaluated, which keeps its column-by-column write. meshVariable_lookup_by_symbol and SwarmVariable.array are unchanged. Units. deform and refinement pass the evaluated values on as plain numbers, as development does, so their units behaviour is development's. They have units faults of their own (review of #909, round 3, H1, H2, P1), left for later. The limiter still compares dimensional values with non-dimensional bounds (its TODO(units)), also unchanged. Behaviour to note. A non-symmetric MATRIX expression or variable through global_evaluate now comes back in its components, where it came back transposed. Tests. tests/test_0784_global_evaluate_component_slots.py, serial: on development 8 failed, 2 passed (the passes are the TENSOR controls); here 10 passed. tests/parallel/test_0785_evaluated_values_reach_storage_parallel.py, listed in batch 3 of scripts/test.sh. On development, serial: deform fails with "cannot reshape array of size 60 into shape (15,3)". Here: 3 passed at np 1, 2, 3. Its constant-field deform with units passes on both: it guards against development's number moving. Mutants, each killed by test_0785: - the limiter's old bound order: MATRIX error 3.0 in serial and at np 2; - deform's old reshape: ValueError; - refinement's old reshape: ValueError at np 2; - deform values reduced by their units: T raw 0.0005 for 0.5. Underworld development team with AI support from Claude Code
…DOFs, units included (#909, #965, #977) What was wrong. - #909. The transfer loop asked for the new node coordinates and evaluated each variable only where old_var.data.size > 0. Both calls are collective, so a rank with no cells skipped them and the others hung or aborted. The evaluation was also the rank-local evaluate, while a rank's new nodes need not lie in its old cells. - #965. A rank with no cells answered _classify_points_in_domain with one array where its callers unpack two. It raised alone inside global_evaluate, on a submesh with empty ranks or wherever a migrated point reached an empty rank. - #977. The restore reshaped evaluated values by row (wrong for a MATRIX, raising on a symmetric tensor) and packed dimensional values as raw. pack_raw_data_to_petsc rejects a UnitAwareArray, so on development a units-carrying variable came back zeroed. The restore's collective pack also sat behind a rank-local reshape-and-catch. The fix. - Every rank runs the transfer for every variable with a local vector, through global_evaluate. - The restore lays out and reduces values with ddt._evaluated_in_storage_layout. - A raise on any rank after the collectives of the transfer or of the layout resets that variable on all ranks; it is agreed on the verdict communicator before the pack. A raise on one rank before those collectives still hangs the others, as the comment says. - The classifier returns its pair. Corrected comments: the metricCreateIsotropic TODO (#975) and the global_evaluate TODO (#976). Tests. tests/parallel/test_0783_remesh_empty_rank_transfer.py; adaptMetric and metricCreateIsotropic are stood in, since no PETSc here adapts in parallel. Each test asserts its premise. On development: - every variable type, no old DOFs on one rank: np 2 exit 59, np 3 exit 142; - no new cells: np 2 and 3 exit 142; - a failure in the transfer: np 2 exit 59, np 3 exit 142; - a failure in the restore: AttributeError (no layout helper); - an empty rank asking about points: ValueError, then exit 124 at np 2 and 3; - the #965 child mesh at np 4: ValueError "Calling nonzero on 0d arrays", exit 124. Here: np 2, 5 passed, 2 skipped; np 3, 6 passed, 1 skipped; np 4 and 8, 7 passed. The child-mesh test needs np 4, so CI's default np 2 does not reach it. test_0785 gains the remesh-with-units test (K, cm/yr, Pa SYM_TENSOR, Pa 2 x 3 MATRIX). On development, serial: T 1.5, V 2.25, S 1.125, M 2.25 out. Here: exact to 1e-9 at np 1 to 8. Underworld development team with AI support from Claude Code
…ery rank (#991) What was wrong. In parallel, _refine_prolongate and _refine_restrict read the coordinates as non-dimensional, so with units they give wrong values on every shape: at np 3 a scalar in K was out by 968. On development a symmetric tensor raised there instead, but only because of the reshape that 7bfdfaa replaced. After 7bfdfaa it too came out silently wrong (3.0). The fix. Both transfers raise NotImplementedError, naming #991, when the parallel route would be taken and either variable carries units. The decision uses only the variables' units and the rank count, which are the same on every rank, so every rank raises together. The serial route is unchanged; with units it is exact. On 7bfdfaa's limiter change. Mesh.remesh does not use the limiter, but mesh.deform does. With global_evaluate fixed and the old bound order, deform puts a square MATRIX out by 3.0 even in serial, where development was right. The bound-order change is therefore what keeps deform no worse than development. Callers. copy_into and add_into on an adapt() child are the only callers of these transfers in the library. No test refines a variable with units in parallel; the parallel tests that adapt (0078, 0873, 1086, 1097, 1134) pass at np 2 and 3. Tests. test_0785 gains two tests: - the refusal (np >= 2). Before this commit, at np 2 both transfers returned on every rank: [['returned', 'returned'], ['returned', 'returned']]. Now every rank refuses both, and neither variable is written; - the serial route with units, exact both ways. test_0785: 5 passed, 1 skipped at np 1, 2, 3, 4, 8. p04_refine.py, at np 1: unchanged, exact on every shape with and without units. At np 3: without units unchanged (<= 9e-16); with units every shape raises the refusal on every rank. test_1079, 1080, 1107: unchanged at np 2, 3, 4, 8. Underworld development team with AI support from Claude Code
…scales; tensor history is tested (#991) What was wrong. - ae8cdb2 refused the parallel refinement route only when a variable carried units. The fault is the model's scaling: with reference quantities set, the coordinates are dimensional whatever the variables carry. With no units on either variable, a scalar came out by 2.5 and a 2 x 3 MATRIX by 15 at np 3, silently. - No test covered units on one side only, so a check of the first variable alone passed every test (restriction then out by 3874). - No test covered ddt._write_evaluated writing more than one column. A mutant writing only column 0 passed every test, while a tensor history then held [1, 0, 0, 0] for [1, 2, 3, 4]. The fix. The refusal also fires whenever non-dimensional scaling is active, which is the same on every rank. The check on either variable's units stays, for a model whose scaling is switched off: there a child in K is out by 1936 on restriction. .coords_nd is left to the #991 fix. Correction to 7bfdfaa's message and test_0784's docstrings. They call the TENSOR cases controls that "were never transposed". That is false: global_evaluate passes every result through a MATRIX container, so on development every non-symmetric 2-D result came back transposed, TENSOR variables included. Development fails the global_evaluate TENSOR case; its two passes in test_0784 are the RBF TENSOR and symmetric-tensor cases. Tests. test_0785's refusal test now covers, under reference scales: both variables in K, no units on a scalar, no units on a 2 x 3 MATRIX. With the scaling switched off it covers a parent in K with a child without units, and the reverse. - Before this commit, at np 3: the two no-units cases returned on every rank and wrote wrong values (1.59 and 9.56 out). - Here: 5 passed at np 2 and 3. - The first-variable-only mutant fails the child-in-K case at np 2 and 3: restriction out by 1936. test_0784 gains a zero-velocity semi-Lagrangian step on a TENSOR and a SYM_TENSOR, checking every stored column of the history. - On development: the TENSOR fails, with 01 and 10 swapped (errors 1.0 at 01 and 10); SYM passes. - Under the column-0-only mutant: both fail. - Here: 2 passed at np 1 and 2. test_0785's reference_scales fixture now also restores the scaling flag. Setting reference quantities switches scaling on, and neither reset_default_model nor conftest's isolate_test_state switches it off. So the refinement test that followed saw a scaled model and was refused. Reruns: test_0783, 0784, 0785 at np 1 to 4 pass. p04_refine at np 3: refs refuses every shape on every rank; norefs <= 9e-16. Underworld development team with AI support from Claude Code
…ies (#991) What was wrong. 05ffb10 refused when uw.is_nondimensional_scaling_active(), but that flag is not the same as "the model has reference quantities", and it is wrong in both directions: - set_reference_quantities(..., nondimensional_scaling=False) leaves the flag off, but the coordinates are still dimensional. Nothing refused, and at np 3 a scalar without units came out by 2.5 and a 2 x 3 MATRIX by 15. - After set_reference_quantities and then reset_default_model, the coordinates are non-dimensional again but the flag stays on. The route is exact there, and it was refused. The fix. _refuse_parallel_refinement_with_units refuses at np > 1 when uw.get_default_model().has_units(), or when either variable carries units. Both are the same on every rank. The docstring, the message ("the model has reference quantities") and the test docstrings now name that predicate. Tests. test_0785 gains two tests: - reference quantities with nondimensional_scaling=False and no units, which must refuse. At 05ffb10, np 3: both transfers returned on every rank, with values out by 1.59 and 1.25. - set then reset, which must transfer exactly. At 05ffb10, np 3: NotImplementedError. Here: test_0785 has 5 passed, 7 skipped at np 1, and 11 passed, 1 skipped at np 2 and 3. p49 at np 3: - noscale_nounits, noscale_units and len1_nounits refuse on every rank; - reset_after_refs transfers to 4.4e-16 (S) and 3.6e-15 (N). The one-sided-units cases are now refused by the model's reference quantities as well, so they no longer single out the variable-units check. Underworld development team with AI support from Claude Code
…transfer-909 # Conflicts: # tests/parallel/empty_rank_fixtures.py
Adversarial review record (narrowed branch)Reviewed at ae8cdb2, re-checked at 05ffb10. The one re-check condition, the refusal keying on the model's reference quantities rather than the scaling flag, is fixed at 77884aa with two tests that failed at 05ffb10. Then development (with #983 and #958) was merged in at 23d372b. The fixture conflict was resolved to this branch's version, and test_0782 to 0785 pass at np 2, 3, 4 and 8. The earlier three-round record is on #909. Reviewed 2026-11-08. Three commits: 7bfdfaa, 6384f77, ae8cdb2. The worktree is clean, and the installed package matches VerdictReady, with two conditions. Every round-3 finding is gone, or behaves exactly as on development. Nothing we measured is worse than development. Refinement with units now refuses at np ≥ 2, where it used to give a silently wrong value. The branch also fixes more than it claims. On development, What is left:
FindingsMediumM1. The #991 refusal keys on the variables' units, but the fault is the model's units. Probe
Under reference scaling
M2.
LowL1. The branch fixes more than it says, and its docstrings say the opposite. The
Consequences on D, all fixed on B:
The text that is wrong:
All three are false. D fails that TENSOR case: 8 failed / 2 passed ( L2. No test covers one-sided units for the refusal.
L3. A failure in Round-3 findings, rerun on both builds
Attacks that failed
Tests: can they fail?The new files on B:
On D, using the branch's tests:
Mutants (the three new files at np 1, 2 and 3):
What CI's np 2 does not reach:
The classifier mutant n06 still hangs at np 2, so the empty-rank classification is caught at np 2 anyway. Issue verdicts
Merge conditions
Could not test / did not run
Re-check at 05ffb10Re-checked 2026-11-08: the conditions only. The install matches VerdictReady once M1' is fixed (a one-line change). L1, L2 and M2 are closed, and every new test can fail. The new refusal is keyed on FindingsM1' (Medium). The scaling flag is the wrong predicate.
So the flag gets two cases wrong at np 3 (
The questions asked
CI-shaped reruns
Issue verdictsUnchanged, with one note on #991: it stays still live. The case with reference quantities and Merge conditions
Underworld development team with AI support from Claude Code |
Adversarial review of #1002 at 23d372bWe judged the code first and read the author's record (the first PR comment) after. This record adds only what that record misses or gets wrong. Builds:
Must fix1. Medium. The container write now indexes
The fix: make the failure rank-uniform.
A serial test of Should fix1. Medium.
Probes This is a tier B test, so it gates merges. It pins the cancellation of two filed defects, and its docstring says "a deform of a units box to 0.99 X". Either:
2. Medium.
On B, probe The fix is at the root: take the reshape shortcut only when the layout is row-major. That excludes a MATRIX with both dimensions above one. The container write can then go back to 3. Low. The fix is The author's record showed the same at round 3, by overlay. With this fix, #991 closes, and the refusal, its two tests and the question of which predicate it keys on all go away. If the refusal stays, its message names #991 but not what to do. It should name the route that works: serial. 4. Low. Charter §5, layering and DRY.
5. Low. Issue state: #996 is closed by this branch and not named. The semi-Lagrangian tensor test fills #996's gap ( Notes1. Objective rates and non-symmetric tensors (asked by the hub). No path takes L or W through
2. Convention probe (
3. Viscoelastic runs are bit-identical ( No VE or zg95 campaign default reaches a changed path:
The refusal therefore fires only for a user 4. Mutants we planted in serial. They were Python-level, planted by a pytest plugin, and we ran the three new files under each. All were killed:
The branch's tests on D: 11 failed (9 in 0784, 2 in 0785). The remesh units probe (
5. The author's record has two errors.
6. The 7. 8. Merge commit 23d372b keeps git's 9. 10. The Issue verdicts
Not checked
Underworld development team with AI support from Claude Code |
…yout helper moves next to _data_layout What was wrong. - The RBF route recovers a derivative into one scalar work variable, so a matrix-valued derivative came back (N, 1, 1). This is pre-existing (#999). Since 7bfdfaa, global_evaluate indexes that result per component inside its rank-local `if local_coords.shape[0] > 0`. With rbf=True or mode="fast", ranks holding points raised IndexError, while a rank holding none went on into the swarm's migration. On development the first entry was broadcast into every component: grad of 3x read [3, 3]. - _evaluated_in_storage_layout, which lays out a variable's storage, lived in systems/ddt.py, and the discretisation layer imported it upward (Charter section 5). - test_0785's units deform test described a deform it does not do. The fix. - evaluate_nd refuses a non-1x1 expression with derivatives under rbf=True (and so mode="fast"), with NotImplementedError, as it already refuses evalf=True. The decision rests on the expression and the flags, the same on every rank. A scalar derivative still takes the RBF route. - _evaluated_in_storage_layout and _storage_components move to discretisation_mesh_variables.py, beside _data_layout. _to_nondim_ndarray moves to utilities/unit_aware_array.py, beside UnitAwareArray. ddt imports all three from there, so its other importers (swarm, constitutive_models) are unchanged. There is no change in behaviour. - test_0785's units deform docstring now says what the test pins: development's number, reached only because #979 and #989 cancel. It fails with REMESH_MONOTONE=off. Tests. - New in test_0785, np >= 2, with an empty rank: a gradient through global_evaluate(mode="fast") with points on rank 0 only. Before: IndexError on the ranks with points, then exit 142 at np 2 and exit 134 at np 3. On development: exit 124 at np 2 (the #965 classifier), and at np 3 it returned without error. Here: every rank refuses. - New in test_0784, serial: evaluate(rbf=True) and global_evaluate(mode="fast") of a gradient both refuse; a scalar derivative is exact (3.0). Before: no error. On development: evaluate returned (2, 1, 1) and global_evaluate returned [3, 3] for [3, 0]. Results: test_0783 7 skipped / 5+2 / 6+1 / 7 passed at np 1 / 2 / 3 / 4; test_0784 13 passed at np 1 to 4; test_0785 5+8 skipped at np 1, 12+1 at np 2, 3, 4. test_0782 at np 2: 4 passed. DDt and adapt tests, serial (0066, 1052, 1053, 1054, 1056, 0070, 1057, 0835): 72 passed. Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
Response to the cross-review, at 6b435eeMust fix: done.
Should fix:
Corrections to our record: Runs at 5980f27:
parallel test_0782: 4 at np 2. At 6b435ee, which changes only the issue number in the message, after a rebuild: test_0784 13 passed; test_0785 12 passed, 1 skipped at np 2 and 3. Coverage OK on 398 files. Underworld development team with AI support from Claude Code |
|
Must fix 1, checked at 6b435ee by reading the code only (we ran nothing).
Resolved. The np 2 abort before the fix (exit 142) and the np 2 and serial tests after it are the author's runs. Underworld development team with AI support from Claude Code |
…-from-mesh-906 Underworld development team with AI support from Claude Code
…#991) underworldcode#1003 moved both parallel sites to coords_nd and the storage layout, so the refusal underworldcode#1002 added is no longer needed: the transfers are exact for every shape at np 2 and 3. test_0785's refusal tests now assert exactness, over scalar, vector, 2x3 MATRIX, TENSOR and SYM_TENSOR. Underworld development team with AI support from Claude Code
Mesh.remeshnow transfers every variable past a rank holding none of its DOFs, units and symmetric tensors included, andglobal_evaluatereturns every non-symmetric 2-D result in its components rather than transposed. A parallel refinement transfer in a model with reference quantities now refuses, where it used to give silently wrong values.What was wrong
Mesh.remeshhung, or aborted with exit 59 or 142, when a rank held no old DOFs, no new cells, or raised during the transfer or the restore. Rank-local decisions were made ahead of collectives.global_evaluateon a submesh with an empty rank raised "Calling nonzero on 0d arrays" on that rank, then hung (exit 124 at np 4).Mesh.remeshzeroed a variable carrying units, and raised on a SYM_TENSOR.global_evaluatewrote every non-symmetric 2-D result transposed: TENSOR variables out by 2.9 at np 1 and 3.3 at np 3, velocity gradients by 0.77 and 0.93, MATRIX variables of every shape, any non-symmetric sympy matrix. At np 2 and up, interior points came back transposed and out-of-domain points did not, within one call.mesh.deform, semi-Lagrangian history and the clamp limiter inherited it.The fix
_any_rank_failed, and the submesh classifier returns its pair on every rank (global_evaluate on a submesh raises on empty ranks and its peers hang (np 4) #965).global_evaluatewrites its data container by_data_layout, andrbf_evaluatereads the stored column._evaluated_in_storage_layoutis split out ofddt._write_evaluatedintodiscretisation_mesh_variables.py, beside_data_layout, and reduces units;Mesh.remeshuses it (Mesh.remesh silently zeroes units-carrying and symmetric-tensor variables #977).deformwould have put a square MATRIX out by 3.0 even in serial, because development's two transpositions cancelled there. Its units behaviour is development's (global_evaluate with monotone clamp returns wrong values in a units model, and mesh.deform uses it #989)._refine_prolongateand_refine_restrictlay out every shape, and at np 2 and up they raiseNotImplementedErrornaming Refinement transfers in a units model are wrong at np 2 and up: target coordinates lose their units #991 when the model has reference quantities or either variable carries units. They raise on every rank together, since the decision rests on rank-uniform facts. They used to return silently wrong values (scalar out by 968 at np 3). The serial route is unchanged.What changes for users
global_evaluateresult, as above.evaluate(..., rbf=True)returns MATRIX variables in their components.mesh.deformkeeps TENSOR and non-square MATRIX variables in their components. On development TENSOR was out by 1.5 at np 1 and 1.59 at np 3, a 2×3 MATRIX by 2.5, and a 3×2 by 1.0.deformno longer raises on SYM_TENSOR.global_evaluate(..., monotone="clamp")clamps MATRIX and TENSOR against the right bounds (development: MATRIX 5.2 and TENSOR 1.55 off the plain value), and limits a SYM_TENSOR (development raised).copy_intoandadd_intoon anadapt()child refuse in a model with reference quantities. In such a model with a length scale of 1 m and no units, the old route may have been right; it is refused too. No library path calls these at np > 1; only user code between anadaptparent and child does.evaluate(..., rbf=True)andglobal_evaluate(..., mode="fast")refuse a matrix-valued expression with derivatives, on every rank, naming The RBF route returns a matrix-valued derivative as (N,1,1), broadcast through global_evaluate #1004. They used to return one broadcast value,(N,1,1). A scalar derivative still takes the RBF route.write_timestepfile layouts andSwarmVariable.arrayare unchanged;SwarmVariable.arraystill reads a MATRIX back transposed (A MATRIX swarm variable reads back transposed #1005).Not fixed here
Deform, refinement and semi-Lagrangian paths with units are as on development, and are filed as one bundle: #979, #989, #990, #991, #992, #993. Also left: #976, interior nodes extrapolated on strip partitions; #959, deform with an empty rank or a rank whose nodes don't move; #984's
read_timestepon tensors; #994, #995; #999, #1000, #1001, #1004, #1005, #1006 (the layout loop written out seven times).This is the narrowed form of a branch that had three review rounds (record on #909). The
meshVariable_lookup_by_symbolchange and theSwarmVariable.arrayshape checks from those rounds are dropped. They caused a transposed semi-Lagrangian slot and a new hang.Tests
tests/parallel/test_0783_remesh_empty_rank_transfer.py, with adapter stand-ins, since this PETSc has no parallel adapter: on development, exit 59 at np 2 and 142 at np 3 in every case, and the global_evaluate on a submesh raises on empty ranks and its peers hang (np 4) #965 child exit 124 at np 4. Here 5 passed, 2 skipped at np 2; 6 passed, 1 skipped at np 3; 7 at np 4 and 8. The global_evaluate on a submesh raises on empty ranks and its peers hang (np 4) #965 case needs np 4, which CI's np 2 does not reach.tests/test_0784_global_evaluate_component_slots.py, serial, including a zero-velocity semi-Lagrangian step on TENSOR and SYM_TENSOR: 9 failed, 3 passed on development; 12 passed here, at np 1 to 4.tests/parallel/test_0785_evaluated_values_reach_storage_parallel.py: remesh with units, deform of every tensor shape, the refinement layout, and the refusal, including a model with reference quantities and the scaling flag off, and a reset model that must transfer. 11 passed, 1 skipped at np 2, 3, 4, 8. Mutants: 19 planted, 17 killed by the first review; the two survivors are killed by tests added since.test_0782(A degree-2 mesh builds with a rank holding no cells, and its cells have true sizes #983's) still passes at np 2, 3, 4, 8 on the merged branch;check_test_coverage.pyOK on 398 files.test_0774,0779,0781,0855,1079,1080and1107at np 2 to 8 (6384f77); the adapt userstest_0078,0873,1086,1097and1134at np 2 and 3 (ae8cdb2); a serial regression sweep, 256 passed (ae8cdb2). All passed.Closes #909
Closes #965
Closes #977
Closes #996
Refs #991, #984, #976, #959
Underworld development team with AI support from Claude Code