Skip to content

A re-declared mesh variable refuses to change; helper variables named after their owner; uw.unwrap expands completely (#1118, #824) - #1209

Merged
lmoresi merged 7 commits into
developmentfrom
bugfix/unwrap-arguments-and-variable-redeclaration
Nov 16, 2026
Merged

lmoresi merged 7 commits into
developmentfrom
bugfix/unwrap-arguments-and-variable-redeclaration

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #1118 and #824, both from the probe sweep of 2026-11-15, which ran on development 176958a.

What changes

#1118: a re-declared mesh variable refuses to change.

  • A MeshVariable is identified by its name on the mesh. Declaring the name again used to return the existing variable and drop every new argument, with only a print.
  • A re-declaration that would change the kind, type, number of components, degree, continuity or symbol now raises ValueError. The kind is mesh variable or integration-point variable. The message names what would change.
  • One that asks for what is held returns the variable, as before. This is the rule Refuse a re-declaration that would change what an expression container holds #780 set for expressions.
  • The type and components are compared as the variable resolves them when it is built. That inference moves from __init__ into _declared_layout, shared by both, so a type that overrides the component count is the same request.
  • Units and the remesh policy are not compared.

Library helpers named after their owner. Several helpers made mesh variables under fixed names, so two owners on one mesh shared one variable and the second overwrote the first. With the refusal, that sharing raised instead. Each now has a name of its own, chosen the same on every rank from what the mesh already holds, not from a creation count:

helper new name
level_set.interface_thickness epsilon_<phi>, shown as \epsilon
decoded viscoelastic stress tau_decoded, or the first free tau_decoded_<k>
swarm proxies and index-variable level sets the plain name, unless a variable another owner made holds it on the mesh; then the first free numbered name (proxy_<k>_<name>, <name>_<k>_<i>). Each records the owner that made it, so a single swarm keeps the names its checkpoints carry, also when it returns to a mesh.
SurfaceCollection and FaultCollection default variable names numbered per collection
FreeSurface fields (h_inf, un_tgt, V_p1, carry, the held solves' V and P, the mesh velocity, ...) numbered per free surface
metric-density helpers the tag and degree only, since the variables live on their own mesh (development used id(mesh), which differs between ranks); every rank hits or misses the cache together

A variable's symbol is told apart by its own name. UnderworldFunction identified a variable's function by its display name and its mesh only. So two variables on one mesh that show one symbol were one function: the two swarms' <phase> proxies, or a varsymbol given twice. Then a.sym - b.sym was 0, and evaluating b gave a's values. The identity is now the mesh and the variable's clean name, which is unique on the mesh.

Not changed: uw.meshing.fault_metric(method="adapt") keeps its fixed name fault_metric. It is the mmg path, which stays available but is not used internally.

#824: uw.unwrap passes its arguments by keyword.

  • It forwarded keep_constants and return_self positionally into expressions.unwrap(fn, depth, keep_constants, return_self). So keep_constants arrived as depth, which expanded one level of a nested expression, or none.
  • It now agrees with expressions.unwrap.
  • Left open: the parameters' meanings. keep_constants=True selects the 'dimensional' mode, which substitutes .value; apply_scaling has no effect under the default; and tutorials 3 and 13 and the docstring describe them otherwise. That is a separate decision, not part of uw.unwrap passes keep_constants into depth: expands one level, and keep_constants=False expands nothing #824's title.

One example renamed. docs/examples/utilities/advanced/Ex_Integrals_on_Meshes.py declared "T" at degree 3 over an existing degree-2 "T". The new variable is "T3".

Tolerances and coordinate matches

None added to the library.

Test bounds:

  • the proxies' linear fields at 1e-12;
  • the interface thickness against its closed form on a regular box at rel 1e-10;
  • the fault distance against the distance to a plane at 1e-10;
  • the surface distance against the distance to a segment at 1e-10.

Tests

  • tests/test_0131_redeclaration_and_unwrap.py (13 tests):
    • each kind of change refuses, and the message names it;
    • identical re-declarations return the variable, including those whose type overrides the count, a manifold vector declared with dim components, and an integration-point variable;
    • uw.unwrap expands a two-level expression to 6 x, with and without keep_constants.
    • 9 fail on development (measured at 1bd2b66), and 4 on the first commit of this branch.
  • tests/test_0132_helper_variables_per_owner.py puts two owners on one mesh for swarm proxies, index level sets, the interface thickness, surface collections and fault collections. It checks that two variables showing one symbol are two functions that each evaluate their own values. Its tests fail on the code before the renaming, and the symbol tests on bffd9d4.
  • Untested here: the decoded viscoelastic stress. Stokes.tau with a log-conformation history raises on development (a shape mismatch in the tensor projection), and a separate PR fixes it and adds the two-solver test.

All runs are serial, on macOS (12-core Apple M4):

  • Level 1 and 2 tests: 4178 passed at e3f38fc. The failures are the three that also fail on development on this machine: two analytic_full entries, and test_1123's walk, a gmsh mesh difference.
  • Every test file touching the renamed helpers: 850 passed.

After the merge of development (16e459c): tests/parallel/test_1132_metric_density_shared_nodes_parallel.py read the density cache by id(mesh), which this branch replaced. It now uses metrics._density_variable(mesh, degree, tag) (c5ab848). The merge brought no conflict; _function.pyx's identity line is this branch's.

Review

Two rounds of adversarial review, then H1's review. All three records are posted below.

Issue state

Underworld development team with AI support from Claude Code

…letely (#1118, #824)

#1118: MeshVariable.__new__ returned the existing variable for a name already
on the mesh and dropped every new argument, with a print. A caller asking for
two components, degree 1 and the symbol \bar{f} got one component, degree 2
and {f}. A re-declaration that would change the number of components, the
type, the degree, the continuity or the symbol now raises ValueError, naming
what it would change and how to fetch the existing variable. One that asks
for what is held returns it, as before. On a manifold mesh a vector may be
declared with dim or cdim components. This follows the rule #780 set for
expressions. Units are not compared.

#824: uw.unwrap passed keep_constants and return_self positionally into
expressions.unwrap(fn, depth, keep_constants, return_self). keep_constants
arrived as depth, so one level of a nested expression was expanded, or none,
and return_self arrived as keep_constants. Both branches now pass them by
keyword.

Tests: tests/test_0131_redeclaration_and_unwrap.py; 7 of its 8 tests fail on
development fafbecb (the eighth, the same declaration twice, passes there
too). Level 1 and 2 tests on 6 workers (4167 passed, files that start
processes excluded) raise the new refusal nowhere.

Underworld development team with AI support from Claude Code
… are named after their owner (review of #1118)

From the adversarial review of 8350af1:
- _declaration_changes compared the raw num_components with the held count,
  while __init__ lets vtype override it. The same IntegrationPointVariable
  (vtype=VECTOR) or MeshVariable(n, vtype=SCALAR) declared twice raised, and a
  SYM_TENSOR re-declared as a (dim, dim) TENSOR was accepted. The type and
  shape inference moves out of __init__ into _declared_layout, and the
  re-declaration is compared on what it resolves to. The element kind (mesh or
  integration-point variable) is compared too.
- The message names the held variable and asks for its own arguments,
  instead of pointing at mesh.vars, which holds the internal base. A matching
  re-declaration returns the variable without printing on every rank.
- Library helpers made mesh variables under fixed names, so two owners on one
  mesh shared one variable (silently before, raising with the refusal). Each
  is now named after its owner, the same on every rank:
  - level_set.interface_thickness: epsilon_<phi>, shown as \epsilon;
  - the decoded viscoelastic stress: tau_decoded_<solver number>;
  - swarm proxies and index-variable level sets: the plain name, unless
    another owner holds it on the mesh, then with the swarm's number
    (_unshared_name). A single swarm keeps the names its checkpoints carry;
  - SurfaceCollection's default variable names: numbered per collection;
  - the metric-density helpers: mesh.instance_number, not id(mesh), which
    differs between ranks.
- docs/examples/utilities/advanced/Ex_Integrals_on_Meshes.py declared "T" at
  degree 3 over an existing degree-2 "T"; the new one is "T3".

Tests: tests/test_0131 gains a type-only change, a components-only change,
identical declarations whose type overrides the count, a manifold vector
declared with dim components, and the element-kind refusal; 4 of them fail on
8350af1. tests/test_0132_helper_variables_per_owner.py puts two owners on one
mesh for each helper; all 4 fail without the renaming. Level 1 and 2 tests and
every test file touching the renamed helpers pass, apart from
test_1123's walk test, which fails on development on this machine too.

Underworld development team with AI support from Claude Code
…t closed forms (review round 2 of #1118)

From the second adversarial review:
- FaultCollection's default variable names, like SurfaceCollection's, are
  numbered per collection; FreeSurface numbers every variable it makes
  (h_inf, h_inf_bg, un_tgt, V_p1, carry, carry_bc, the held solves' V and P,
  the mesh displacement and velocity), so two free surfaces on one mesh keep
  their own fields.
- A swarm variable's proxy and level sets record the swarm variable that made
  them, so a swarm that comes back to a mesh keeps its plain proxy name; the
  numbered index level-set names keep a separator through cleaning
  (M_<swarm>_<index>), so they cannot coincide.
- The metric-density cache is keyed on the mesh's instance number and global
  point and cell counts, the same on every rank, where its rank-local counts
  could make one rank build projection solvers alone.
- The clean-name rule is one function, _clean_name.
- test_0132 checks the proxy names, the index level-set names, the
  interface thickness against its closed form on a regular box, and two
  fault collections' distance fields against the distance to their planes.

uw.meshing.fault_metric(method="adapt") keeps its fixed name: it is the mmg
path. The decoded viscoelastic stress has no two-solver test: Stokes.tau with
a log-conformation history raises on development, which a separate PR fixes.

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

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 16, 2026

Copy link
Copy Markdown
Member Author

Adversarial review record

Two rounds, each by a fresh reviewer that read the code through git without running it. The measurements below were made by the author, serially, on macOS (12-core Apple M4).

Round 1, on 8350af1. Fixed in f7918ec

  • An identical re-declaration could raise, and some real changes passed.
    • The raw num_components was compared with the held count, while __init__ lets vtype override it.
    • So IntegrationPointVariable(..., vtype=VECTOR) twice raised.
    • And a SYM_TENSOR re-declared as a (dim, dim) TENSOR was accepted.
    • The inference is now one function, _declared_layout, and the re-declaration is compared on what it resolves to.
  • The element kind was not compared. It is now.
  • The message pointed at mesh.vars, which holds the internal base. It now names the held variable and asks for its own arguments.
  • Library helpers used fixed names: level_set epsilon, tau_decoded, swarm proxies, SurfaceCollection defaults, and the metric names, which used id(mesh) and so differ between ranks. Each is now named after its owner.
  • A shipped example re-declared "T" at another degree. The new variable is renamed.
  • Tests that could not fail. The type-only, components-only, identical-overriding, manifold and kind cases were added.

Round 2, on f7918ec. Fixed in c88d339

  • More fixed names: FaultCollection's defaults and FreeSurface's fields. These are now numbered per owner.
  • The numbered index level-set names could coincide after cleaning. They now keep a separator.
  • A swarm returning to a mesh got a new numbered proxy. Proxies now record their maker.
  • The metric-density cache key used rank-local counts. It is now the same on every rank.
  • The clean-name rule had several copies. It is now one function.
  • Docstring claims of closed forms the tests did not check. The thickness, fault and surface distances are now checked against closed forms, and the proxy names are asserted.

Attacks that found nothing

  • _declared_layout against the old __init__, line by line, for every vtype: no behaviour change.
  • Rank consistency: mesh.vars changes only through collective creation, so the choice of name agrees on every rank. The instance numbers rest on every uw_object being created on every rank, which the existing solver names already assume.
  • No caller relied on the old default names. Only the generated docstring inventory lists them.
  • The refusal fired nowhere in 4172 level 1 and 2 tests.

Left open

Issues

Underworld development team with AI support from Claude Code

…il Stokes.tau decodes

The previous commit carried the test file as it stood before two changes:
the two IndexSwarmVariables' swarms are now held (a variable needs its
swarm), and the two-solver decoded-stress test is removed, since Stokes.tau
with a log-conformation history raises on development; it returns with the
fix for that.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on head bffd9d4: changes requested. One high finding. The renamed helpers are now separate variables, but two of them still share one symbol, so any expression or evaluation that names the second owner gets the first. The rest of the PR does what it says, at np 1, 2 and 3, including a rank with no cells.

Findings

High: owner-derived names, but a shared symbol (swarm proxies, interface thickness)

A mesh variable's sym is a sympy function named by its symbol, not by its name. Two of the renamed helpers set a fixed varsymbol:

  • swarm proxies use \left<phase\right>, from the swarm variable's symbol;
  • interface_thickness uses \epsilon.

So the two owners' fields are one sympy object.

Case 1: two swarms on one mesh, each with a degree-1 variable phase. Swarm A holds x and swarm B holds 3y. The proxies are proxy_phase and proxy_21_phase, and both have the symbol {\left<phase\right>}.

  • a.sym[0] - b.sym[0] simplifies to 0.
  • uw.function.evaluate(b.sym[0], [[0.2, 0.3], [0.7, 0.6]]) returns [0.2, 0.7], which is A's x. B's 3y would be [0.9, 1.8]. Evaluating the proxy's own symbol, b._meshVar.sym[0], gives the same wrong answer.
  • A projection of a.sym[0] + b.sym[0] gives 6y, B counted twice. Its error against x + 3y is 3.0.
  • A projection of b.sym[0] alone is right, to 2.7e-5 against 3y. The conflation appears once both owners' symbols are in play.
  • The proxies' nodal arrays are both right, to 4e-16. That is all test_0132 checks, so it passes.

Case 2: interface_thickness on two level sets. The variables are epsilon_phi_a and epsilon_phi_b, and both have the symbol {\epsilon}.

  • e1.sym[0] - e2.sym[0] is 0.
  • After e2.array[...] = 5.0, evaluating e2.sym[0] returns e1's values, 0.0279 and 0.0280.

By reading (not run): SurfaceCollection.compute_nearest_fields has the same pattern. Its numbered fault_n_<n>, fault_id_<n> and fault_w_<n> keep the fixed symbols \hat{\mathbf{n}}_f, f_{id} and w_f. Two collections' fields would then be one symbol in a rheology expression.

What is already right: the index-variable level sets (M_<n>_^{[i]}), the free-surface fields, the fault and surface distance fields, tau_decoded_<n> and the metric helpers. Each takes its symbol from its new name, and their symbols differ.

On development the two owners shared one variable outright, so this is not a regression. But it means #1118's follow-up is not done: the values are now kept apart, and the expressions still mix them.

Suggested fix and tests:

  • Give the numbered branch of _unshared_name a numbered symbol as well, for example \left<phase\right>^{(21)}. A single swarm keeps its plain symbol, as it keeps its plain name.
  • Name epsilon after its level set, for example \epsilon_{phi_a}.
  • Do the same for the three nearest-field symbols.
  • In test_0132, assert that the two owners' sym differ, and that evaluate of each owner returns that owner's closed form.

Medium: names from instance_number differ between ranks once any rank makes an object the others do not

uw_object.instance_number counts every object, expressions included. Reading stokes.F1 makes three of them.

Case (np 2):

  • One mesh carries a Stokes solver and a swarm with phase.
  • Rank 0 alone reads stokes.F1, as a notebook display under if uw.mpi.rank == 0 does.
  • A second swarm with phase is then made.

What happens:

  • The second swarm's instance number is 30 on rank 0 and 27 on rank 1.
  • Its proxy is proxy_30_phase on rank 0 and proxy_27_phase on rank 1. The mesh-variable lists gathered from the ranks differ.
  • mesh.write_timestep(..., meshVars=[both proxies]) then fails on both ranks with Error in HDF5 call H5Fcreate(). Each rank opened a different per-variable file.

On development, both proxies were the one proxy_phase, which was wrong in another way. The same naming also reaches tau_decoded_<n> and the metric helpers' mdg_*_<n>. The latter is still much better than id(mesh), which differed between ranks every time.

This is an existing convention: the pressure split, the yield probe, the thin sheet, and the snapshot keys for swarms and history managers all use instance_number. So it need not hold this PR. Two ways to remove it:

  • a per-class counter, as this PR already uses for FreeSurface and the two collections;
  • agreeing the number across ranks once.

I suggest a follow-up issue if the class counter is not taken here.

Low: a numbered name is not checked for being free

_unshared_name returns numbered without looking it up in mesh.vars. In the contrived case, swarm 1 has a variable called 21_phase and swarm 21 has phase. Both proxies are then proxy_21_phase, which raises if the layouts differ and silently shares if they match. One lookup of numbered, with a further suffix if it is held, would close it.

Low: the PR body's failure counts

At development fafbecb, on this machine:

  • 9 of the 14 tests in test_0131 fail: the 7 refusal tests and both unwrap tests. The body says 7.
  • All 5 tests in test_0132 fail, the fault collection included. The body says the first four.

Confirmed correct

Two owners on one mesh, at np 1, np 2 and np 3 with an empty rank. The np 3 runs use a shell partition that leaves the last rank with no cells:

  • cells [4, 4, 0] for the viscoelastic box;
  • [35, 31, 0] for the swarm box;
  • [187, 185, 0] for the 3-D fault box;
  • [121, 121, 0] for the metric box.

In every case below, the mesh-variable names and the swarm-variable names gathered from every rank are identical.

  • Two viscoelastic solvers, stress history. The histories are distinct (psi_star_sl_25_0, psi_star_sl_60_0). Each solver's tau matches its own one-step closed form, at 3.5e-13 and 1.5e-15. A's stress is unchanged after B solves. At np 1 and 2, each equals the same solver on its own mesh exactly (difference 0.0).
  • Two viscoelastic solvers, log-conformation. Run on this branch merged with Tensor_Projection's work variable takes the tensor's degree; Stokes.tau decodes a log-conformation history #1210, because the decode needs it. They decode into tau_decoded_7 and tau_decoded_42, with the same closed-form errors at np 1, 2 and 3 (the np 3 run with an empty rank), and each equals its solo run exactly.
  • Two swarms with phase. The proxies are distinct, of degree 1 and 2, and each holds its linear field to 4.4e-16 at the nodes. The index variables M on two swarms give M0, M1 and M_38_0, M_38_1, with distinct symbols.
  • FaultCollection. fault_distance_0 and fault_distance_1 each match the distance to their own plane to 1.1e-16.
  • FreeSurface. Two free surfaces on one mesh, for two Stokes solvers with densities in the ratio 1 : 3. Every field is numbered (h_inf_fs0/1, V_held_fs0/1, V_cons_fs0/1, carry_fs0/1, un_tgt_fs0/1, ...). The velocities are in the ratio 3.000000. Each equals the same model on its own mesh exactly, at np 1 and 2. At np 3 with an empty rank, the free surface cannot be built at all; that is an existing defect, below.
  • The metric cache key. The key gathered from every rank is identical at head: (4, 1, 'own1', (154, 242)) at np 3 with an empty rank. At development it was not identical: it carried id(mesh) and the local point and cell counts. Two owners with different tags get separate entries and separate helper variables. A repeated call is a cache hit with the same result.
  • Checkpoint. model.save_state(file=...) and then load_state in a fresh process, at np 1 and 2, with the owner-derived names proxy_phase, proxy_21_phase and epsilon_phi. After load_state, the nodal values of both proxies are exact: 3.3e-16 against x and 1.3e-15 against 3y. Both swarms' particle data are exact.
  • Redeclaration (MeshVariable with an existing name returns the old variable and ignores new varsymbol, degree and components #1118).
    • The issue's reproducer now raises, at np 1, 2 and 3 alike: "would change its type, degree, symbol".
    • A change of degree, of continuity or of symbol alone, a type change, and an integration-point variable over a mesh variable each refuse, with the same outcome on every rank.
    • An identical redeclaration returns the held variable.
    • The mesh stays usable after the refusals.
    • At development, every one of these printed "Skipping" and returned the old variable.
  • uw.unwrap (uw.unwrap passes keep_constants into depth: expands one level, and keep_constants=False expands nothing #824). It now gives 6*x, with and without keep_constants. At development it gave 3*a_{in} both ways.
  • Build. The PR is Python-only, and its merge base has the same compiled source as the build used here.

Seen while reviewing, the same at development, not part of this PR

This is not investigated. It is worth an issue of its own.

  • FreeSurface with an empty rank. _build_interior_diffuser takes np.max(dist) of an empty array, so the empty rank raises and the others wait (np 3). The branch on dist is also decided rank by rank.

What was run

  • New tests: test_0131 and test_0132.

    • serially at head: 18 passed;
    • at np 2 at head: 18 passed;
    • serially at development: 14 failed, 4 passed.
  • Probes (one script, logs kept by the reviewer):

    • at np 1 and 2: two viscoelastic solvers, two swarms, two index variables, two fault collections, two free surfaces, metrics, redeclaration, the rank-dependent naming case, checkpoint write and read, and the symbol checks;
    • at np 3 with an empty rank, through a shell partition hook on gmsh meshes: the same set except the checkpoint and the symbol checks.
  • Neighbours, serially at head: 324 passed, 2 skipped. The files:

    • swarms and proxies: 0005, 0067, 0068, 0071, 0072, 0110, 0111, 0113, 0115, 0116, 0117, 0506, 0020 (swarm snapshot), 1164;
    • surfaces, faults and metrics: 0540, 0850 (surfaces and faults), 0847, 0762, 0750, 0765;
    • level sets and free surfaces: 1105, 1070, 1074;
    • viscoelastic: 1054;
    • JIT: 0103, 0105;
    • and 0131, 0132.
  • Neighbours at np 2 at head: every test passed in 0072, 0115, 0116, 0117, 0506, 0540, 0850 (surfaces and faults) and 1074; that is about 270, counted from the progress output. Three files fail at np 2 at development too, identically, from a rank-local assertion followed by a hang or abort; they are serial tests:

    • 0071 test_the_symbol_participates_in_expressions[nodes] (4.12 > 4.5);
    • 0113 test_issue289_proxy_tracks_particles_through_advection ("blob must contain particles" on one rank);
    • 1105, second test (0.3005 < 0.2).

    0750 was not reached at np 2.

Every parallel run went under the MPI supervisor.

Not run:

  • the full suite;
  • test_1072 (spherical free surface);
  • the 3-D compute_nearest_fields case (read only);
  • the neighbour files at np 3;
  • 0750 at np 2.

Underworld development team with AI support from Claude Code

…only the mesh's variables (review of #1209)

H1's review of bffd9d4:
- The helpers had separate names but one sympy function: UnderworldFunction
  identified a variable's function by its display name and the mesh, so two
  swarms' proxies of "phase" (both shown as <phase>) were one function, and
  a.sym - b.sym was 0, evaluating b gave a's values. Any two variables on a
  mesh showing one symbol did the same. The function's identity is now the
  mesh and the variable's clean name, which is unique on the mesh.
- Names built from instance_number diverge across ranks when one rank makes a
  uw_object the others do not (an expression printed on rank 0 alone), and a
  write_timestep then fails in H5Fcreate. The helpers' names now read only
  mesh.vars, which collective creation keeps the same on every rank
  (_owned_name): the plain name if free or the owner's, else the first free
  numbered one. Swarm proxies, index level sets and tau_decoded use it; the
  metric-density helpers need no number, their names living on their own
  mesh. Collections and free surfaces keep their own class counters, which
  count only objects made on every rank.

Tests: test_0132 checks that two swarms' proxies are two functions and that
each evaluates its own values, that the interface thickness and a user's
epsilon are two functions, and that two variables showing one varsymbol
evaluate their own sum; these fail on bffd9d4. Level 1 and 2 tests (4178
passed) show only the three failures that also fail on this branch's base on
this machine.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

e3f38fc: answers the change request

High: one sympy function for two helpers. UnderworldFunction identified a variable's function by its display name and its mesh only, so every pair of variables on one mesh showing one symbol was affected, not only the helpers. The identity (_uw_id) is now the mesh and the variable's clean name, which is unique on the mesh. The new tests in test_0132, which fail on bffd9d4:

  • two swarms' phase proxies: a.sym - b.sym is not 0, and each evaluates its own field;
  • the interface thickness and a user's epsilon are two functions;
  • two variables declared with one varsymbol evaluate their own sum.

Medium: names from the instance counter diverge across ranks.

  • The helpers' names now read only mesh.vars, which collective creation keeps the same on every rank (_owned_name): the plain name if it is free or the owner's, else the first free numbered name.
  • Swarm proxies, index level sets and tau_decoded use it.
  • The metric-density names need no number, since they live on their own mesh.
  • Collections and free surfaces keep their class counters, which count only objects made on every rank.
  • The _uw_id above still holds mesh.instance_number. That is rank-local identity, and nothing written to disk reads it.

Runs. Serial, on macOS (12-core Apple M4): level 1 and 2 tests 4178 passed. The 3 failures also fail on this branch's base on this machine: two analytic_full entries, and test_1123's walk on this host's gmsh mesh. Not run here: your rank-divergence case with stokes.F1 read on rank 0 only, then write_timestep, at np 2. Please re-run it.

Pre-existing: the FreeSurface empty-rank np.max. That fix is a separate PR, next.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on head e3f38fc (round 3): ready to merge on green from this review. Both earlier findings are fixed. The change to symbol identity reads old checkpoints and keeps every expression test passing, and I found no stored symbol it could silently mismatch.

I re-checked both earlier findings and the risk the author flagged, that a change to symbol identity touches every expression.

Round 3 changes one compiled file, function/_function.pyx, so this round was run on a fresh build of e3f38fc. The development side used a build whose compiled sources match merge base fafbecb.

Item by item

Item Earlier finding Result at e3f38fc Evidence
Two swarms' phase proxies High: one symbol, values conflated Fixed proxy_phase and proxy_1_phase are distinct functions; a.sym - b.sym no longer simplifies to 0. At np 1 and 2, evaluating a gives x and evaluating b gives 3y at three points (to rounding). Projecting a + b gives x + 3y to 1.7e-13; before, it was 6y, with error 3.0.
interface_thickness on two level sets High: one symbol Fixed epsilon_phi_a and epsilon_phi_b are distinct functions. After e2.array[...] = 5, evaluating e2 gives 5 and e1 keeps its closed form, at np 1 and 2.
SurfaceCollection.compute_nearest_fields (now run, 3-D box, two collections) High, by reading Fixed fault_n_0/1, fault_id_0/1, fault_w_0/1 and d_faults_0/1 are distinct functions. With the id fields set to 1 and 2, each evaluates to its own value. Each weight field matches exp(-0.5 (dz / 0.1)^2) to 6e-17, at np 1 and 2.
Rank-divergent names (rank 0 alone reads stokes.F1, then a second swarm, then write_timestep, at np 2) Medium: proxy_30_phase on one rank and proxy_27_phase on the other; the HDF5 create failed Fixed The instance numbers still differ (30 and 27), but the names no longer depend on them: both ranks name the proxy proxy_1_phase, the gathered lists are identical, and write_timestep writes both files.
A numbered name not checked for being free Low Fixed _owned_name takes the first numbered(k) that is free or the owner's own.
PR body failure counts Low Left The body still says 7 tests in test_0131 fail on development; it is 9 here. Text only.
Development checkpoint read on the branch (np 1, np 2) Risk Reads back Written on development: mesh variables T (P2), V (P2 vector, own varsymbol) and the proxy proxy_phase, plus the swarm variable phase. Read on the branch with read_timestep: T and V exact (0.0), proxy_phase to 8.9e-16. The swarm read path gives the same nearest-neighbour result as a branch-to-branch read (8.4e-2 on a linear field over a different particle layout; that is the interpolation, not a mismatch). load_state of the development snapshot also restores T exactly and proxy_phase to 8.9e-16.
Branch checkpoint read on the branch (np 1, np 2), two swarms Risk Reads back proxy_phase 8.9e-16 and proxy_1_phase 1.8e-15, by read_timestep and by load_state; T and V exact.
Other stores of symbols or names Risk None at risk The disk snapshot keys variables by clean name and does not write sympy objects (they are marked as skipped). The in-memory snapshot holds live references within one process. The transcript is JSON text: one written on development reads back on the branch with uw.read_transcript, with its records intact. The srepr-keyed caches (the JIT graph hash and the pure-sympy lambdify cache) are in memory and need no compatibility.
Two meshes, a variable T on each Must stay distinct Distinct The two functions differ, and JIT projections and evaluations on each mesh give that mesh's values (x and 2x), at np 1 and 2.
The same variable fetched again Must be identical Identical Re-declaring it, reading it through mesh.vars["T"], and reading it after a DM rebuild all give the identical function, with an equal hash and the same func object. A second projection solver on the same expression builds no new JIT module (1 before, 1 after).
JIT reuse between two functions that print alike Not asked; checked Correct srepr of a mesh-variable function prints only its display name (Function('{T}')(N.x, N.y)), so I checked compiled reuse explicitly. On one solver, projecting a and then b gives x and then 3y; a new solver on a after b gives x, all to about 1e-13, at np 1 and 2.
New tests Pass test_0131 and test_0132: 19 passed serially and 19 at np 2 at e3f38fc. Against bffd9d4, the three symbol and level-set tests in test_0132 fail, as they should.
Expression-heavy slice Pass 1098 passed, 9 skipped, 14 xfailed, 1 xpassed. The xfails are the files' own known gaps (units extraction, std()). The xpass, test_0720 test_mesh_coordinates_complex, also xpasses at development.

Note

Printed forms do not show the new identity: two owners' symbols still print the same ({\left<phase\right>}(N.x, N.y) - {\left<phase\right>}(N.x, N.y) is a nonzero difference). That is a readability point only; the values are right.

What was run

  • Build: e3f38fc built fresh. The development side used the build at fafbecb's compiled sources, with development's Python at the merge base.

  • Probes: serially and at np 2:

    • symbol identity;
    • 3-D surface collections;
    • the variable identity and JIT reuse checks;
    • the rank-divergence write;
    • checkpoint write and read in both directions;
    • transcript write on development, read on the branch.

    Every parallel run went under the MPI supervisor. Logs are kept by the reviewer.

  • Slice: 137 test files (JIT, unwrap, units, adjoint, evaluate, expressions, viscoelastic and log-conformation, swarm proxies), serially, with -m "not tier_c" and three pytest workers. The log-conformation shear start-up recurrence was left out for time; it ran in full on Tensor_Projection's work variable takes the tensor's degree; Stokes.tau decodes a log-conformation history #1210's review.

Not run:

  • the full suite;
  • checkpoints across a change of rank count;
  • np 3 for this round.

Underworld development team with AI support from Claude Code

test_1132 found the cached density by matching the cache key's first entry
to id(mesh), which #1209 replaced with the mesh's instance number, so the
lookup found nothing (CI, shard 4). metrics._density_variable(mesh, degree,
tag) returns it, so a test need not know the key's layout.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit aa3c49d into development Nov 16, 2026
10 checks passed
lmoresi pushed a commit that referenced this pull request Nov 16, 2026
…nd H1's review of #1220)

Two meshes' UWCoordinates are unequal under == but hash-equal and structurally
equal, and unwrap of an expression over the coordinates returns one object for
both meshes, holding the first mesh's UWCoordinates: a derived solver's copied
viscosity carried them into the second mesh's solver. A coordinate is a
position, not mesh-owned data, so coordinates no longer identify a mesh at all;
variables carry their mesh in their function class (#1209). The rotated
normal's re-tag stays, for its own check (a normal written in another mesh's x
and y is accepted, by name). test_0745 adds a first FreeSurface that is built
and never solved.

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.

2 participants