Skip to content

Mesh.remesh transfers past an empty rank, units included; global_evaluate no longer transposes - #1002

Merged
lmoresi merged 8 commits into
developmentfrom
bugfix/remesh-transfer-909
Nov 8, 2026
Merged

lmoresi merged 8 commits into
developmentfrom
bugfix/remesh-transfer-909

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Mesh.remesh now transfers every variable past a rank holding none of its DOFs, units and symmetric tensors included, and global_evaluate returns 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

The fix

What changes for users

  • Every non-symmetric 2-D global_evaluate result, as above.
  • evaluate(..., rbf=True) returns MATRIX variables in their components.
  • mesh.deform keeps 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. deform no longer raises on SYM_TENSOR.
  • Semi-Lagrangian history of a non-symmetric TENSOR holds the field, not its transpose, at every step. This changes the values of existing runs that use one.
  • 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).
  • Parallel copy_into and add_into on an adapt() 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 an adapt parent and child does.
  • evaluate(..., rbf=True) and global_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_timestep file layouts and SwarmVariable.array are unchanged; SwarmVariable.array still 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_timestep on 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_symbol change and the SwarmVariable.array shape 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.py OK on 398 files.
  • Run at earlier commits of this branch, not repeated on the tip: neighbours test_0774, 0779, 0781, 0855, 1079, 1080 and 1107 at np 2 to 8 (6384f77); the adapt users test_0078, 0873, 1086, 1097 and 1134 at 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

…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
Copilot AI balanced review requested due to automatic review settings November 7, 2026 23:16

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.

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

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 src/. "B" (branch) is wt-909n. "D" (development) is wt-900: 37aa2a1 plus the #905 projection fix. In src/ it differs from f31edcb only in function/field_projection.py, and its installed copies of the five touched .py files are byte-identical to its source. Probes are in review909n/probes/, logs in review909n/logs/<name>.log, and mutants (cp -a overlays) in review909n/ov/, built by review909n/mkmut.py. Every number comes from a run unless it is marked (reading).

Verdict

Ready, 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, global_evaluate transposed every non-symmetric 2-D result, TENSOR variables included, not only MATRIX variables. So development's mesh.deform transposed a TENSOR, and semi-Lagrangian history transposed a TENSOR at every step. Both are right here.

What is left:

Findings

Medium

M1. The #991 refusal keys on the variables' units, but the fault is the model's units. Probe p44_refine_modes.py refs_nounits, np 3, reference quantities set, no units on either variable:

  • prolong and restrict error: S 2.5, MATRIX 2×3 15 (values up to 24);
  • identical on B and D, no error raised;
  • at np 1 the route is serial and exact.

Under reference scaling cv.coords and pv.coords are dimensional whatever the variable carries, and that is #991's title ("in a units model"). The refusal at discretisation_mesh.py:2613 (any(getattr(v, "units", None) …)) lets this case through.

M2. _write_evaluated writing more than one column is still not under test (round 3 M3, still open).

  • Mutant n13 writes only stored column 0. It survived all three new files at np 1, 2 and 3: 15/14, 20/3, 21/2 passed/skipped.
  • It is live: SL history of a TENSOR and of a SYM_TENSOR comes out [1, 0, 0, 0] against [1, 2, 3, 4] (p43_n13_1).
  • The commit splits _evaluated_in_storage_layout out of _write_evaluated but adds no test of _write_evaluated itself.
  • The fix is a short serial test: SemiLagrangian on a non-symmetric TENSOR with zero velocity, then one update_pre_solve, as in p43_sl_tensor.py. It would also lock in the new transposition fix (L1).

Low

L1. The branch fixes more than it says, and its docstrings say the opposite. The global_evaluate container is a MATRIX swarm variable for every expression. So on D a TENSOR variable, a velocity gradient, or any non-symmetric 2×2 sympy matrix came back transposed (p40_ge_shapes.py):

case D np 1 / np 3 B np 1 / np 3
TENSOR G 2.92 / 3.33 1.8e-15 / 1.8e-15
∇V (2×2) 0.77 / 0.93 1.0e-5 / 1.5e-5 (projection)
mixed 2×2 expression 2.89 / 2.93 8.9e-16 / 1.8e-15
G with units stored [1,2,3,4] for [1,3,2,4] right (p47)

Consequences on D, all fixed on B:

  • mesh.deform of a TENSOR, without units: G error 1.5 (np 1) and 1.59 (np 3). Also MATRIX 2×3 2.5, MATRIX 3×2 1.0, MATRIX 2×3 degree 2 1.25. B: 0 in serial; at np 3 the error matches the limiter-off seam error (G 0.066) (p11b_nosym).
  • SemiLagrangian history of a non-symmetric TENSOR: psi_star[0] holds the transpose at every step, at np 1 and np 2 (p43). B is exact.
  • global_evaluate(..., monotone='clamp') on a whole variable: |clamp − plain| on a linear field is M 5.2 and G 1.55 on D, and SYM raises; all 0 on B (p48).
  • Out-of-domain points at np 3 came back un-transposed through the fallback, while interior points came back transposed. On D a single call mixed the two layouts; on B they agree.

