Skip to content

A raw pint quantity is taken where a uw.quantity is (UNFILED 35) - #1306

Open
lmoresi wants to merge 1 commit into
developmentfrom
fix/raw-pint-quantities-at-setters
Open

lmoresi wants to merge 1 commit into
developmentfrom
fix/raw-pint-quantities-at-setters

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

What changes for users: a raw pint quantity, such as 1e-6 * uw.units.m**2 / uw.units.s (the form the units tutorial wrote), is taken wherever a uw.quantity is: a constitutive parameter, uw.expression, and a body force component.

UNFILED 35, 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 657d984.

The defect

A constitutive parameter took uw.quantity(1e-6, "m**2/s"), but sent the raw pint form to sympy.sympify(float(q)). pint then raised "Cannot convert from 'meter ** 2 / second' to 'dimensionless'", which names neither fix. uw.expression("k", 3.0 * uw.units("W/(m*K)")) and stokes.bodyforce = (0 * uw.units("Pa/m"), -3e4 * uw.units("Pa/m")) failed the same way.

The fix

A small helper, function.quantities.from_raw_pint, turns a raw pint Quantity into a UWQuantity. It is called where a value enters:

  • the constitutive parameter setter;
  • UWexpression's constructor and its .sym setter;
  • each body force component.

From there the raw form takes the same path as a uw.quantity. CLAUDE.md's rule is to accept the forms a user writes and store pint objects. uw.non_dimensionalise and a field's .array already took the raw form, and are tested here so that they stay that way. Boundary values took it already (#1264).

Test

tests/test_0778_raw_pint_quantities.py, 5 tests. Each sets a value in the raw form and checks it against the uw.quantity form:

  • a parameter;
  • the body force;
  • an expression;
  • non_dimensionalise;
  • a field's .array.

On development the first three fail, with the DimensionalityError above.

Regression runs

  • Serial: the bands test_00* and test_05* to test_08*, on 75cb427, 6 xdist workers: 2390 passed, 0 failed.
  • Parallel: scripts/test.sh --parallel-only --p 2 on 75cb427: all 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)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

UNFILED 35: a constitutive parameter took uw.quantity(1e-6, "m**2/s") but
sent 1e-6 * uw.units.m**2 / uw.units.s, the form the units tutorial wrote,
to sympify(float(q)), and pint raised a DimensionalityError naming neither
fix; uw.expression and the body force did the same. A raw pint Quantity is
now converted to a UWQuantity where a value enters: the parameter setter,
UWexpression's constructor and .sym setter, and each body force component.
non_dimensionalise and a field's .array already took the raw form.

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

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.

This branch has not been deployed

No deployments
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