Skip to content

A quantity boundary value is non-dimensionalised in a units model (#1238) - #1264

Merged
lmoresi merged 4 commits into
developmentfrom
fix/bc-quantity-model-units
Nov 20, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
fix/bc-quantity-model-units

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What changes for users: in a model with reference quantities, a boundary condition given as a uw.quantity (or a pint Quantity) is applied in model units. Before, it could be applied at its SI magnitude: a wall at 5 mm/yr against a 10 mm/yr reference got 1.58e-10 where 0.5 is right, with no warning.

Closes #1238. Found by the units desk (a Claude session). The development values in the table were measured on development's add_condition. Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on development c902390.

The defect, more narrowly than the issue put it

add_condition replaced a quantity by to_base_units().magnitude, its SI number. An older path then divides plain numbers by the field's scaling_coefficient. For a velocity on a field the solver made itself, which carries units, that division happened to give the model value. It is wrong in three cases:

case recorded on development right
Stokes with fields passed in without units (the issue's example) 1.58e-10 0.5
a scalar field without units, e.g. Poisson's u 5000 for 5 km 0.5
a traction, 1 MPa on a natural condition 3.16e15: 1e6 Pa divided by the velocity scale 0.0316: 1 MPa over the stress scale

The fix

  • In a model with reference quantities: a quantity in a boundary condition is non-dimensionalised, as the body force setter already does, in a tuple or as a single value, for essential and natural conditions. These entries are not divided again by the older path.
  • A quantity of the wrong dimension is refused. On a field with units, the value of an essential condition must have the field's dimension; otherwise it is refused, naming both. With the conversion fixed, 1 MPa on a velocity wall would otherwise have become a believable 0.0316, where development's 3e15 was plainly wrong (the parallel review). A quantity on a field without units, the case A uw.quantity boundary condition is applied at its SI magnitude in a model with reference quantities #1238 was filed for, and a plain number are accepted as before. The field's dimension is read from its unit itself, so an offset unit (degC) works. The message names the condition and the component.
  • Without reference quantities: the SI magnitude is the value, as before.
  • In a dimension the model has no reference for (a temperature with only length, mass and time given): the field runs at scaling coefficient 1, in SI, and warns when made. So the SI magnitude is kept there too. test_0812 relies on this. The UNFILED item 17 PR gives such a dimension its SI base unit as the scale, and after it this branch's fallback gives the same answer by the same route.

Test

tests/test_0774_boundary_condition_quantities_in_a_units_model.py, 14 tests:

  • the recorded value, against the model value worked out by hand, for an essential uw.quantity and a pint quantity, a natural traction, and a single value on a Poisson field;
  • the wall's velocity after a solve, on the solver's own fields and on fields passed in without units;
  • without reference quantities, the SI magnitude;
  • a dimension with no reference, in SI;
  • 1 MPa on a velocity wall refused, naming both dimensions, and m/s accepted;
  • on a degC field, 1300 K, 1026.85 degC and 0 degC accepted, and 5 km refused;
  • a plain number on a field without units, accepted.

On development 4 fail: the fields passed without units, the scalar field, the traction, and the wrong-dimension refusal. The cases that development already got right pass on both.

Regression runs

  • Serial: every tests/test_*.py except tier C, 6 xdist workers, on 529f1765: 4431 passed and 3 failed, all in test_0812, the dimension with no reference. The fallback above was then added (82df5f0), and test_0774 and test_0812 give 12 passed.
  • Parallel: scripts/test.sh --parallel-only --p 2 on 82df5f0: all passed.
  • After the dimension check (a9ebf94):
    • the units and Stokes bands (test_07*, test_08*, test_100* to test_102*): 1906 passed, 0 failed;
    • the files that pass a quantity to a boundary condition: 49 passed;
    • after the offset-unit fix (1c98a1b): test_0774 and test_0812, 18 passed.

Checklist (UW3 Style Charter)

  • Followed the Style Charter over the surrounding code (S2)
  • No drive-by refactors (S9)
  • Regression test written first, with level_* and tier_* markers (S8)
  • No hedging names, no commented-out code (S3, S4)
  • No new exception swallow (S4); the one except ValueError names the case it handles
  • Parallel safety: the conversion is the same on every rank; np 2 pass clean (S11)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

)

add_condition replaced a uw.quantity or pint Quantity by its SI magnitude and
applied that number in model units. An older path then divided plain numbers
by the field's scaling_coefficient, which happened to give the model value for
a velocity on a field the solver made; with fields passed in without units, a
scalar field without units, or a traction (divided by the velocity scale), the
value was wrong, 3e9 off for 5 mm/yr against a 10 mm/yr reference, with no
warning.

In a model with reference quantities a quantity is now non-dimensionalised, as
the body force is, and is not divided again. Without reference quantities the
SI magnitude is still the value.

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

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 20, 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.)