The text that is wrong:

  • test_0784's module docstring: "A TENSOR and a symmetric tensor store by row, so neither was affected".
  • The test_global_evaluate_returns_a_variable_in_its_components docstring: "The TENSOR is the control … it was never transposed".
  • 7bfdfaa's "the passes are the TENSOR controls".

All three are false. D fails that TENSOR case: 8 failed / 2 passed (t0784_dev). The 2 passes are the RBF TENSOR and SYM cases. The PR should state the behaviour change as "any non-symmetric 2-D result of global_evaluate", and note that a non-symmetric TENSOR SL history changes value.

L2. No test covers one-sided units for the refusal.

  • Mutant n02 checks only the first variable, and survived at np 2 and 3.
  • Under it, a units-free parent with a child in K gives prolong error 2.5 and restrict error 3874 at np 3, silently (p44_refs_child_only_n02_3). The branch refuses on every rank.
  • Fix: add a parent-without-units or child-without-units case to test_the_parallel_refinement_transfers_refuse_a_variable_with_units.

L3. A failure in _reinit_variable_on_new_dm on one rank still skips the collective verdict (reading). The outer try in the restore loop (discretisation_mesh.py:~9839) catches a raise from _reinit_variable_on_new_dm per rank. That rank then skips _any_rank_failed and pack_raw_data_to_petsc, which are collective. This is the same class as the "raise before the collectives" case the comment already admits. It was structurally the same on D, and it is not reachable by any input we could construct. A comment would do.

Round-3 findings, rerun on both builds

