Skip to content

A dimension with no reference has the SI base unit as its scale (E/R met the temperature reference) - #1284

Merged
lmoresi merged 2 commits into
developmentfrom
fix/unreferenced-dimension-scale
Nov 20, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
fix/unreferenced-dimension-scale

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What changes for users: in a model with reference quantities, a constant whose units include a dimension the model has no reference for has the right model value. An activation energy in J/mol over a gas constant in J/(mol K) is the clearest case. With a temperature reference, the normalised Arrhenius factor exp(E/(R*T) - E/(R*T0)) was 1000 times too large in its exponent and overflowed to NaN; it now evaluates to its value. Without a temperature reference a quantity with amount of substance changes too: in the parallel review's model, 300 kJ/mol had the model value 0.994 and now has 0.00244, its energy over the model's energy scale.

The UNFILED item 17 (a NaN in exp(A*T0/T)*exp(-A)), found and fixed by the units desk (a Claude session). Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH), on development e7e02b9.

The defect

Model.get_scale_for_dimensionality builds a scale from the fundamental scales: length, mass, time, temperature. It raised for a dimension with none, which is amount of substance always, and temperature when no temperature reference is given. Every caller caught the error and fell back to a raw number:

  • UWQuantity.data, a named constant's model value. It returned the value in the quantity's own units. So E = 3e5 J/mol gave 3e5 and R = 8.314 J/(mol K) gave 8.314. Their ratio, 36084, is in kelvin, and it never met the temperature reference. Against 1000 K, E/(R*T) came out 25774 where 25.77 is right. The same energy written as 300 kJ/mol gave 300.
  • The relabelling of an Integral. It returned the model-unit number labelled with physical units.
  • non_dimensionalise of a unit-aware array. It warned and returned the array unchanged.
  • dimensionalise. It refused.

The fix

In get_scale_for_dimensionality, a fundamental dimension with no reference takes its SI base unit as the scale: one mole, one kelvin. That is the scale a field of that dimension already runs at: a field in K with no temperature reference warns at creation and uses a scaling coefficient of 1. A mole cancels in every ratio with a meaning. A temperature with no reference stays in kelvin, as before. Every caller listed above goes through this one lookup, so each is fixed by it. A dimension outside the SI base set still raises.

Test

tests/test_0775_unreferenced_dimension_scales.py, 8 tests, each against the hand value. All 8 fail on development:

  • E.data / R.data is E/R in units of the 1000 K reference;
  • 300 kJ/mol has the same model value as 3e5 J/mol;
  • the normalised Arrhenius factor in three forms, exp(E/(R T) - E/(R T0)), exp(E (1/T - 1/T0)/R) and exp(A T0/T) exp(-A) with A = E/(R T0): each gives 25.0722 at T = 1400 K, T0 = 1600 K, through evaluate;
  • the same factor through an Integral, which is the JIT's constants path;
  • with no temperature reference, a kelvin constant is its value in kelvin;
  • an energy per mole round-trips through dimensionalise.

Regression runs

  • Serial: every tests/test_*.py except tier C, 6 xdist workers, on d1eaf50: 4462 passed, and 3 failed, all test_1086_mmpde_seam_matches_serial. Its spawned runs go silent under load, a known artefact.
  • Parallel: scripts/test.sh --parallel-only --p 2 on d1eaf50: all passed.

Relation to open PRs

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)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

The model's scale for a dimensionality was built from its fundamental scales,
and a fundamental dimension without one (amount of substance; a temperature
with no temperature reference) raised. Every caller that caught the error fell
back to a raw number: UWQuantity.data returned the value in its own units, so
an activation energy of 3e5 J/mol and a gas constant of 8.314 J/(mol K) gave
E/R = 36084, in kelvin, never divided by the temperature reference. With
1000 K, E/(R T) was 1000 times too large and the normalised Arrhenius factor
overflowed to NaN; 300 kJ/mol gave 300. The integral's relabelling, the
non-dimensionalisation of a unit-aware array and dimensionalise all went
through the same lookup.