At 82df5f0: ready to merge on green from this review.

The fix does what the PR says. A quantity in a boundary condition now lands in model units in every case we tried: essential and natural, in a tuple and as a single value, uw.quantity and pint, on fields with and without units, and on Stokes, Poisson, AdvDiffusion and Projection. Plain numbers, sympy expressions and models without reference quantities are unchanged. Plain numbers are bitwise unchanged. The conversion is the same on every rank, and an empty rank does not change it. One medium finding: a quantity of the wrong dimension is still accepted with no error, and it now gives a plausible O(1) number. Development also accepted it with no error. It does not block this PR.

Method

  • Head 82df5f0 was built fresh, and its compiled modules are newer than the build start. The base is the merge base c902390 (development). It comes from an existing build of exactly that commit, with a clean tree, and its installed Python matches its sources. Every run prints underworld3.__file__.
  • Probes read the recorded value (essential_bcs[-1].fn / natural_bcs[-1].fn_f) and the value on the wall after a solve. They ran on head and base and were checked against values worked out by hand. References: length 10 km, viscosity 1e21 Pa s, velocity 10 mm/yr, and temperature 1300 K where a temperature is used. Hand values: 5 mm/yr is 0.5. The stress scale is eta V / L = 3.169e7 Pa, so 1 MPa is 0.031558. 5 km is 0.5. 1026.85 degC = 1300 K is 1.0, and 0 degC is 273.15/1300 = 0.210115.
  • All runs used 4 cores, with other jobs on the machine.

Results: recorded value (serial)

"Solver's fields" means the solver made its own fields, which carry units (velocity scale 3.169e-10 m/s). "Passed fields" means fields passed in without units (scale 1).