R3 probe B D status
H1 deform with units p28 np 1 T raw 0.5 0.5 as D
p02b dim np 1 / 3 T 0.875 / 0.5625, M 0.5 / 0.25 identical as D
p02b raw np 1 / 3 T 0.125, V 0.375 / 0.398, M 0.25 / 0.266 identical as D
p15_limit_units clamp 1.5 K, 1.25 Pa identical as D (limiter TODO(units))
H2 refine with units p04 refs np 3 NotImplementedError (#991) on all 3 ranks, every shape S 968, V 3, M 4, N 6, G 4, Y raises refused (better than D)
p04 refs np 1 ≤ 4.4e-16 identical as D
p04 norefs np 3 ≤ 8.9e-16, every shape N 3.0, G 1.0, Y raises fixed
H3 SL record of a MATRIX component p14 np 2, 3 2.0 2.0 as D (regression gone)
p01_lookup record as D; rbf_eval right rbf_eval transposes MATRIX as D, RBF fixed
M1 scalar given (N,2) p05 scalar_2col every rank raises, exit 1 identical as D (hang gone)
M2 empty-rank 1-D hole p05 hole_1d accepted on every rank identical as D (hang gone)
p05 wrong_N exit 124 exit 124 as D (pre-existing)
p05 vector_3col empty rank accepts, others raise identical as D
M3 multi-column _write_evaluated n13 mutant survives — open (M2 above)
L1 test_0785 docstring read corrected (#976 at np 2 and 3, limiter at np 8) — fixed
L2 write_timestep layout p07 np 1, 3 m [0,1,2,10,11,12], q [0,1,10,11] identical as D (layout change gone)
P2 SL record with units p27 np 1 / 2 0.5 / 500 identical as D (pre-existing)
#984 read_timestep p07 read m, q, t, y raise "(96,k) into (96,j)" identical as D

Attacks that failed

  • Other callers of global_evaluate and evaluate. These are unaffected because their expressions are scalar or 1×n:

    • the velocity in swarm.py:5871-5908 and ddt.py:2686;
    • the metric sampler at discretisation_mesh.py:8811;
    • _write_components, which evaluates per scalar component (ddt.py:5454);
    • visualisation/parallel.py and glyphs.py, which use local evaluate and symmetrise (reading);
    • model.transfer_variable_data, which uses local evaluate.

    The remaining callers are SL _sample_history_at_departure, remap_var_set, the _refine_* transfers and Mesh.remesh. All of them now read the result in components and lay it out through _data_layout. No source file applies a .T or transpose to compensate (grep).

  • Shapes through the new container write (p40, np 1 and 3): scalar non-Matrix expressions, 1×2, 2×1, G·x (2×1), Y, M 2×3 and its transpose. All are ≤ 3.6e-15 inside the domain, and B is no worse than D outside it.

  • Units through the container (p47, np 1 and 2): T, V, S, x, T·x, κ·T. B equals D to the last digit, units included. Only the TENSOR differs, and B is the right one.

  • The refusal under partial reference scales (p45): temperature only, or length = 1 m.

    • D at np 3 is wrong by 4.0e3 (S) and 2.4e4 (N), because the dimensional values are stored as raw.
    • B refuses on every rank.
    • np 1 is exact on both.
    • Strict units mode forbids units without reference quantities (p44 norefs_units raises at variable creation on both). So no case was found where the refusal removes a value that was right on D.
  • The refusal is rank-uniform. In every refused run, all ranks printed the same outcome: p04, p44 and p45 at np 3. The mutant that refuses on rank 0 only (n03) hangs at np 2 and 3, so the test detects the asymmetry, though only by its hang.

  • A sub-communicator mesh. A Mesh on a COMM_SELF DM built on rank 0 alone at np 2 hangs at construction, on both builds (p46, exit 124). So verdict_comm against such a mesh cannot be reached.

  • The remesh verdicts.

    • The _lvec is None skip and the dict iteration order are the same on every rank (reading: _set_vec is collective at creation).
    • Making the transfer verdict rank-local (n04), dropping the pop (n17), or skipping the restore verdict (n19) each hang or abort at np 2 and 3.
  • _write_evaluated / _evaluated_in_storage_layout against D (reading). It is the same reduction and the same per-column writes, through a float64 staging array. A count mismatch still raises, and broadcasting is unchanged.

  • The limiter. The new bound order clamps M, G and Y exactly (p48). A scalar component of a multi-component variable under monotone raises "cannot reshape" on both builds, identically.

  • Regression sweep on B, serial: 256 passed, 9 skipped, 0 failed. It covered 0503, 0760_monotone, 0800, 0056, 0057, 0826, 0102, 0761, 0066, 1052-1054, 1056, 0855_oldframe, 1071, 1100, 1120, 0830, 0810, 1057, 0070, 1015, 1016×2, 0835, 0837, 0843, 0834, 0007 and 0008.

  • Regression sweep on B, parallel, np 2 and np 3: 1076, 0775, 0760_swarm_cache, 1062, 0873 and 0796. 14 passed at each np.

  • CI reach.

    • At np 2 (ci_b24_np2), the batch holding 0778, 0779, 0780, 0781, 0783 and 0785 gives 19 passed, 4 skipped.
    • python scripts/check_test_coverage.py: "OK: all 395 test files are reachable".
    • test_0785 is also in serial batch 3.

Tests: can they fail?

The new files on B:

np passed skipped
1 (with 0784) 15 8
2 10 3
3 11 2
4 12 1
8 12 1

On D, using the branch's tests:

Mutants (the three new files at np 1, 2 and 3):

Outcome Mutants
Killed in serial n08 restore reshape, n09 remap reshape, n12 limiter old order, n14 no unit reduction, n15 flat enumerate, n16 development's _function.so (10 failures), n18 remap reduces units
Killed only at np ≥ 2, by an assertion n01 no refusal, n07 remesh uses local evaluate, n10 prolong reshape, n11 restrict reshape
Killed only at np ≥ 2, by a hang or abort (124/142; CI catches these only through the supervisor's silence limit) n03 rank-0 refusal, n04 rank-local verdict, n05 old guard, n06 old classifier, n17 no pop, n19 restore verdict skipped
Survived n02 refusal on the first variable only (L2), n13 _write_evaluated column 0 only (M2)

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

  • M1:
  • M2: add the TENSOR SL test (zero velocity, non-symmetric, one update_pre_solve). It must kill n13 and fail on D.
  • L1: correct the test_0784 docstrings and the 7bfdfaa text: a TENSOR was transposed by global_evaluate on D. State in the PR that deform and SL history of a non-symmetric TENSOR change value.
  • L2: add a one-sided-units case to the refusal test (it must kill n02).
  • To file as pre-existing (both builds, rank-uniform):
    • global_evaluate of a derivative expression with an out-of-domain point at np ≥ 2 raises "cannot reshape array of size 2 into shape (2,2,2)" (p40 gradV out, np 3);
    • monotone='clamp' on a component of a multi-component variable raises "cannot reshape" (p48). It is reachable from _write_components with monotone_mode set on a tensor history (reading).

Could not test / did not run

  • A real adaptMetric: no mmg in this PETSc.
  • The full suite. Parallel tests beyond those named. Anything above np 8.
  • test_1061 and test_1059: they did not finish in round 3 and were not retried.
  • From reading only:
    • L3;
    • that _lvec is the same on every rank;
    • that the visualisation callers and glyphs are unaffected;
    • that _write_components reaches the limiter.
  • No full advection-diffusion or VE-Stokes solve with a non-symmetric TENSOR history. Only the SL step itself (p43).
  • Hygiene: the worktree is clean at ae8cdb2, and nothing was pushed or posted. No processes of ours remain. The p50.py mpirun jobs on the host are not ours and were left alone. The overlays take 946 MB under review909n/ov/.

Re-check at 05ffb10

Re-checked 2026-11-08: the conditions only. The install matches src/ (cmp of discretisation_mesh.py) and the worktree is clean. Fresh mutants were cp -a'd from the 05ffb10 install into review909n/ov2/. Probes p49_refine_scaling.py and p50_flag.py, logs logs/p49_*, logs/mut2_*, logs/rc_*.

Verdict

Ready 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 uw.is_nondimensional_scaling_active(). That flag is not "the model has reference quantities", and the two part in both directions, as measured below.

Findings

M1' (Medium). The scaling flag is the wrong predicate. model.has_units() is the right one. Measured, serial (p50_flag.py):

state scaling flag has_units() var.coords max
fresh False False 1.0
set_reference_quantities(...) True True 1e6
the same, then uw.reset_default_model() True False 1.0
set_reference_quantities(..., nondimensional_scaling=False) False True 1e6

So the flag gets two cases wrong at np 3 (p49):

  • False negative, silent and wrong. With nondimensional_scaling=False and no units on the variables, prolong and restrict are out by S 2.5 and N 15. The numbers are identical on development. The coordinates are dimensional whether or not the flag is on, and only the variables' units can refuse here, and they have none. This is the M1 case again, by another route.
  • False positive: it now refuses what was right.
    • After set_reference_quantities then reset_default_model, the coordinates are non-dimensional again. Development gives S 4.4e-16 in both directions (its MATRIX 2×3 is out by 12 from the old reshape, which the branch fixed). 05ffb10 raises NotImplementedError on every rank.
    • Same with length = 1 m and no variable units: development S 4.4e-16, 05ffb10 refuses.
    • The reset_default_model case is reachable in a session or script that resets the model.
  • The fix: scaled = uw.get_default_model().has_units(). It is model state set by the same SPMD calls, so it is as uniform as the flag. In every row above it gives the right answer, and it still refuses the units cases through with_units.
  • The test does not tell the two apart. The fixture's "unscaled" cases switch the flag off with reference quantities still set, which is exactly the false-negative state. They pass only because the variables there carry units.
  • Add: the case (None, None, scaled=False) with reference quantities set must refuse, and a reset-then-refine case must not.

The questions asked

  1. Is the flag uniform?

    • Yes, in every case we built: allgather of the flag gave [True]*3 or [False]*3 in all four p49 modes.
    • The library sets it only in Model.set_reference_quantities (model.py:2317) and in scoped contexts (nondimensional_scaling_context, _apply_scaling inside uw.unwrap(apply_scaling=True)), none of them rank-conditional (reading). Only user code inside if rank == 0: could split it.

    Does it refuse anything that was right? Yes, see M1' (reset, length = 1 m).

    Is serial still allowed? Yes: if uw.mpi.size == 1: return comes first, and the test_0785 serial-route test passes.

    Do library paths reach the transfers at np > 1?

    • The only callers are copy_into and add_into on a refinement child (enhanced_variables.py:653-655, grep). adapt() itself, remesh and the multigrid do not call them (grep).
    • So a scaled model refuses only when a user calls copy_into or add_into between an adapt parent and child at np ≥ 2.
    • In the tests, only test_0835 (serial) and test_0785 do this.
  2. L2: closed.

    • Mutant r02 (first variable only) is killed at np 2 and 3 by [child_in_K_unscaled].
    • Two further mutants are also killed at np 2 and 3: r20 (flag only) by both unscaled cases, and r21 (units only) by [no_units_scalar] and [no_units_matrix].
    • At np 1 all of these pass by design: the refusal is parallel-only.
  3. M2: closed.

    • Mutant r13 (column 0 only) fails test_semi_lagrangian_history_keeps_every_component_of_a_tensor[TENSOR] and [SYM_TENSOR] at np 1, 2 and 3.
    • On development, test_0784 gives 9 failed / 3 passed, and its new SL TENSOR case fails (rc_dev_0784). SYM passes there, as the commit says.
  4. L1: closed (reading).

    • test_0784's module docstring and both test docstrings now say that global_evaluate transposed every non-symmetric 2-D result, TENSOR included. The RBF route was right for TENSOR and SYM.
    • The 05ffb10 message corrects 7bfdfaa. Its one inaccuracy is M1': the docstring and the message say "in a model with reference scales", and the code tests the scaling flag.
  5. The leak claim: confirmed.

    • reset_default_model (model.py:5968) resets strict units only. isolate_test_state (tests/conftest.py:245) calls reset_default_model and touches the strict-units mode only (reading). After set_reference_quantities and reset_default_model the flag is still True (p50). This leak is the same on development.
    • What it means here: a later parallel refinement transfer in the same process is refused, which is the M1' false positive, and with has_units() that would not happen.
    • CI ordering. In tests/parallel/ only two files set reference quantities:
      • test_0750, with nondimensional_scaling=False, so the flag is never switched on. It resets after.
      • test_0785, whose fixture and refusal test now restore the flag.
    • test_0785 is the last file of its np 2 batch (24: 0778, 0779, 0780, 0781, 0783, 0785). The only other parallel copy_into user, test_0770 (batch 18), is a submesh, not a refinement child. So no CI parallel batch is affected.
    • Serial runs never take the refused route. In serial batch 3, 1090 → 0785 → 1088 together give 27 passed / 5 skipped / 1 xfailed.
    • Serial tests that set reference quantities and leak the flag to later tests do so on development too. This branch does not change that.

CI-shaped reruns

  • test_0783, 0784 and 0785 together at np 2 under the supervisor: 26 passed, 3 skipped.
  • CI batch 24 at np 2: 23 passed, 4 skipped.
  • python scripts/check_test_coverage.py: "OK: all 395 test files are reachable".

Issue verdicts

Unchanged, with one note on #991: it stays still live. The case with reference quantities and nondimensional_scaling=False is still silently wrong (S 2.5, N 15 at np 3), and the refusal now also fires after a model reset, where the transfer is right. With has_units(), the refusal would cover #991's case completely; the fix proper (.coords_nd) is still to come.

Merge conditions

  • Replace uw.is_nondimensional_scaling_active() with uw.get_default_model().has_units() in _refuse_parallel_refinement_with_units.
  • Add the two cases above to the refusal test: reference quantities set with the flag off and no units must refuse, and reference quantities set then reset must not.
  • Keep the fixture's flag restore. It is harmless and documents the leak, which should be filed separately: reset_default_model leaves the scaling flag on.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #1002 at 23d372b

We 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:

  • B is 23d372b, built in its own worktree. uw.__file__ points into that worktree's env, and the installed ddt.py, swarm.py, functions_unit_system.py, remesh.py and discretisation_mesh.py match src/ under cmp.
  • D is the rotated-vel-pc-963 env at 488c53b. It differs from development 7274187 only in unrelated hunks of discretisation_mesh.py (options cleanup, cell sizes, adapt repair) and in field_projection.py. _function.pyx is the same as development's. The installed copies of the files we probed are the same as their source.
  • Every run was serial, with OMP_NUM_THREADS=1. Probes and logs are in scratchpad/rev1002/.

Must fix

1. Medium. function/_function.pyx:626-634: a matrix-valued derivative through the RBF route now raises on only some ranks, which is a hang at np ≥ 2 (from reading the code).

The container write now indexes values[:, i, j] inside the rank-local if local_coords.shape[0] > 0:. The local RBF route returns (N, 1, 1) for any matrix-valued derivative. This is pre-existing: evaluate(L, rbf=True) has shape (2, 1, 1) on both builds. So with rbf=True or mode="fast", every rank that holds evaluation points raises IndexError. A rank that holds none goes on to evaluation_swarm.dm.migrate (line 644) and the barrier, and waits there. Development broadcast the first entry into every component. That was silently wrong, but it did not hang.

mode="fast" is the documented cheap route for derivative terms ("Clement gradient (no solve), RBF everywhere"). Probe probe_fast_grad.py, T = 3x and v = (y, 0):

D  global_evaluate  fast grad T (1x2)  shape (2, 1, 2) row0 [3. 3.]        right: [3, 0]
D  global_evaluate  fast L (2x2)       shape (2, 2, 2) row0 [0. 0. 0. 0.]  right: [0, 1, 0, 0]
B  global_evaluate  fast grad T (1x2)  RAISES IndexError: index 1 is out of bounds for axis 2 with size 1
B  global_evaluate  fast L (2x2)       RAISES IndexError: index 1 is out of bounds for axis 2 with size 1
D,B evaluate        fast L (2x2)       shape (2, 1, 1) row0 [0.]

The fix: make the failure rank-uniform.

  • Either refuse a derivative under rbf=True up front in evaluate_nd, as it already refuses evalf=True ("Derivative expressions cannot be evaluated with evalf=True"). That decision depends only on the expression and the flags, so it is the same on every rank.
  • Or check values.shape[1:] == expr_shape and reach a collective verdict before raising.

A serial test of global_evaluate(grad, pts, mode="fast") should expect a named error (or the right values). The local (N, 1, 1) result belongs with #999, which records only its np ≥ 2 out-of-domain form.

Should fix

1. Medium. tests/parallel/test_0785_evaluated_values_reach_storage_parallel.py:150-167: test_deform_with_units_keeps_a_constant_field does not do the deform it describes.

Probes probe_deform_units*.py:

fixture call:                 dm coords max after 990000000000.0  T raw range 0.5 0.5
REMESH_MONOTONE=off pytest:   AssertionError: (499.99999999999994, 980100500.0)
0.99 * ND coords, clamp on:   dm coords max after 990000.0  T raw 0.5 0.5
0.99 * ND coords, clamp off:  dm coords max after 990000.0  T raw 500.0 500.00098

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. swarm.py:1229: the cause of the transposition is still live for every MATRIX swarm variable.

  • SwarmVariable._pack_array_to_data_format reshapes by row whenever a·b equals num_components.
  • _data_layout stores a MATRIX by column, and _unpack_data_to_array_format reads by layout.
  • That mismatch is why global_evaluate transposed. The branch works around it in that one caller (_function.pyx:626-634).

On B, probe probe_swarm_matrix.py:

M22 MATRIX wrote [[1,2],[3,4]]        read [[1,3],[2,4]]
M23 MATRIX wrote [[1,2,3],[4,5,6]]    read [[1,3,5],[2,4,6]]
T22 TENSOR wrote [[1,2],[3,4]]        read [[1,2],[3,4]]

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 .array. If this is not fixed here, file it (we found no issue) and put a # TODO(BUG): on the shortcut.

3. Low. discretisation/discretisation_mesh.py:2608-2625: the #991 refusal stands where a two-line fix is proven.

The fix is cv.coords_nd (and pv.coords_nd) at both sites, with the global_evaluate result passed to _evaluated_in_storage_layout without numpy.asarray, so that its units are reduced. At expression level, in a model with reference quantities, it is exact with units on the variables and without. Probe probe_refine_fix.py, serial:

units=K:    route as is err 1.937e+03; coords_nd + reduce err 2.220e-16
units=None: route as is err 1.250e+00; coords_nd + reduce err 2.220e-16

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.

  • _evaluated_in_storage_layout lays out a variable's storage, but it lives in systems/ddt.py. It is imported by discretisation/discretisation_mesh.py:2637, 2668, 9857 and discretisation/remesh.py:482, so the discretisation layer now imports from systems.
  • The same (i, j) → _data_layout loop now exists six times:
    • ddt.py:283-286;
    • _function.pyx:629-633;
    • functions_unit_system.py:725-726;
    • swarm.py:1236-1237;
    • discretisation_mesh_variables.py:768-771;
    • _function.pyx:1300-1306.
  • The fix: one packer, on the variable. Fixing Should fix 2 at the root removes the copy in _function.pyx.

5. Low. Issue state: #996 is closed by this branch and not named.

The semi-Lagrangian tensor test fills #996's gap (tests/test_0784_global_evaluate_component_slots.py:77-102). A mutant whose _write_evaluated writes only column 0 fails it in both cases (TENSOR and SYM_TENSOR; plugin mutplugin.py, MUTANT=write_column0: 2 failed, 10 passed). Name #996 in the PR and label it fixed-in-PR.

Notes

1. Objective rates and non-symmetric tensors (asked by the hub).

No path takes L or W through global_evaluate, and nothing evaluates grad(v) at departure points. So development never used Lᵀ in a viscoelastic run. Every history a solver builds is a SYM_TENSOR (systems/solvers.py:682, :5655), and _storage_components reads only i ≤ j.

path what goes through global_evaluate symmetric effect of B
constitutive_models.py:2836 _objective_term: UCM Lσ+σLᵀ, Jaumann Wσ−σW nothing: L = u.sym.jacobian(X), W = Unknowns.W, symbolic in the residual n/a none
constitutive_models.py:2750 _carried_through_step (order q, "cayley") and :2809 frozen atoms nothing: K = W or L, symbolic atoms symmetrised none
constitutive_models.py:2713, :2851 convected_step="deformation" nothing, symbolic n/a none
thin_sheet.py:119, :212 _surface_spin (the sheet's W, used by Cayley) nothing, symbolic n/a none
ddt.py:3853 SemiLagrangian._sample_history_at_departure psi_star[i].sym: stress or log-conformation yes (SYM_TENSOR) bit-identical (probe below)
the same, on a TENSOR history (user-built only) psi_star[i].sym no D stored the transpose every step; B is right (test_0784: D {'01': 1.0, '10': 1.0})
ddt.py:2686 departure velocity V (1×dim) n/a none
ddt.py:5444 IntegrationPointSemiLagrangian._write_components one scalar entry at a time n/a none
constitutive_models.py:2889 max_elastic_timestep, carried-stress health local evaluate of scalars, history from .array n/a none

2. Convention probe (probe_layout.py). UW3's L is L_ij = ∂u_i/∂x_j (petsc_generic_snes_solvers.pyx:1970). That is the convention _objective_term assumes.

v = (-y, x)   evaluate L         D [[0,-1],[1,0]]   B [[0,-1],[1,0]]
              global_evaluate L  D [[0, 1],[-1,0]]  B [[0,-1],[1,0]]
v = (y, 0)    evaluate L         D [[0,1],[0,0]]    B [[0,1],[0,0]]
              global_evaluate L  D [[0,0],[1,0]]    B [[0,1],[0,0]]
TENSOR [[1,2],[3,4]], global_evaluate, inside and just outside:  D [[1,3],[2,4]]   B [[1,2],[3,4]]

evaluate and global_evaluate disagreed on D and agree on B. A constant matrix with no mesh variable skips the swarm and was right on both builds.

3. Viscoelastic runs are bit-identical (probe_ve.py). The probe ran a box Stokes solve with a semi-Lagrangian history, 3 steps of dt 0.05, rotated free slip, for four variants: Jaumann ETD, Jaumann with Cayley, UCM BDF, and UCM with log-conformation. The md5 of psi_star[0].data and of v.data match between D and B in all four (for example, Jaumann ETD 5650326b…, UCM log d2903bee…).

No VE or zg95 campaign default reaches a changed path:

  • the zg95 drivers call global_evaluate on scalars and vectors only, and set no reference quantities;
  • the notch drivers set reference quantities, but transfer only v, p and scalars;
  • the VE cylinder history is a SYM_TENSOR;
  • no campaign calls copy_into or add_into, the only callers of _refine_* (enhanced_variables.py:653-655).

The refusal therefore fires only for a user copy_into or add_into between an adapt parent and child at np ≥ 2. It is raised on every rank or on none, before any collective in _refine_*.

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:

mutant result
flat reshape 3 failed: SL SYM_TENSOR, remesh with units, deform shapes
no unit reduction remesh with units fails, T_u 1498.5
old limiter order deform fails, M_d 3.0
column 0 only 2 failed

The branch's tests on D: 11 failed (9 in 0784, 2 in 0785).

The remesh units probe (probe_remesh_units.py), T, SYM_TENSOR and TENSOR:

  • D zeroes T (maximum 0.0) and S;
  • B gives errors ≤ 1.8e-15 with the scaling flag on, with it switched off after set_reference_quantities, and with nondimensional_scaling=False;
  • strict units refuses units with no reference quantities at variable creation.

5. The author's record has two errors.

  • It says visualisation/parallel.py uses local evaluate. It calls global_evaluate (:28, :60-61, :99, :149) on whatever field the user passes, so a tensor field now arrives in its components. No library caller passes one.

  • Its CI-shaped rerun ("batch 24: 0778 … 0785") predates the merge of 0782. At the tip the MPI phase has 13 batches, and 8 of them differ from development's:

    CI was pending at the time of review.

6. The rbf_evaluate comment is false (_function.pyx:1823-1825). It says "A scalar's records none". Every UnderworldFunction is built with a data_loc, a scalar's being 0 (discretisation_mesh_variables.py:380-387). So the is not None guard covers a state that cannot occur (Charter §5).

7. remesh.py:522-524 cites "review of #909, round 3, H1 and P1". It should cite #979 and #989 (Charter §4).

8. Merge commit 23d372b keeps git's # Conflicts: lines and has no attribution line.

9. _any_rank_failed is a generic collective verdict written as a Mesh static method, and fault_contact.py:75 does the same inline. One helper in uw.mpi would serve both.

10. The global_evaluate change is user-visible: a script that read a gradient through it gets a different matrix. A docs/developer/CHANGELOG.md entry would record it.

Issue verdicts

Not checked

  • No MPI of any kind. Hyperion should run:
    • Must fix 1: at np 2, global_evaluate(v.sym.jacobian(mesh.X), pts, mode="fast") with a few points given on rank 0 only, under mpi_supervisor.py --silence 120. Expect exit 124 on B and values on D.
    • CI batch 5 at np 2 (0783, 0785, 0790, 0795, 0796, 0855), and batches 6 and 7 (0873 to 1063, and 1064 to 1071), for the boundary shift.
    • probe_ve.py at np 2 and 3 on B and on D: the history md5 should match.
    • The coords_nd form of _refine_prolongate and _refine_restrict at np 2 and 3, by overlay, with units on the variables and without.
    • test_0783 at np 4 (the global_evaluate on a submesh raises on empty ranks and its peers hang (np 4) #965 child mesh).
  • A real adaptMetric: this PETSc has no mmg.
  • The full suite. We ran only the three new files, the mutants and the probes.

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
@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Response to the cross-review, at 6b435ee

Must fix: done.

  • evaluate_nd now refuses a non-1×1 expression with derivatives under rbf=True, and so under mode="fast", raising NotImplementedError on every rank, beside the existing evalf=True refusal. It names The RBF route returns a matrix-valued derivative as (N,1,1), broadcast through global_evaluate #1004, filed for the pre-existing (N,1,1) shape.
  • Reproduced first at the previous head, with an empty rank and points on rank 0 only: ranks with points raised IndexError: index 1 is out of bounds for axis 2 with size 1, exit 142 at np 2 and 134 at np 3. On development the same run hangs at np 2 (exit 124, in the global_evaluate on a submesh raises on empty ranks and its peers hang (np 4) #965 classifier) and returns wrong values at np 3. Serially, development gives [3, 3] where [3, 0] is right.
  • New tests: test_0785 at np ≥ 2, where every rank reports "refused", with the empty-rank premise asserted; test_0784 serially, which failed "DID NOT RAISE" before the fix. A scalar derivative stays exact through the RBF route.

Should fix:

  1. The units deform test's docstring now says what it pins: development's number through the global_evaluate with monotone clamp returns wrong values in a units model, and mesh.deform uses it #989 clamp, with coordinates at 9.9e11 (mesh.deform in a units model leaves the mesh scaled to metres: the remesh transaction reads dimensional coordinates #979), failing under REMESH_MONOTONE=off. It is not a correct deform, and fixing either issue is expected to change the number.
  2. The swarm MATRIX packer is filed as A MATRIX swarm variable reads back transposed #1005: [[1,2],[3,4]] reads back [[1,3],[2,4]] on development and on this branch; TENSOR round-trips. Not changed here, since swarm changes were the source of round 3's regressions.
  3. Refinement transfers in a units model are wrong at np 2 and up: target coordinates lose their units #991 stays a refusal. The .coords_nd change is small, but every units change in this branch's history opened a new fault in review. The hub is bundling Refinement transfers in a units model are wrong at np 2 and up: target coordinates lose their units #991 with mesh.deform in a units model leaves the mesh scaled to metres: the remesh transaction reads dimensional coordinates #979, global_evaluate with monotone clamp returns wrong values in a units model, and mesh.deform uses it #989 and Semi-Lagrangian clamp is off by the units scale: psi_star 0.0005 for 0.5 #990 to Writing a unit-aware array to SwarmVariable.array stores its magnitude as non-dimensional #993 for one owner, and deform shares the coordinate fault.
  4. The layout helper moved beside _data_layout in discretisation_mesh_variables.py, and _to_nondim_ndarray beside UnitAwareArray. ddt re-imports both, so swarm.py and constitutive_models.py are unaffected. Serial DDt and adapt tests: 72 passed. The six other copies of the loop are listed in The storage-layout loop is written out in seven places; one helper would stop them disagreeing #1006.
  5. Closes #996 is added, and Test gap: no test checks that ddt._write_evaluated writes every column #996 is labelled.

Corrections to our record: visualisation/parallel.py does call global_evaluate. And after #983's merge the MPI batch boundaries moved, so test_1063 and test_1064 now sit in batches 6 and 7.

Runs at 5980f27:

test np 1 np 2 np 3 np 4
test_0783 7 skipped 5 passed, 2 skipped 6, 1 skipped 7
test_0784 13 13 13 13
test_0785 5, 8 skipped 12, 1 skipped 12, 1 skipped 12, 1 skipped

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

@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Must fix 1, checked at 6b435ee by reading the code only (we ran nothing).

  • Placement. The refusal is in evaluate_nd inside the derivative branch, beside the evalf refusal and after expr is coerced to a Matrix. expr.shape is therefore always defined there.
  • Same verdict on every rank. The condition is derivfns and mesh is not None, rbf and not force_l2, and expr.shape != (1, 1). All three come from the symbolic expression and the call's flags, so every rank reaches the same verdict before the RBF work and before the swarm's migration. No rank is left waiting.
  • Scope. A local evaluate(..., rbf=True) of a matrix-valued derivative is refused too. It returned (N, 1, 1) before, which is right to stop. The refusal also covers a matrix that mixes a scalar derivative with plain fields. That is conservative, and the message gives the route that works.

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

@lmoresi
lmoresi merged commit fe494b1 into development Nov 8, 2026
9 checks passed
lmoresi added a commit that referenced this pull request Nov 8, 2026
…-from-mesh-906

Underworld development team with AI support from Claude Code
lmoresi pushed a commit that referenced this pull request Nov 11, 2026
#982 turns the remap limiter off by default, so the extrapolated 500 K is
stored unclipped. The case pins the storage-layout path under the clamp it
was written for (#1002), so set REMESH_MONOTONE to clamp for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…#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
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