Such a dimension now has one SI base unit as its scale (one mole; one kelvin
with no temperature reference), the scale a field of that dimension already
runs at. test_0775 checks each against the hand value, through evaluate, an
Integral and a round trip; all 8 fail on development.

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

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

#1284 at d1eaf50: a dimension with no reference gets its SI base unit as the scale

Verdict at d1eaf50: ready to merge on green from this review. The fix does what it says. With a 1000 K temperature reference, both Arrhenius forms used to give NaN and now match the hand value to 3e-16. An Arrhenius-viscosity Stokes solve used to stop with NaN/Inf and now converges, with the same answer at np 1, np 2 and np 3 with an empty rank. Nothing that ran on development changed: 139 units test files, 14 parallel units files and 26 docs examples. Finding 1 (Medium) is a regression in evaluate for expressions that carry a mole and contain a field. The cause is an existing defect in evaluate, and it can be a follow-up. Findings 2 to 5 are wording and scope.

What users see differently

  • With a temperature reference: an energy per mole meets the temperature reference. E/(R*T) and exp(E/(R*T) - E/(R*T0)) give their values. E in J/mol used to give NaN (or 0 through an Integral). E in kJ/mol happened to be right, because 1 kJ against 1000 K cancels.
  • With no temperature reference (length, mass, time only): this changes more than the PR body says. Five things change:
    • 300 kJ/mol in an Arrhenius factor was wrong on development (0.994 instead of 0.00244) and is now right. J/mol was already right.
    • A temperature field can now be set from a quantity (T.array[...] = uw.quantity(1400, "K")). On development that raised. The values are unchanged: kelvin at coefficient 1.
    • Constants that mix kelvin with a referenced dimension have new model values: 2 K/Myr gives 24 (time scale about 12 Myr), not 2.
    • J/mol and J/(mol K) constants have model values around 1e-18 and 1e-22, where development returned the raw number (finding 1).
    • Dirichlet temperature values, solves and BC values are unchanged.
  • Partial reference sets (temperature only, or length and temperature): length, mass and time with no reference now take 1 m, 1 kg and 1 s. On development they raised (finding 3).
  • Amount of substance, current and luminosity take 1 mol, 1 A and 1 cd, unless a reference gives a scale. A concentration reference still gives substance its own scale.

Method

Results

Arrhenius at T = 1200 K, T0 = 1000 K, through evaluate (E = 3e5 J/mol, R = 8.314 J/(mol K); hand value 0.0024444079)

reference set form development head
length, viscosity, velocity, 1000 K exp(E/(R T) - E/(R T0)) NaN 0.0024444079 (rel 3e-16)
same exp(E (1/T - 1/T0)/R) NaN 0.0024444079
same Integral of the factor 0 0.0024444079
same E/R [K] 36083714 (1000x) 36083.714
same E/(R T0) [1] 36083.714 (1000x) 36.083714
same, E = 300 kJ/mol both forms 0.0024444079 0.0024444079
length, viscosity, velocity (no temperature ref) both forms, J/mol 0.0024444079 0.0024444079
same, E = 300 kJ/mol both forms 0.9940041 (wrong) 0.0024444079
temperature only; length + temperature both forms, J/mol NaN 0.0024444079

E = 1e5 J/mol (hand 0.13470733) shows the same pattern.

Scales and model values (L = 30 km, viscosity 1e24 Pa s, velocity 2.5 mm/yr; "+T" adds 1000 K)

