Repository navigation
A re-declared mesh variable refuses to change; helper variables named after their owner; uw.unwrap expands completely (#1118, #824) - #1209
Conversation
…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
Adversarial review recordTwo 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
Round 2, on f7918ec. Fixed in c88d339
Attacks that found nothing
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
|
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)) 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. FindingsHigh: owner-derived names, but a shared symbol (swarm proxies, interface thickness)A mesh variable's
So the two owners' fields are one sympy object. Case 1: two swarms on one mesh, each with a degree-1 variable
Case 2:
By reading (not run): What is already right: the index-variable level sets ( 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:
Medium: names from
|
…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
e3f38fc: answers the change requestHigh: one sympy function for two helpers.
Medium: names from the instance counter diverge across ranks.
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 Pre-existing: the FreeSurface empty-rank Underworld development team with AI support from Claude Code |
|
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)) 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, Item by item
NotePrinted forms do not show the new identity: two owners' symbols still print the same ( What was run
Not run:
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
…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
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.
MeshVariableis 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.ValueError. The kind is mesh variable or integration-point variable. The message names what would change.__init__into_declared_layout, shared by both, so a type that overrides the component count is the same request.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:
level_set.interface_thicknessepsilon_<phi>, shown as \epsilontau_decoded, or the first freetau_decoded_<k>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.SurfaceCollectionandFaultCollectiondefault variable namesFreeSurfacefields (h_inf,un_tgt,V_p1,carry, the held solves' V and P, the mesh velocity, ...)id(mesh), which differs between ranks); every rank hits or misses the cache togetherA variable's symbol is told apart by its own name.
UnderworldFunctionidentified 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. Thena.sym - b.symwas 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 namefault_metric. It is the mmg path, which stays available but is not used internally.#824:
uw.unwrappasses its arguments by keyword.keep_constantsandreturn_selfpositionally intoexpressions.unwrap(fn, depth, keep_constants, return_self). Sokeep_constantsarrived asdepth, which expanded one level of a nested expression, or none.expressions.unwrap.keep_constants=Trueselects the 'dimensional' mode, which substitutes.value;apply_scalinghas 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.pydeclared "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:
Tests
tests/test_0131_redeclaration_and_unwrap.py(13 tests):dimcomponents, and an integration-point variable;uw.unwrapexpands a two-level expression to6 x, with and withoutkeep_constants.tests/test_0132_helper_variables_per_owner.pyputs 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.Stokes.tauwith 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):
After the merge of development (16e459c):
tests/parallel/test_1132_metric_density_shared_nodes_parallel.pyread the density cache byid(mesh), which this branch replaced. It now usesmetrics._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