case development head right
Stokes essential (uw.quantity(5,"mm/yr"), None), solver's fields 0.49999999999999195 0.5 0.5
same, passed fields (the issue's case) 1.5844e-10 0.5 0.5
same as pint 5*uw.units("mm/yr"), both field kinds 0.5 / 1.5844e-10 0.5 / 0.5 0.5
5 km/Myr, 0.5 cm/yr, 1.5844e-10 m/s, passed fields 1.5844e-10 0.5 0.5
single value uw.quantity(5,"mm/yr"), passed fields 1.5844e-10 0.5 0.5
Stokes natural (0, 1 MPa), solver's fields 3.156e15 0.031558 0.031558
same, passed fields; pint form the same 1.0e6 0.031558 0.031558
natural with a quantity in each component (1 MPa, 2 MPa) 3.16e15, 6.31e15 0.031558, 0.063115 same
Poisson essential uw.quantity(5,"km"), u without units 5000 0.5 0.5
Poisson essential 5 km, field with units km 0.49999999999998573 0.5 0.5
Poisson natural 5 km (record only) 5000 0.5 0.5
Projection essential 5 km 5000 0.5 0.5
AdvDiff T (units K): 1300 K, 1026.85 degC, pint Quantity(1026.85,"degC"), 1300 delta_degC 1.0000000000000007 1.0 1.0
AdvDiff T: 0 degC 0.21011538461538473 0.2101153846153846 0.210115

Plain numbers and sympy entries: development and head are identical to the last digit in every case. Some examples: (0.5, 0.0) gives 1577879999.9999747 on the solver's fields and 0.5 on passed fields. A plain traction 1e6 gives 3.156e15 or 1e6. 0.5*yy stays symbolic. Poisson plain 0.5 gives 0.5. AdvDiff plain 1300.0 gives 1.0.

Mixed tuples: the quantity is converted and the plain number keeps its old meaning. (q, 0.25) gives 0.5 and 788939999.99 on the solver's fields, and 0.5 and 0.25 on passed fields. (None, q) and (sympy.Float(0.25), q) behave the same way, component by component. The free component stays free.

Without reference quantities, the full probe (81 cases) gives identical output on development and head.

Results: after a solve (serial)

case development head
issue reproduction as written (domain_depth, convergence_rate), quantity wall vx 1.5844e-10 0.5
same, as uw.expression 0.5 0.5
Stokes wall 5 mm/yr, solver's fields 0.5 0.5
Stokes wall 5 mm/yr, passed fields 1.5844e-10 0.5
Stokes 1 MPa shear traction, max abs v 5.55e14 0.00555276 (uw.expression of the same quantity: 0.00555276)
Poisson essential 5 km, wall u 5000 0.5
Poisson natural flux uw.quantity(1e-7,"m/s"), min u -3.17e-7 -1000 (uw.expression of the same quantity: -1000 on both)
AdvDiff wall 1026.85 degC, wall T 1 1
Projection wall 5 km 5000 0.5
uw.expression of 5 mm/yr, changed to 8 mm/yr between solves 0.5 then 0.8 0.5 then 0.8

Head now agrees with the uw.expression route in every case where both can be used. An expression is still kept symbolic and converted at solve time. So a time-dependent value changed between solves still takes effect. That path is unchanged.

Results: parallel

The probe uses a gmsh box (cellSize 0.1) and solves four problems. Stokes with passed fields has a 5 mm/yr wall and a 0.1 MPa top traction. Stokes with the solver's fields has a 5 km/Myr wall. Poisson has a 5 km wall. AdvDiff has degC walls with a temperature reference. Layouts: np 1; np 2 with horizontal bands; np 3 with an empty rank (cells 121/121/0, checked on each rank). All ranks recorded the same value in every case.

quantity head np1 head np2 band head np3 empty rank dev np1 / np2 / np3
Stokes left vx (passed fields) 0.5 0.5 0.5 1.5844e-10 at all np
Stokes vrms (passed fields) 0.4367590893 0.4367576167 0.4367576167 3310.36 / 3310.39 / 3310.39
Stokes vrms, solver's fields (evaluated in m/s) 1.384006e-10 1.384001e-10 1.384001e-10 3310.36 / 3310.39 / 3310.39
Poisson wall u / integral of u 0.5 / 0.2500002796 0.5 / 0.2500001737 0.5 / 0.2500001737 5000 / 2500.0028 or 2500.0017
AdvDiff wall T / integral of T 1 / 72.85885681 1 / 72.85885681 1 / 72.85885681 1 / 72.85885681 at all np

np 2 and np 3 agree to all digits printed. np 1 differs from them by 3e-6 relative, and development shows the same np 1 vs np 2 difference. On head, the two Stokes variants agree with each other: 0.43676 × 3.1688e-10 m/s = 1.384e-10 m/s. On development they did not.

Regression runs

  • Serial, 73 files with at most 4 xdist workers: the units, quantity, scaling and boundary-condition tests (essential, natural, Nitsche, flux, body force), plus test_0774, test_0810 and test_0812. Head: 574 passed, 7 skipped, 12 xfailed. Development (72 files; test_0774 is new): 566 passed, 7 skipped, 12 xfailed.
  • test_0774 run against the development build: 3 failed, 5 passed. These are the three failures the PR names: fields passed without units, the natural quantity, and the single quantity on a Poisson field.
  • Parallel, np 2, head: eleven units and boundary files under tests/parallel (0765, 0766, 0768, 0770, 0787, 0992, 1065, both 1069 files, 1086, 0856). 22 + 31 passed, 2 skipped.
  • test_0774, test_0810 and test_0812 under mpirun at np 2 and np 3, head: 17 passed, 1 failed. The failure is test_0812::test_poisson_check_bc_values, and test_0812 with test_0810 fails the same way on development at np 2 and np 3 (see 5).
  • Tutorials, run as scripts on both builds. 13 (scaling with physical units) gives identical printed results. The only change is the recorded top velocity: 0.999999999999990 on development, 1.0 on head. 14 (time stepping with units, K walls) gives identical T, profile and recorded values. 15 (thermal convection with units) stops on both builds while building the mesh (Cannot convert from 'kilometer' to 'dimensionless'), before any boundary condition is set. So it was not compared.

Findings

  1. Medium: a quantity of the wrong dimension is accepted with no error, and it now gives a plausible number. On a velocity wall, uw.quantity(1, "MPa") records 0.0316 and uw.quantity(5, "km") records 0.5. Development also took both with no error, but gave values that were obviously wrong (3.2e15 and 1.6e13 on the solver's fields; 1e6 and 5000 on passed fields). The new number looks reasonable, so the mistake is now harder to see. When the field carries units, an essential condition could compare the quantity's dimension with the field's and refuse a mismatch. A natural condition would need the flux dimension, so that is harder. This could be a follow-up issue; it does not block this PR.

  2. Low: the new path is gated on model.has_units(), but the older division is gated on uw.is_nondimensional_scaling_active(). With reference quantities set and scaling switched off (uw.use_nondimensional_scaling(False)), head gives 0.5 for a 5 mm/yr wall. Development gives 1.58e-10, and the uw.expression route gives 5. This is an unusual setup, and the expression route is itself odd there. One sentence in the code comment on which gate is meant would help.

  3. Low, existing before this PR: a plain number still means two different things. On a field with units it is read as SI and divided by the scaling coefficient, so (0.5, 0.0) on the solver's velocity gives 1.58e9. On a field without units it is read in model units. A plain traction is divided by the velocity scale, so a plain 0.0316 traction records 9.97e7. With this PR, a tuple can hold a quantity in model units next to a plain number read as SI: (q, 0.25) gives (0.5, 7.9e8). The PR rightly leaves plain numbers alone. The natural-condition division by the velocity scale looks like the same defect as A uw.quantity boundary condition is applied at its SI magnitude in a model with reference quantities #1238 for plain numbers, and it is worth an issue.

  4. Low, existing before this PR: a single uw.expression (not in a tuple) is refused with ValueError: Unknown quantity type: <class '...UWexpression'>, on both builds. After this PR, that elif branch can only be reached by such objects. A message saying to put the value in a tuple, or accepting it, would help.

  5. Low, existing before this PR: test_0812::test_poisson_check_bc_values fails under mpirun at np 2 and np 3 on development and on head. It reads the bottom value as 949.98 (expected 300) and the top as 949.98 (expected 1600). The test looks serial-only by nature, and the PR does not change the result, so this is noted only.

  6. Low, cosmetic: one comment line at line 5430 of the .pyx is 131 characters long ("...the SI magnitude is the value. Entries converted here are in their final form and are not").

Code reading: there is no rank-dependent branch. The conversion depends only on the model's reference quantities, and the runs above confirm this. The one except ValueError wraps only get_scale_for_dimensionality. That function raises ValueError only for a missing dimension or missing references, and the comment names that case. The index set in_model_units uses the tuple position. That matches the scaling loop, including tuples with None and the single-value form. A quantity in each component of a vector works; we did not try a tensor condition.

Not run

  • Tensor-valued conditions, and a quantity inside sympy.Matrix([...]). The latter raises SympifyError on both builds, so there is no change.
  • add_nitsche_bc with a quantity. It does not go through add_condition.
  • The full test suite, and parallel runs at np 4.
  • Tutorial 15, past mesh construction (it fails there on both builds).
  • Docs examples that set plain-number boundary conditions in a units model (fault_friction, the thermal convection examples). Their conditions are plain numbers or expressions, which this PR does not change.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

H1's review of #1264: with the conversion fixed, 1 MPa on a velocity wall
became a believable 0.0316 where development's 3e15 was plainly wrong. On a
field with units the value of an essential condition must have the field's
dimension; otherwise it is refused, naming both. A quantity on a field
without units (the case #1238 was filed for) and a pure number are accepted
as before.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 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.)

At a9ebf94: changes requested.

This is a short re-check of the one new commit since our review at 82df5f0. The check works as described for velocity, Poisson, vector projection and temperature fields in K. A quantity of the wrong dimension is refused at add time, the error names both dimensions, and every rank raises the same error. One new problem needs a one-line fix first. On a field whose units are degC, every quantity in an essential condition is now refused with a pint OffsetUnitCalculusError, including correct values such as 1300 K and 0 degC. At 82df5f0 those values were converted correctly and the model solved.

Earlier findings, then and now

finding at 82df5f0 at a9ebf94
1. Medium: wrong dimension accepted with a believable value 1 MPa on velocity gives 0.0316; 5 km gives 0.5 Field with units (the solver's own fields, or passed fields with units): refused, with both dimensions named. Field without units: still accepted, with the same values (see 2 below).
2. Low: has_units() gate vs is_nondimensional_scaling_active() open unchanged
3. Low: a plain number means two different things (existing before this PR) open unchanged
4. Low: a single uw.expression is refused (existing before this PR) open unchanged
5. Low: test_0812::test_poisson_check_bc_values fails under mpirun (existing before this PR) open unchanged
6. Low: 131-character comment line line 5430 still line 5430

Runs

Head a9ebf94 was built fresh. All 12 compiled modules are newer than the build start, and every probe prints underworld3.__file__. We compared it with the 82df5f0 build from our review. References: 10 km, 1e21 Pa s, 10 mm/yr, and 1300 K where a temperature is used. All runs used 4 cores, with other jobs on the machine.

Recorded value of an essential condition:

case 82df5f0 a9ebf94
velocity, solver's fields: (1 MPa, None), (5 km, None), (1 K, None), a single 1 MPa, pint 1 MPa 0.0316 / 0.5 / 3.16e9 / 0.0316 / 0.0316 refused, both dimensions named
velocity, passed fields with units m/s: the same five the same as above refused
velocity, passed fields without units: the same five 0.0316 / 0.5 / 1.0 / 0.0316 / 0.0316 unchanged
(5 mm/yr, 1 MPa), (None, 1 MPa), (0.25, 1 MPa) on a field with units 1 MPa gives 0.0316 refused; the message names the value 1 MPa
vector projection, field in m/s: (5 mm/yr, 1 MPa) and (None, 5 km) accepted (0.5, 0.0316) and (free, 0.5) refused
T in K: 5 mm/yr, 1 MPa 0.5, 0.0316 refused
Poisson, u in km or m: 1 Pa, 5 mm/yr 3.16e-8, 0.5 refused
Poisson, u dimensionless: 5 km 0.5 refused
dimensionless 0.5 on a field with units (velocity, or u in km) 0.5 refused (see 4 below)
compatible units on velocity: 5 mm/yr, 5 km/Myr, 0.5 cm/yr, 1.5844e-10 m/s, pint; all three field kinds 0.5 (1.5844e-10 m/s gives 0.5000000000000001) identical
T in K: 1300 K, 1026.85 degC, pint degC, 1300 delta_degC / 0 degC 1.0 / 0.2101153846153846 identical
T in degC: 1300 K, 1026.85 degC, 0 degC, 1300 delta_degC, pint degC 1.0, 1.0, 0.210115, 1.0, 1.0 OffsetUnitCalculusError for all of them
Poisson, u in km: 5 km, 5000 m 0.5 identical
field without units: 1 Pa on Poisson u; 5 mm/yr and 1 MPa on T 3.16e-8; 0.5, 0.0316 unchanged (accepted)
plain numbers on any field as in our review identical
  • Natural conditions: all 18 Stokes traction cases are identical on the two builds (three field kinds; 1 MPa, (1 MPa, 2 MPa), wrong dimensions 5 mm/yr, 5 km and 1 K, and plain 1e6). So are the Poisson and AdvDiff natural cases. A wrong dimension in a natural condition is still accepted: 5 mm/yr as a traction records 0.5.
  • After a refusal, the solver is unchanged: no condition is added. A correct condition added next solves to a wall vx of 0.5.
  • The full probe from our review, with and without reference quantities, gives identical output to 82df5f0 except three newly refused cases. These are 1 MPa, 5 km and a dimensionless 0.5 on the solver's velocity. Without reference quantities, the solver's fields have no units, so nothing is refused there.
  • Parallel: a gmsh box at np 2 (horizontal bands, 121/121 cells) and at np 3 with an empty rank (121/121/0). (1 MPa, 0) and (None, 5 km) on Stokes, and 5 mm/yr on T in K, are refused on every rank with the same message. No condition is recorded. A collective call right after the refusal completes. The following solve gives a wall vx of 0.5 on all ranks. 1026.85 degC on T in K records 1.0 on all ranks. At 82df5f0 all of these were accepted on every rank.
  • test_0774: 10 passed on head. Against the 82df5f0 build, 1 failed: test_a_quantity_of_the_wrong_dimension_is_refused_on_a_field_with_units. The other new test, a plain number on a field without units, passes on both builds, as a guard should.
  • Serial, the same 73 units and boundary-condition files as in our review, with at most 4 workers: 576 passed, 7 skipped, 12 xfailed. That is 574 at 82df5f0, plus the two new tests.
  • Parallel at np 2, the same eleven units and boundary files: 22 + 31 passed, 2 skipped, the same as at 82df5f0.

Code reading. The check runs inside add_condition, before any collective call. It depends only on the field's units attribute and the quantity, and both are the same on every rank. A field "has units" when self.Unknowns.u.units is not None. Every caller passes f_id = 0, so the pressure branch is never reached. The check runs whether or not the model has reference quantities.

Findings

  1. High: a field whose units are degC now refuses every quantity in an essential condition. The check builds the field's dimension as (1 * uw.units(str(field_units))).dimensionality. For an offset unit, pint refuses to multiply 1 * degC and raises OffsetUnitCalculusError: Ambiguous operation with offset unit (degree_Celsius). So 1300 K, 1026.85 degC, 0 degC and 1300 delta_degC are all refused, and so are wrong dimensions, with the same pint error instead of the new message. At 82df5f0, a T field in degC (scale 1300) recorded 1.0 for 1026.85 degC, and a solve gave 1.0 on the wall. uw.units(str(field_units)).dimensionality, read from the unit with no multiplication, gives [temperature] for degC on both builds. That looks like the fix. A test on a degC field would guard it. Plain numbers on a degC field are unaffected (1300.0 records 1.0000000000000007 on both builds).

  2. Low: the case from the original issue, fields passed without units, still accepts a wrong dimension with a believable number. On velocity, 1 MPa gives 0.0316, 5 km gives 0.5, and 1 K gives 1.0 (with a temperature reference). The same holds on a T or Poisson field without units. The author scoped the check to fields that carry units, and with no units on the field there is nothing to check against. This is worth a sentence in the docstring, or a follow-up issue. Natural conditions are also unchanged, as scoped.

  3. Low, cosmetic: the message always begins add_dirichlet_bc on '<label>', even when the call was add_essential_bc. For a tuple, it names the value (the value 1 [megapascal]) but not its position. Adding "component 1" would help with (1 MPa, 1 MPa)-style tuples.

  4. Low, a behaviour change to note: a dimensionless quantity, such as uw.quantity(0.5, "dimensionless"), on a field with units is now refused. At 82df5f0 it gave 0.5. This follows from the rule and seems right, but a user relying on it will see a new error.

Not run

  • A field in degF or any other offset unit besides degC. We expect the same as finding 1.
  • Tensor-valued conditions, and add_nitsche_bc (it does not go through add_condition).
  • Parallel runs at np 4, the full test suite, and the tutorials (the commit does not touch the paths they use with plain numbers or expressions).
  • The fix suggested in finding 1 was not built or tested. We checked only that Unit.dimensionality returns [temperature] for degC.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

…self

The parallel review of #1264: on a field in degC every quantity in an
essential condition raised pint's OffsetUnitCalculusError, the right ones
too, because the check multiplied the field's unit by 1. It now reads the
unit's own dimensionality. The message names the condition (essential,
Dirichlet) and the component when there are several, and the docstring says
a field without units is not checked.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 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.)

At 1c98a1b: ready to merge on green from this review.

This is a short re-check of the one new commit since a9ebf94. The check now takes the field's dimension from the unit itself. On a field in degC (and in degF), every correct temperature is accepted and records the same value as at 82df5f0, before the check was added. A wrong dimension is refused with both dimensions named. Everything else from our a9ebf94 re-check is unchanged except the message text. Two small notes are below. Neither blocks the merge.

Earlier findings, then and now

finding at a9ebf94 at 1c98a1b
1. High: a degC field refuses every quantity with pint OffsetUnitCalculusError 1300 K, 1026.85 degC, 0 degC and 1300 delta_degC all refused Fixed. They record 1.0, 1.0, 0.2101153846153846 and 1.0, as at 82df5f0; pint degC records 1.0. km, mm/yr and MPa are refused with both dimensions named.
2. Low: fields without units still unchecked open The author kept this scope and documented it (see 2 below). Behaviour unchanged.
3. Low: message always says add_dirichlet_bc and does not name the component open Fixed. The message now reads essential (Dirichlet) condition on '<label>', which is right for both add_essential_bc and add_dirichlet_bc. For a tuple or list it adds component N (0-based): (0, 1 MPa) gives component 1, and (1 MPa, 2 MPa) gives component 0, the first bad entry. A single quantity gets no component.
4. Low: a dimensionless quantity on a field with units is now refused noted unchanged, as expected
Earlier Low: 131-character comment line line 5430 now line 5433

Runs

Head 1c98a1b was built fresh. All 12 compiled modules are newer than the build start, and every run prints underworld3.__file__. References: 10 km, 1e21 Pa s, 10 mm/yr and 1300 K. All runs used 4 cores, with other jobs on the machine.

  • Offset-unit fields, compared with 82df5f0. On T fields in degC, degF and K, we added 1300 K, 1026.85 degC, 0 degC, 1300 delta_degC, pint 1026.85 degC, 1880.33 degF, 32 degF and a plain 1300.0. They record 1.0, 1.0, 0.2101153846153846, 1.0, 1.0, 1.0, 0.21011538461538465 and 1.0000000000000007 on all three fields, identical to 82df5f0. 5 km, 5 mm/yr and 1 MPa are refused on all three fields, and the message names both dimensions (for example [length] and degree_Celsius, [temperature]). At 82df5f0 those were accepted as 0.5, 0.5 and 0.0316. A solve on the degC field with 1026.85 degC or 1300 K on the wall gives 1.0 there, and so does the degF field with 1880.33 degF.
  • Our full a9ebf94 probe (124 cases), compared case by case once the message prefix is normalised. Only seven cases differ, all on the degC T field. 1300 K, 1026.85 degC, 0 degC, 1300 delta_degC and pint degC are now accepted with the values above. 5 mm/yr and 1 MPa are now refused with the new message, where before they failed with the pint error. Every other case gives the same values and the same refusals, and natural conditions are unchanged.
  • Parallel, gmsh box, at np 2 (horizontal bands, 121/121 cells) and np 3 with an empty rank (121/121/0). (1 MPa, 0) and (None, 5 km) on Stokes, 5 mm/yr on T in K, and 5 km on T in degC are refused on every rank with the same message, and no condition is recorded. A collective call right after the refusals completes. On every rank, 1300 K and 0 degC on the degC field record 1.0 and 0.2101153846153846, and 1026.85 degC on T in K records 1.0. The solves give a wall vx of 0.5 and a degC wall T of 1.0. All 20 gathered cases agree across ranks.
  • test_0774: 14 passed on head. The file from head, run against the a9ebf94 build, has 4 failures: all four new cases (test_a_temperature_on_a_celsius_field_is_accepted for K, degC and 0 degC, and test_a_length_on_a_celsius_field_is_refused). The other 10 pass.
  • Serial, the same 73 units and boundary-condition files, with at most 4 workers: 580 passed, 7 skipped, 12 xfailed. That is 576 at a9ebf94 plus the four new tests.

Code reading. The diff is the one-line dimension change, the component index (only when conds is a tuple or list), the new message and the docstring sentence. The check still runs before any collective call and depends only on the field's units and the quantity.

Findings

  1. Low: the new degC tests check only that the condition is accepted. They do not check the recorded value. Asserting 1.0 for 1300 K and 1026.85 degC, and 0.2101 for 0 degC, would also guard the offset conversion. The probes show the values are right today.
  2. Low, cosmetic: the sentence about unitless fields is in the add_condition docstring, between the label and components entries, so it reads as part of label. It is not in the add_dirichlet_bc or add_essential_bc docstrings, which are the ones users read. Moving it under conds in those two would make it visible.

Not run

  • Parallel test files at np 2, np 4, the full test suite and the tutorials. The commit changes only the dimension lookup and the message, and the earlier np 2 file runs showed no change.
  • Tensor-valued conditions, and add_nitsche_bc (it does not go through add_condition).
  • Offset units other than degC and degF.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit eed486f into development Nov 20, 2026
10 checks passed
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