quantity development, +T head, +T development, no T head, no T
scale [mol] raises 1 mol raises 1 mol
scale [J/mol] raises 7.12982e22 raises 7.12982e22
scale [J/(mol K)] raises 7.12982e19 raises 7.12982e22
quantity(3e5, "J/mol").data 300000 (own units) 4.20768e-18 300000 4.20768e-18
quantity(300, "kJ/mol").data 300 4.20768e-18 300 4.20768e-18
quantity(8.314, "J/(mol K)").data 8.314 1.166088e-19 8.314 1.166088e-22
quantity(2, "K/Myr").data 0.024 0.024 2 24
quantity(1600, "K").data 1.6 1.6 1600 1600
J/mol round trip through dimensionalise raises 3e5 raises 3e5

Solves

case development head
Stokes, viscosity 1e24 Pa s * exp(E/(R T) - E/(R T0)), quad box 12x12, np 1 DIVERGED_FUNCTION_NANORINF converged; ∫|v|² 6.95204598655e-38, ∫exp-factor 14892.054 (hand 14827.6, P1 T)
same, np 2 NaN/Inf ∫|v|² 6.9520460184e-38 (5e-10 from np 1), ∫exp-factor identical
gmsh box, np 1 — ∫|v|² 7.02127101678e-38
gmsh box, np 3 with rank 2 holding no cells NaN/Inf ∫|v|² 7.02127144811e-38 (6e-9, solver tolerance 1e-8)
Poisson, T in K, no temperature reference, Dirichlet 300/1600 K 300 / 950.0 / 1600 identical
same with a 1000 K reference identical identical

At np 2 and np 3, every rank, including the empty one, printed the same J/mol scale (7.1298197581567495e22) and the same model values for E and R.

Tests

run development head
139 units-related test files, not tier C (3 or 2 xdist workers) 1677 passed, 15 skipped, 16 xfailed, 2 xpassed 1685 passed (the 8 new), same skips
test_0775 (new) 8 failed 8 passed
test_0812 (dimension with no reference) 4 passed 4 passed, file unchanged
11 parallel units pytest files + test_1070, np 2 all passed except test_1097 same
ptest_0010, ptest_0202 (script style), np 2 PASS / OK PASS / OK
26 docs examples that build a units model 11 exit 0, 14 exit 1, 1 timeout identical exit codes and output
  • test_0812 still asserts T = 300 K at the bottom and 1600 K at the top (±1 K), and dT/dy = 1300 K per model length (1%).
  • test_1097's fourth test went silent for over 60 s on rank 0 and the supervisor stopped it. It did this on both builds.
  • The examples' output differs only in timestamps, paths and timings. The one numerical difference is a dt in Ex_Convection_Annulus_Recorded at 2e-14 relative. That is run-to-run noise: three development runs gave …025.875, …025.355 and …025.23, and head gave …025.23. The failing examples fail the same way on both builds, for reasons that have nothing to do with units (API drift, a swarm error, an X display).

#1264 at a9ebf94, with and without this PR (Poisson, top at 1600 K, Neumann flux of 2.6 K·m/s at the bottom, κ = 1 m²/s; hand value 300 K at the bottom)

build 1000 K reference no temperature reference
development, or this PR alone -648399 K -648399 K
#1264 alone 300.01 K -648399 K (fallback: SI magnitude)
#1264 + this PR 300.01 K 300.01 K

With this PR's model.py, #1264's tests (test_0774, test_0812) and test_0775 give 22 passed. #1264 alone gives 14 passed, with the 8 of test_0775 failing.

