Repository navigation
Units contract: evaluate refuses mixed units and far points; Stokes fields carry units (#771, #904, #881, #786, #844, #1001) - #1182
Conversation
… units model (#844) Stokes(mesh, velocityField=v) used to discard v when no pressure was passed, and the reverse. Now only the missing field is created. In a model whose scales cover them it is created in m/s or Pa (units ruling, 2026-11-13), so the default path never builds a unitless field in a units model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yield_stress_min's 0 Pa default made a viscoplastic stress pascal-tagged in a model with no units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… points far outside the mesh (#771, #904, #786) In a model with reference quantities, evaluate and global_evaluate refuse an expression that combines a field without units with a leaf that has units, and name both. A field without units alone is still a pure number. A point the locator places in no cell and that lies further outside the node bounding box than the mesh's largest cell radius is refused, serially in evaluate and collectively in global_evaluate. check_extrapolated=True returns the mask instead, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The contract said evaluate is non-dimensional; the units design, and the code, make it the dimensional gateway. Brought into line with the 2026-11-13 ruling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…786) Every rank calls it, a rank with no points contributing none, and the bounding box is reduced with the buffer Allreduce: the pickled form compared whole arrays and raised on one rank, which left the others in the collective (test_0783, test_1152 hung at np 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…refuses before evaluating (#844, #786, #999) A field passed alone must fit degree, or the one created beside it would pair into an unstable P1/P1 or P2/P2 problem that converges silently (review finding 1). A units model with no mass scale is kinematic: Stokes, which needs stress, refuses at construction, naming the missing scale (ruling, 2026-11-13). The far-outside refusal is a bounding-box test with the mesh's largest cell radius as the scale, before any evaluation: it needs no point location, and refuses a derivative as it does a field, at any rank count (#999's case). Tests: a solve into a passed field, a no-units baseline, degree mismatch, kinematic model, #999 serial and parallel; a tier per test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The velocity it would create comes after the passed pressure on the mesh, and the solver takes the first of the pair as the velocity, so the velocity boundary conditions would land on the pressure. Refused, naming the fix: pass both, velocity first, or neither. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1147) The pressure-nullspace guard, not the boundary-condition assignment, finds the pressure by creation order; without the nullspace the solve is right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evaluate(v, pts) with the MeshVariable rather than v.sym reached mesh_vars_in_expression unwrapped and raised (test_0820). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verdict: NOT READY at 4366ba0. Built and tested merged with development c2aa36b. The merge was clean, with no conflicts. Review and parallel test runs by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). The parallel side holds up. The far-point refusal reaches the same verdict on every rank at np 2, 3 and 4. That includes a rank with no cells and ranks that are passed no points, and nothing hangs. The kinematic refusal is also clean on every rank. Two other things do not hold up:
Findings1. High: the far-point refusal breaks the remap inside
|
| test | branch | development |
|---|---|---|
tests/test_1071_slcn_moving_mesh.py::test_slcn_bounded_on_wobbling_squeezed_annulus (serial) |
fails: "85 of 3460 query points lie outside the mesh, further than its largest cell (0.0454 model units)" | passes |
tests/parallel/test_1172_moved_refined_mesh_solves_on_moved_geometry_parallel.py, np 2 |
6 failed, 19 passed: "106 of 376 query points lie outside the mesh …" | 13 passed, 2 skipped |
| same file, np 4 | 6 failed, 18 passed | 13 passed, 2 skipped |
The failures are the same on every rank, so nothing hangs. Still, a single deform whose boundary moves by more than a cell is a normal operation (a free surface, or a squeeze as in test_1071), and it is now refused.
Fix: internal resampling must not go through the user-facing refusal. The remap (and the old-frame semi-Lagrangian sample in ddt.py, which samples feet that are not clamped) should pass check_extrapolated=True, or call the evaluator below the gateway.
Reproduce: pytest tests/test_1071_slcn_moving_mesh.py, and mpirun -n 2 python -m pytest --with-mpi tests/parallel/test_1172_moved_refined_mesh_solves_on_moved_geometry_parallel.py.
2. High: in a units model, the default Stokes stress comes back in 1/s
Stokes(mesh) now creates u in m/s. The viscosity parameter keeps no units:
- its default is
UWexpression1, withunits None; - a plain number set by the user, such as
shear_viscosity_0 = 1, also has none.
(The #881 change applies to ExpressionDescriptor; ViscousFlowModel.shear_viscosity_0 is an api_tools.Parameter.) The gateway then dimensionalises 2·η·E(u) as a strain rate. There is no refusal, because a plain number is not counted as a leaf.
Reference quantities: 1000 km, 1e21 Pa s, 1 cm/yr. The velocity is set to a model-unit shear, dvx/dy = 1. Output of evaluate(stokes.constitutive_model.flux[0, 1], [[0.5, 0.5]]):
| viscosity | development | branch |
|---|---|---|
| default | 0.99999995 (plain, model units) | 3.1688e-16, units 1/s |
= 1 |
0.99999995 (plain) | 3.1688e-16, units 1/s |
= uw.quantity(1e21, "Pa*s") |
1.0e21 kg/(m s), the #771 defect | 3.1688e5 Pa (correct) |
So the PR fixes the dimensional-parameter case, but the common default path goes from a correct number in model units to a wrong number labelled with the wrong units. This contradicts the PR's statement that "the default path never builds the mix". Either:
- a parameter holding a plain number in a units model is read as a model-unit value carrying its declared units; or
- the refusal counts a parameter that has no units beside a field that has units as a mix.
The PR's own test (test_stokes_default_stress_evaluates_in_pascal) sets the viscosity as a quantity, so it does not see this.
3. High: a library-internal mixed-units refusal stops a NavierStokes solve (test_1153), and "dimensionless" counts as dimensional
_unit_leaves counts any leaf whose units is not None as dimensional, dimensionless included. The semi-Lagrangian trace history creates its vtrace_* variables with units=uw.get_units(V). For a velocity without units in a units model, that is dimensionless, measured. The second NavierStokes step then evaluates V·(1+r) − vtrace·r and is refused:
tests/test_1153_timestep_estimates_and_setters.py::test_a_navier_stokes_step_given_as_a_ratio_of_times_is_reduced, which fails with "mixes fields without units (U1153n) with leaves that have units (vtrace_15_n1)"; it passes on development.
The same rule gives false refusals to users. Serial probe, units model (30 km, 1e24 Pa s, 2.5 mm/yr), T a field without units holding 2:
| expression | development | branch |
|---|---|---|
T * eta1/eta0 (both Pa s, ratio 1000) |
2000, plain (correct) | refused |
T * exp(eta1/eta0 - 1000) |
2, plain | refused |
T * k with k = uw.expression(..., uw.quantity(3, "dimensionless")) |
6 | refused |
T * phi with phi a field of units "dimensionless" |
1 | refused |
Suggested fix: count a leaf as dimensional only when its units are not dimensionless, so a dimensionless ratio of dimensional constants is not a mix.
4. Medium: existing tests broken by the ruled refusals, and not updated (test_1059, test_1056, test_1148)
These follow from the 2026-11-13 ruling, but the PR states "No existing test changed", and these tests fail on the merged tree:
tests/test_1059_yield_stress_min_units.py, all 9 tests, are refused atevaluate(constitutive_model.viscosity). The yield stress isC_0 · seed, whereseedis a field without units. Under the ruling,seedneedsunits="dimensionless". With the current rule (finding 3) that works only because no field without units is left in the expression.tests/test_1056_navier_stokes_supg_api.py::test_estimate_dt_carries_time_units_on_both_basesandtests/test_1148_changing_timestep_keeps_the_snes.py::test_a_timestep_with_units_is_the_reduced_constant[navier_stokes_slcn]both raise "Stokes needs length, time and mass scales … no mass scale". The refusal fires even when both fields are passed, as here (NavierStokes always takes both).
All 13 tests in findings 1 (serial part), 3 and 4 pass on development: 17 passed in the same selection, and the branch gives 13 failed, 4 passed. The PR's serial run covered bands 0000–0499, 01, 05, 062, 07, 08, 1000–1019, 107 and 110. That leaves out 1056, 1059, 1148 and 1153, and the parallel test_1172 at np 2 and 4. Test_1071 is in band 107 but fails on the merged tree, probably through remesh changes on development since d66c7da.
5. Low: refusals the checks miss
- A field wrapped in a
uw.expressionis not checked for far points.mesh_vars_in_expressiondoes not descend into aUWexpression, although_unit_leavesdoes. Serialevaluate(uw.expression("wfar", 2*T), [[6e4, -3e4]])returns 1.917, extrapolated, whereevaluate(T, …)is refused. Constitutive parameters are built this way. - Coordinates are not leaves, so
T * xreturns 30000 m andT + xreturns 75000 m on both arms. They carry the same "unknown dimension" ambiguity asT * eta, which is refused. That is defensible as a design choice, but it should be stated.
6. Low: the far-point refusal depends on the rank count for a rank-local evaluate
It is checked in evaluate only when uw.mpi.size == 1. At np 2, the same evaluate(T, [[0.5,0.5],[6e4,-3e4]]) returns 0.958 on rank 0 and 1.0 on rank 1, extrapolated, where np 1 raises. The PR documents this, but the same script now raises in serial and silently extrapolates in parallel. Consider a warning there in parallel, beside the existing #606 one.
Parallel safety: what was checked
The far-point refusal. Probe of 13 cases, under the supervisor:
- default partition, at np 2, 3 and 4;
- a forced partition whose last rank holds no cells (cells per rank [162, 0], [87, 75, 0] and [62, 49, 51, 0]), at np 2, 3 and 4.
Each case gathers every rank's outcome. Every verdict agreed across ranks, in every configuration, and no run hung. The cases:
- a far point on rank 0 only, and on the rank with no cells only;
- a far point on one rank while every other rank, or rank 0, is passed no points;
- no rank passed any points;
- a point less than one cell outside;
- a pure coordinate expression, which is not refused;
- global_evaluate of a derivative raises at np 2 and up when a point is outside the domain #999's scalar derivative and gradient at (1.5, 0.5);
check_extrapolated=True, which returns the mask.
How "far" is measured. Against the global node bounding box: an elementwise buffer Allreduce MIN/MAX, where a rank with no nodes contributes ±inf. The tolerance is the global largest _cell_radii (get_max_radius, an allreduce). The far count is summed across ranks before the raise, so the raise is collective. There is no absolute tolerance. In serial the box and radius are local, which is the same thing.
The kinematic refusal. Clean ValueError on every rank at np 1 and 2, for models with:
- length and velocity;
- length and viscosity (no time or mass scale);
- length, time and temperature.
Length, velocity and viscosity gives m/s and Pa.
Scanner over the .pyx hunk (prototype collective-guard scanner).
.pyx: the merged tree gives the same 29 hits as development c2aa36b. Nothing new.- With
.pyfiles: one new hit,_refuse_points_far_outsidereturning onmesh is NonebeforeAllreduce.meshcomes frommesh_vars_in_expression(expr), which depends only on the expression, so the guard is the same on every rank. Benign. - The constructor's new raises (kinematic model, degree mismatch, pressure only) depend only on model state and arguments, and come before any collective.
#999
This PR does not close #999, and it does not claim to. The far point is now refused the same way at every rank count. The part left is a point less than one cell outside, probe point (1.05, 0.5):
- the gradient still raises
NotImplementedError(therbf=Trueguard) at np 2, 3 and 4, on both partitions, where np 1 returns shape (3, 2, 2); dVx/dxthere depends on the rank count:
| partition | np 1 | np 2 | np 3 | np 4 |
|---|---|---|---|---|
| default | 1.9999 | 1.8789 | 1.8999 | 1.8999 |
| with a rank holding no cells | 1.896 | 1.9061 |
On development at np 2, the far gradient raises NotImplementedError and the far dVx/dx returns 1.8912; the near case is the same as on the branch.
Test numbers
test_0760 and parallel/test_0786 duplicate existing numbers. The test-coverage gate (scripts/check_test_coverage.py) passes on the merged tree ("all 462 test files are reachable"), and 91 serial test numbers are already shared on development, so nothing minds. The new parallel file uses skipif(uw.mpi.size < 2) rather than mpi(min_size=2). It is still picked up by the enumeration of tests/parallel/.
What passed
- The PR's tests on the merged tree:
- serial: 21 passed, 2 skipped;
tests/parallel/test_0786_global_evaluate_outside_domain_parallel.py: 4 of 4 on every rank, at np 2, 3, 4 and 8.
- On development, the same files give 14 failed and 7 passed, as the PR states.
- Serial evaluate and units files: 173 files that call
evaluate,global_evaluate,set_reference_quantitiesorunits=, excluding tier C, with 6 xdist workers.- Result: 1418 passed, 13 failed, 8 errors.
- The 13 failures are findings 1, 3 and 4.
- The 8 errors are
test_1086_mmpde_seam_matches_serialcavity cases, whose serial child was silent for 120 s under load. Rerun alone, they pass on both arms (8 passed each).
- Parallel evaluate files: 37
tests/parallel/test_*files that callevaluate, in batches of 6 under the supervisor.- np 2: 155 passed, 6 failed.
- np 4: 163 passed, 6 failed.
- All 12 failures are test_1172 (finding 1). No supervisor events.
- A convection-style probe in a units model: Stokes with its own fields, a temperature without units advected by it, two AdvDiffusion steps, and swarm advection. It runs at np 1 and 2, and the solution matches development.
Not run
- The full serial suite, and
scripts/test.sh --parallel-onlyat np 3 and 4. - 3-D meshes, and curved meshes (annulus, sphere) for the far-point rule with a point inside the bounding box.
- The parallel evaluate files at np 3 and 8.
Development arm. The development comparison used a build at c766bea. Development has moved 30 commits since, to c2aa36b. The ones touching the changed areas:
- The monotone clamp bounds a value by the cell it was interpolated in (#682, #994) #1153: the monotone clamp by containing cell, in
functions_unit_system.pyand_function.pyx; - A solid disc declares a Lower boundary its mesh has no label for, and asking for that label is a segmentation fault #1163: label checks;
- sensitivity() leaves out the flux and continuity-row terms of a natural or Nitsche condition: wrong-signed gradient for a Nitsche datum #1143: the boundary terms of
sensitivity().
None touches the new checks. Every failing test file is identical on both arms, and every failure traceback ends in a function this PR adds. The comparison stands.
Aside: on development, a probe where rank 0 alone passed a 1-D coordinate array (2,) to global_evaluate, and the other rank (0, 2), hung at np 2. Rank 0 raised before a collective that rank 1 entered (get_max_radius). That is pre-existing, outside this PR, and was not retried on the branch.
Logs kept by the reviewer.
Underworld development team with AI support from Claude Code
…sionless is a pure number (H1's review of #1182) - An internal-resampling context, entered on every rank, under which the far-point check stands aside: remap_var_set, mesh.remesh's transfer and the refinement transfers ask about moved nodes that can lie more than a cell outside the old geometry. - A field or constant declared dimensionless is a known pure number: neither a field without units nor a dimensional leaf. - The far-point check unwraps named expressions, so a wrapped field is seen. - test_1056 and test_1148 give their kinematic models a mass scale (a solver that needs stress is refused without one); test_1059's seed multiplier is declared dimensionless. Underworld development team with AI support from Claude Code
…bers the solver's fields (#844) The pressure-only refusal existed because the pressure-nullspace guard read the pressure by creation order (#1147). With #1170 merged, the passed pressure is kept and the velocity created beside it with degree `degree`; a pressure whose degree is not degree - 1 is refused with the degree to pass. Underworld development team with AI support from Claude Code
Solver-side read of the
|
| fields | mesh field_id (u, p) |
solver fields | largest difference from the default, velocity / pressure |
|---|---|---|---|
| none passed | 0, 1 | velocity, pressure | reference |
| velocity alone | 0, 1 | velocity v, pressure created |
0 / 0 |
| pressure alone | 1, 0 | velocity created, pressure p |
0 / 0 |
| both, pressure created first | 1, 0 | v, p |
0 / 0 |
| a scalar first, then pressure alone | 2, 1 | velocity created, pressure p |
0 / 0 |
Same in both the pinned and the unpinned set; with the pin the pressure on Top is exactly 0 in every row. The last row is the one where the mesh's field 1 is the pressure and the velocity is the mesh's field 2. These differences are not zero by construction: before #1170 the pressure-first rows addressed the wrong field.
tests/test_0760_evaluate_units_contract.py and tests/test_1013_stokes_fields_by_solver_number.py: 45 passed.
Findings
-
test_stokes_keeps_a_pressure_passed_without_a_velocitywould pass with a wrong pressure. It assertsabs(p).max() > 0. A hard baseline is available at no cost: the solution is identical to the default-order solve (table above), so the test can assert the pressure and velocity equal those ofStokes(mesh)on the same mesh. -
The "degree that fits" case in
test_a_passed_field_of_the_wrong_degree_is_refusedis a pair that locks.Stokes(mesh, velocityField=v1, degree=1)creates a pressure of degree 0 beside the P1 velocity (162 pressure unknowns on 162 cells). On the problem above it converges (reason 2) with a largest velocity of 5.2e-8, where P2/P1 gives 2.5e-2. This is not new: by reading,Stokes(mesh, degree=1)on development builds the same pair. But the hunk's comment says the refusals stop the solver from pairing a passed field with one that does not fit it "and solve an unstable pair without a word", and the test then asserts this pair is accepted. Suggest the accepted case use a P3 velocity withdegree=3, and the comment say what the refusals cover: a passed field whose degree disagrees withdegree. Refusingdegree=1itself is a separate question and not for this PR.
Read and found in order
_stokes_default_units()is called before any field is created, so the kinematic-model refusal leaves no half-built variable behind.- The refusals apply only when exactly one field is passed; both passed is left to the caller, as before.
- The tests use identity (
is None) in place of== None.
No tolerances or coordinate matches in the hunk.
Underworld development team with AI support from Claude Code
…ccepted degree is P3 (W1's re-check of #1182) The kept-pressure test now compares velocity and pressure with Stokes(mesh) on the same mesh. The accepted-degree case was P1 velocity with P0 pressure, a pair that locks; it is P3 with degree=3 now. The comment states what is refused: a passed field whose degree does not match. Underworld development team with AI support from Claude Code
|
Verdict: READY with conditions at d1ec701. The head already contains development 4b782b2, so merging development into it changed nothing ("Already up to date"). It was built and tested as d1ec701, merged with development 4b782b2. Re-review and parallel test runs by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). The earlier review was at 4366ba0, merged with development c2aa36b, and found the PR NOT READY. Every regression from the earlier review is gone:
The internal-resampling context is collective-safe. The far-point refusal still agrees on every rank in all 13 cases, including a rank that holds no cells. A pressure passed alone gives a solve bitwise equal to Two conditions:
Finding 2 is still awaiting the lead's ruling, as the PR body says. The earlier findings
New findingsA. Medium: a dimensionless ratio of dimensional constants is still refused beside a field without units
A viscosity contrast written as a ratio of two dimensional viscosities is a common way to build a rheology. Beside a temperature without units it is now refused, although the product is well defined. The workaround is to state the ratio as a dimensionless quantity. Either:
B. Low: the PR body contradicts the pressure-only changeCommit 7aa1a3d replaces the pressure-only refusal with a degree check. The body still says otherwise in two places:
The test list in the body names "a solve into a passed velocity" but not the new kept-pressure test, which compares against C. Low: the degree-mismatch message for a P0 pressure suggests a locking pair
D. Informational: a passed pressure's continuity is not checkedA discontinuous P1 pressure passed alone is accepted beside a P2 velocity ( The internal-resampling context: collective safetyWhat it is.
It is used only as
Every rank enters it alike.
The check is decided before any collective. In Could a user's
What stays outside the context. The semi-Lagrangian sample in Scanner (prototype collective-guard scanner, Python and Cython). Compared with development 4b782b2, the head adds two hits and removes none, ignoring line numbers. Both are in
The far-point refusal again (np 2 and 4)The same 13-case probe as in the earlier review was run under the supervisor, on two partitions:
In all four configurations, 13 of 13 verdicts agreed across ranks, and nothing hung. The only change from the earlier run is the "field wrapped in
The kinematic-model refusals are clean and identical on every rank at np 1 and 2. A model with length, velocity and viscosity gives m/s and Pa. The kept-pressure path (np 1 and 2)
Wrong degree. Refused with the same
A P2 pressure with The wider sweepSerial. The same 172 test files as the earlier review: those that call
Earlier this sweep gave 1418 passed, 13 failed and 8 errors. The 13 failures were findings 1, 3 and 4, and all are gone. Parallel. The 38
The PR's own tests.
Development arm. The comparison used a development build at 4b782b2. That is exactly the development commit merged into the head, so there is no difference between the two arms' development code. The only failures on the head were test_1086 under load, and those pass on both arms when run alone. No other comparison was needed. Not run
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
… a units model; mixes decided per product (#1182) Louis's ruling (option c): in a model with reference quantities a finite nonzero bare number assigned to a parameter that declares a dimension is refused at the setter, naming the units and the uw.quantity form; an unset dimensional default (viscosity 1) is refused when a solve or an evaluate first reads it, the same on every rank. Numbers inside expressions stay pure numbers. The mixed-units refusal now reduces each product's dimensional factors together: T*eta1/eta0 and T*exp(-E/(R*T0)) are pure numbers beside T, T*eta1 is refused (H1's review). A P0 pressure passed alone is pointed to P2/P1. Library work is exempt through the internal context: the solver's history (ddt), and the adjoint's inert scratch assemblers. Tests and docs that set dimensional parameters with bare numbers in a units model now say model_units(value, units) (tests/_units_helpers.py), which keeps their numbers; test_0812 and test_0817 gain the time (and length) scales a diffusivity needs; test_1059's bare-float floor is now the refusal it gets. Tutorial 13's diffusivity is a quantity. Underworld development team with AI support from Claude Code
…-11-13) Underworld development team with AI support from Claude Code
|
Re-check of #1182 at 6e94dc9 (Louis's bare-number ruling): READY. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). Built merged with current development (a clean merge), following the re-review at d1ec701. 1. Every refusal is the same on every rank, including a rank with no cells.
There was no hang, including on the empty rank. 2. The per-product mix check accepts exactly the products that come out dimensionless.
3. Tests on the merged tree.
Not rerun at this head: the 172-file serial sweep and the 38-file parallel sweep from the d1ec701 re-review. The author reports a full serial and np 2 pass on this head. Underworld development team with AI support from Claude Code |
…tant, the warm start copies stored values (H1's review of #1205) - _check_derived_solvers_match called .subs on the plain number a constant unwraps to in a units model, and a bare except hid it: a re-assigned viscosity was not caught and the solve ran on the stale one. Constants are compared as they are, and the swallow is gone. - _solve_consistent warm-started V_cons and P_cons through .array, which put a velocity with units into a field without them; it copies .data, the raw variable-to-variable copy inside the non-dimensional boundary, as ddt.py does. - test_0785's refinement metric is 400 (h = 0.05), which refines; 0.1 was an h of 3.2 and refined nothing. test_0992 covers a vector. - CHANGELOG: the two API breaks of the units ruling (#1182, #1081). Underworld development team with AI support from Claude Code
What changes for users: in a model with reference quantities, a bare number for a dimensional parameter (viscosity, diffusivity, …) is refused and must carry units;
evaluaterefuses a field without units beside a dimensional factor;Stokes(mesh)creates its velocity and pressure with units; and a query point far outside the mesh raises instead of returning an extrapolated number.This implements the units contract ruled on 2026-11-13: option A of the design note on #771 and #904, with its sub-decisions. Each change comes with a test that fails on development. Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on development d66c7da merged in.
The contract
evaluateis the dimensional output gatewayND_UNITS_BOUNDARY_CONTRACT.mdcorrected to say soevaluateandglobal_evaluateraiseValueError, naming the unitless fields and the dimensional leavesStokescreates velocity in m/s and pressure in Pa in a units model, and keeps a field that was passedStokesrefuses at construction, naming the missing scalereset_default_modelleaves the scaling flagThe mix (#771, #904)
A field without units stores a non-dimensional number of unknown dimension.
uw.expression(1e24 Pa s), the gateway used to re-dimensionalise the product with the viscosity's scale alone. With reference quantities of 30 km, 1e24 Pa s and 2.5 mm/yr,2 eta E01came back as 1.0e24 labelled Pa s, where 2.64e9 Pa is right.The refusal decides per product, with the dimensional factors reduced together:
T * eta1/eta0(a viscosity contrast) andT * exp(-E/(R*T0))(an Arrhenius factor) are pure numbers besideTand are evaluated: 2.0e-3 forT = 2and a contrast of 1e-3.T * eta1is refused.T + eta1).meshvarreference, derivatives included.uw.expression(..., units="dimensionless"): H1 reported that it drops itsunits=. For a plain constant (uw.expression("d2", 0.5, "…", units="dimensionless")) the units are kept (d2.unitsis dimensionless,has_unitsTrue), so I did not reproduce it. I have not checked other forms.Stokes fields (#844)
Stokes(mesh, velocityField=v)discardedvwhen no pressure field was passed, and the reverse.degree, or it is refused with the degree to pass. Before, a P1 velocity was silently paired into an unstable P1/P1 problem that still converged (review finding 1).degree. A pressure whose degree is notdegree - 1is refused with the degree to pass, and a P0 pressure is pointed to a P1 pressure withdegree=2(P2/P1), sincedegree=1would give the locking P1/P0 pair. A discontinuous pressure passed alone is otherwise taken as given.What changes in a units model, for every class that inherits this constructor (NavierStokes, VE_Stokes and the others):
.arrayof the default velocity and pressure is now dimensional (m/s, Pa)..datais bitwise unchanged, and so is the solve.evaluateof the solver's own stress, with the message naming the unitless field. The fix is to give the passed field units.A kinematic model
Louis ruled on review question 4: a units model with length and time scales but no mass scale is kinematic, and a solver that needs stress is refused.
set_reference_quantities. A kinematic model can still run advection, diffusion or tracer work; only a dynamic solver in it is refused.Points outside the domain (#786, #999)
A point further outside the node bounding box than the mesh's largest cell radius lies in no cell. So the test needs no point location and runs before any evaluation.
global_evaluate_nd's fallback, where a derivative's value depends on np.evaluate. A rank-localevaluatein parallel does not know the global extent without a collective, so there it is checked inglobal_evaluate, which is collective; every rank calls it, a rank with no points contributing none.check_extrapolated=Truereturns the mask instead of raising, as before.There is no new absolute tolerance. The scale is the mesh's own. It separates a wholesale mistake, such as coordinates in metres on a model-unit mesh, from a point just past a curved boundary, which semi-Lagrangian and remesh callers ask about routinely and which is extrapolated as before.
The library's own resampling is exempt. A remap after a mesh move (
remap_var_set,mesh.remesh's transfer) and the refinement transfers ask about moved nodes that can lie more than a cell outside the old geometry, and extrapolate them on purpose. They run inside a private context, entered on every rank, under which the check stands aside. It is decided before any collective, so every rank skips it alike.Dimensionless is a known pure number. A field or constant declared dimensionless (a weakening multiplier, or a history variable with units "dimensionless") is neither a field without units nor a dimensional leaf. So
C0 * seed, withseeddeclared dimensionless, is not refused. A field with no units at all is still refused when mixed.A field inside a named expression is seen by the far-point check: the expression is unwrapped first.
What this does not cover:
evaluaterefuses a far point at np 1 but extrapolates it at np 2 and up. It cannot know the global extent without a collective;global_evaluatechecks at every rank count.T * xorT + xwithTwithout units is not refused.Bare numbers for dimensional parameters (Louis's ruling, option c)
"A bare number used as a viscosity in a unit-aware environment is ambiguous and should be refused."
uw.quantity(value, "<units>")form. Zero and infinity are the same in any units, and are allowed. Nothing changes without reference quantities._pack_constants) or anevaluatefirst reads it. That depends only on the expressions, so every rank decides the same.2*eta, andT*eta1/eta0with the reduction above.ddt.py), and the adjoint's inert scratch assemblers. Every rank enters it alike.#1001
The ruling keeps
reset_default_modelas it is. #1045 already closed the leak between tests in the suite. The docstring now says the flag stays on and how to turn it off.Tests
tests/test_0760_evaluate_units_contract.py, 30 tests, each with its own tier mark. The ones that pass guard behaviour that must not change: a unitless field alone, two dimensions each in its own units, no units without reference quantities, a boundary point answered, the opt-out mask, a solve into a passed velocity, and the no-units baseline.tests/parallel/test_0786_global_evaluate_outside_domain_parallel.py. At np 2 and 4: a far point on one rank raises on every rank, and global_evaluate of a derivative raises at np 2 and up when a point is outside the domain #999's scalar derivative and gradient are refused. The global_evaluate of a derivative raises at np 2 and up when a point is outside the domain #999 cases also run at np 1. All pass here, and the refusal cases fail on development.Existing tests
Why my first paired run missed CI's failures. It covered bands 0000–0499, 01, 05, 062, 07, 08, 1000–1019, 107 and 110. That left out 105x, 114x–115x and 117x, where test_1056, test_1059, test_1148, test_1153, test_1172 and test_1176 live. It was also merged with development d66c7da, while CI merged the newer development with the newer move tests. The run below covers every
tests/test_*.pyand the full np 2 pass, on development c2aa36b merged in.Serial, every
tests/test_*.py, excluding tier C, 6 xdist workers, on c2737bd: 4256 passed, 0 failed, 31 skipped, 18 xfailed, 2 xpassed, 8 errors.test_1086_mmpde_seam_matches_serial. Its spawned reference runs went silent for 120 s at a machine load of about 21. Run alone, the file passes 20 of 20 on this branch and on development.Parallel:
scripts/test.sh --parallel-only --p 2failed onlytest_0035(a bare viscosity in a units model), which is converted at 6e94dc9. It passes at np 2 and 4.CI's failures on the previous head, rerun here: the 8 files pass, 113 tests serial. At np 2 and 4,
test_1172_…_parallel(13 passed),test_1176_…_parallel(3 passed) andtest_0786_…_parallel(4 passed) pass.Existing tests that changed, and why (14 files):
model_units. A new helper,tests/_units_helpers.model_units(value, units), givesvaluemodel units of that dimension, so every number is unchanged. Bare-number assignments in units models becamemodel_units(...)in test_0033, test_0034, test_0812, test_0817, test_0818, test_1056_navier_stokes_supg_api, test_1056_units_slcn_traceback, test_1131, test_1148, test_1153 and test_1450: 36 assignments. The parallel test_0035 gives its viscosity asuw.quantity(1e21, "Pa*s"), which equals its viscosity reference.nondimensional_floatfloor spelling becomesmodel_units(...), and a new test asserts that the bare float is refused.test_estimate_dt_carries_time_units_on_both_bases) and test_1148's units fixture ran NavierStokes in a model with length and time only. A solver that needs stress is refused there, so they now set a mass scale. What they test, time units, is unchanged.uw.quantity(1.0, "m**2/s"), which is 1 in that tutorial's model units.The default viscosity. With the default viscosity, the default Stokes stress used to evaluate as 3.17e-16 labelled 1/s. It is now refused at the first
evaluateor solve that reads it, andtest_the_default_viscosity_is_refused_when_first_readasserts that.Checklist (UW3 Style Charter)
level_*andtier_*markers (S8)Underworld development team with AI support from Claude Code