Findings

  1. Medium: evaluate is wrong for an expression that has a mole in its units and contains a field. In a model with no temperature reference, this was right on development and is wrong on head.
    • evaluate(R*T) at T = 1200 K gives 27801 J/mol on head. The answer is 9976.8, which development gave. With a 1000 K reference, development gave 9.9768 and head gives 27801, so it is wrong on both builds there.
    • A J/mol field set to 3e5 evaluates to 317824 at (0.5, 0.5) and 301426 at (0.1, 0.2).
    • The cause is an existing defect in evaluate. It adds an absolute 1e-18·x·y in model units. With no units at all, evaluate(1e-19*T) is 3.08 times too large at (0.5, 0.5), 1.17 at (0.1, 0.2) and 1.52 at (0.25, 0.25), which is exactly 1e-18·x·y. This looks like the independent_of_N term (vanishing = 1e-18, times x·y) in coordinates.py. Integral and the solvers are exact.
    • This PR exposes the defect because a mole scale of 1 mol, against an energy scale of 7e22 J, puts a J/mol value near 1e-18.
    • Dimensionless ratios such as E/(R T) and constant-only expressions are unaffected. No test or example hit this.
    • Two options: fix evaluate's ε term as a separate issue (preferred: it is wrong without units too), or choose the substance scale so that 1 J/mol is the energy-per-mole scale. Mole cancels in every meaningful ratio, so any scale is valid, and this one keeps activation energies at their SI size.
  2. Medium: the field-creation warning no longer says what happens.
    • It says the variable "will use scaling_coefficient=1.0". On head that holds only when every dimension of the field is unreferenced.
    • With length, mass and time references, a field in K/s runs at 2.64e-15 K/s per model unit, and W/(m K) at 6276.
    • With length and temperature only, m/s runs at 30000 and J/mol at 9e8.
    • A J/mol field in the common setup gives no warning, yet holds 4.2e-18.
    • On development these fields raised on assignment, so the text was never tested against what happens. Suggested wording: "a dimension with no reference uses its SI base unit (1 K, 1 mol, …)".
  3. Low: the scope is wider than the code comment and PR body describe.
    • _SI_BASE_UNITS also covers length, mass, time, current and luminosity. With temperature as the only reference, 3 km now has model value 3000 and 5 cm/yr has 1.58e-9 (SI). On development non-dimensionalising them raised, and .data returned the number in its own units.
    • This is consistent with how such a field runs, and fields still warn. The comment should name every dimension it covers, or be limited to substance and temperature if that is what's meant.
  4. Low: some PR body claims need correcting. They are about the text, not the code.
  5. Low: test notes.
    • test_an_energy_per_mole_round_trips has a hedge: q.dimensionality if hasattr(q, "dimensionality") else None.
    • The no-temperature-reference kJ/mol Arrhenius case, which was wrong on development, is not tested.
    • Separately, and not from this PR: adding concentration=2 mol/m³ to the reference set changes the length scale from 30 km to 2.28 m on both builds.

What was run and not run

  • Run:
    • Arrhenius, scale and model-value probes on development and head, across six reference sets.
    • An Arrhenius-viscosity Stokes solve at np 1 and np 2 (quad box) and at np 1 and np 3 (gmsh box, one rank with no cells, via a shell partition).
    • Poisson BC probes, Dirichlet and Neumann, with and without a temperature reference, on four builds.
    • The units-related serial tests on both builds, and the new test on development.
    • A quantity boundary value is non-dimensionalised in a units model (#1238) #1264's tests with and without this PR.
    • The parallel units files at np 2.
    • The 26 docs examples on both builds, with an extra development rerun to check noise.
  • Not run:
    • The full serial suite. Only the 139 units-related files ran.
    • np 3 or np 4 for the parallel test files.
    • The parallel test files other than the units ones.
    • test_1097's last test to completion. The 60 s silence limit stopped it on both builds.
    • Notebook execution through Jupyter. The examples ran as converted .py copies.
    • The Spiegelman benchmark example to completion. It hit the 900 s limit on both builds.

Underworld development team with AI support from Claude Code

The parallel review of #1284: the field-creation warning for a dimension
without a reference said the variable "will use scaling_coefficient=1.0",
which is no longer what happens. It now says the dimension takes its SI base
unit, and gives the variable's model unit (2.64e-15 K/s for K/s in a model
with no temperature reference). The _SI_BASE_UNITS comment covers every
fundamental dimension, and test_0775 drops a hasattr hedge.

Underworld development team with AI support from Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants