Repository navigation
Conversation
…onal argument to a transcendental function - The Stokes base refuses a velocity of degree 1 on a simplex mesh, from degree=1 or a passed P1 velocity: P1/P0 locks and P1/P1 is unstable. The message points to degree=2 (P2/P1). Decided from the mesh's agreed isSimplex. Q1/P0 on quadrilaterals, P2/P0 on simplices and Darcy are unaffected. Approved by Louis as a change to solver behaviour. - In a model with reference quantities, evaluate refuses exp, log, the trigonometric and hyperbolic functions and erf of an argument whose leaves, reduced together, carry a dimension, and a power with such an exponent: exp(eta1) is refused, exp(eta1/eta0) and exp(-E/(R*T0)) are not. Underworld development team with AI support from Claude Code
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)) (H1 is the session that reviews pull requests and runs the parallel tests.) Verdict: changes requested. The Stokes refusal is correct and safe across ranks. The transcendental refusal has one regression: a correctly dimensionless coordinate argument such as Findings, by severity1. A dimensionless coordinate argument is refused, and a bare coordinate is accepted (regression)
Units model with length 30 km, a T field in K,
The repository's own units-model tests write A possible fix: refuse a transcendental argument only when it is dimensional both as written and with coordinates replaced. That keeps the model-units coordinate convention ( 2. Functions the refusal does not coverThese are evaluated without complaint on a 1e21 Pa s argument:
Two of them are used in the code base:
Testing against sympy's base classes would cover the families and future members: Not gaps:
Unrelated to this PR, and present on development too: 3. The refusal applies at
|
…y rule, refused at the setter too (H1's review of #1197) - Coordinates keep their length in a function argument's reduction, so sin(pi*x/W) and exp(x/L) are dimensionless and accepted. - Every applied sympy function needs a dimensionless argument (erfc, asinh, atanh, …), except a short list that passes units through (Abs, Min, Max, Piecewise, sign, Heaviside, …) and a field's own function; a power keeps the exponent rule. - The check runs where a parameter is set, as well as at evaluate, so a viscosity of eta0*exp(eta1) is refused before a solve runs with it. - The verdict is cached per expression. - The P1 refusal comes before any field is created, and before the #844 degree messages, so a P1 velocity is pointed to degree=2. Underworld development team with AI support from Claude Code
…ex-and-transcendental
…e fix Following the ruling that a coordinate inside exp, sin or log is refused in a model with reference quantities, the refusal now names the coordinate and shows the fix: divide it by a length, e.g. sin(pi*x/W) with W an expression in km. A dimensional argument without a coordinate is pointed to a reference of the same dimension. Three tests that wrote sin(pi*x) or exp(-x**2) in a units model now divide by one model length, from the new tests/_units_helpers.model_length(), which returns 1 without reference quantities. The fault_friction example (.py and notebook) builds its fault geometry and observation weights from x/D and y/D, with D the model depth as an expression. The units tutorials 14 and 15 and the thermal-convection units example already use dimensionless ratios. Underworld development team with AI support from Claude Code
…e shows the fix 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 at cca957b: changes requested. The coordinate-length rule follows the ruling, and the function coverage is complete. The P1 refusal is correct and collective, and the cost is small. What blocks the merge is the cache: the verdict is cached per expression, so it goes stale when a named expression's value is reassigned. It then refuses an expression that is now dimensionless and accepts one that is now dimensional. Two medium findings and two lows follow. The PR was built fresh from cca957b (the Against the earlier review
Without reference quantities, all 52 probe cases give the same values on the PR as on development: nothing new is refused. With units on mesh variables, Findings
Confirmed correct
What was run
Not run:
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
…very solve H1's review of #1197 at cca957b: - The verdict was cached per expression, and a named expression keeps its identity when its value is reassigned, so the verdict went stale both ways. The walk now runs on every call; only the units reduction of each argument is cached, keyed on the argument and the current value and units of every named expression in it, in a bounded LRU (512). - atan2 is a function of a ratio: its two arguments must share a dimension. The library's polar, spherical and geographic angles are built from it. - The body force is checked when set, and every Integral, CellWiseIntegral and BdIntegral when made. Every solve checks the solver's inputs (body force, source, boundary values, constitutive parameters), so a value reassigned inside an expression after it was set is caught too. - The coordinate hint looks only at coordinates outside a field's own function (exp(T) points to T/T0), and a power's hint shows the power. Underworld development team with AI support from Claude Code
…ex-and-transcendental
The body force is now checked when set and at every solve, so four tests that wrote sin(pi*x) in a units model were refused: test_0033, test_0745, test_1131's units-model box and the parallel test_0035. Each divides by one model length (model_length(), or an expression of the reference length in the parallel file), so every argument keeps its value and no assertion moves. 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)) Recheck at 883f1c5: changes requested. Every finding of the previous review is fixed, and each fix was confirmed with the earlier probes. One new problem blocks the merge, found while building the Arrhenius cost case. When a sum contains a mesh variable's dimensionless ratio, the argument's units come out as kelvin. The new refusal then rejects standard dimensionless forms: The Against the previous review (cca957b)
Findings
Noted, not from this PR: on both development and the PR, that viscosity evaluates to NaN in this units model ( The converted testsThe seven conversions across What was run
Not run:
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
…hes refused H1's review of #1197 at 883f1c5. compute_expression_units returned None ("unknown") for a sum of dimensionless terms, and get_units then took the units of the first field in it: T/T0 - 1, E/(R*T) - E/(R*T0) and T/T0 + x/W came back in kelvin, so the normalised Arrhenius factor was refused while E*(1/T - 1/T0)/R was accepted. A sum now has the dimension its terms share, a sum of dimensionless terms is dimensionless, a plain number may sit beside a dimensional term, and terms of different dimensions raise MismatchedSumError naming them. A product with no dimensional factor and a factor of unknown units (2*u, u a field without units) is unknown, not dimensionless; the old sum rule hid that. The whole verdict of the function-argument check is cached on the expression and the state of its named expressions: a repeat solve with a 40-term viscosity pays 1.2 ms for it. Underworld development team with AI support from Claude Code
…ex-and-transcendental
The first fix also changed two answers the tests rely on: a field without units reads as a pure number (test_0850's T/x), and a sum of such terms has no units (test_0851's strain rate of a unitless velocity, test_0760's plain viscoplastic stress). A dimensionless term now counts only when it carries units that cancel (a field or named expression with units, a coordinate), so those keep their development answers, and the product rule is as it was. T/T0 - 1, E/(R*T) - E/(R*T0) and T/T0 + x/W are still dimensionless, and two terms that carry units of different dimensions are still refused. 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)) Second recheck at 7355f46: changes requested. The sum fix works when every term of the sum carries units.
The PR's own compiled sources are unchanged since 883f1c5. The merge of development brought in a changed Against the previous recheck (883f1c5)
Examples and docs that build a units modelEvery notebook and script under
The
One new refusal, in the geographic tutorial. Fourteen files already fail on development, for reasons unrelated to this PR, and fail at the same statement on the PR. The Spiegelman benchmark times out on both. Those files exercise only the code before their failure point. Findings
Also noted, on both builds and not changed by this PR:
Unitless modelsA probe with no reference quantities evaluates 14 expressions: sums, transcendental functions of sums, and atan2. It then runs a Stokes solve with the viscosity The new testsThe six new tests in
The new tests use no temperature reference, so they pass around the 1000x defect. What was run
Not run:
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
…used when set H1's review of #1197 at 7355f46: - A sum with a plain named parameter or a field without units beside a dimensionless ratio (T/T0 + k, beta*C - gamma*T/T0) still returned None, and get_units took the first field's kelvin. A term that carries no units is now a pure number beside the ratio, and get_units no longer falls back to a field's units for a sum: a sum of terms with no units has none. - A sum of terms of different dimensions outside any function (a viscosity eta0 + T) is refused where it is set and at the solve, as at evaluate. - The geographic tutorial subtracted a dimensionless quantity (the centre in model lengths) from a coordinate. The centre is now given its length, and the Gaussian divides by the dimensional radius: the run gives development's velocities. The message says to give such a quantity its units, and prints a negated constant as its number. - The check's state key no longer formats each named expression's units: they follow from its value. Underworld development team with AI support from Claude Code
…ex-and-transcendental
test_0033 and the parallel test_0035 measured u_1*sin(pi*x/L) + u_0*y: a velocity plus a velocity times a length, which a units model now refuses as a sum of different dimensions where the Integral is made. The second term is u_0*y/L, with L one model length (1 without reference quantities), so every value is unchanged. 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)) Third recheck at 5bac99b: changes requested. All five findings from the second recheck are fixed. A plain parameter or a field without units beside a ratio is now a pure number. The geographic tutorial runs and gives development's output. One new false refusal blocks the merge. It sits in the sum rule:
The PR's compiled sources changed. The merge of development brought in two changed Against the second recheck (7355f46)
The questions asked of this headThe units of sums (33-sum probe and a 28-sum fallback probe, against development). Every sum that development evaluated correctly gives the same value on the PR. The values differ only in four cases:
With U a field without units,
The adjoint tests. The old misfit, The geographic example. Editing it is acceptable: it runs and its output matches development. But users with the old idiom will hit the refusal (new finding 2). They see:
That says how to fix the coordinate case. Examples and docs (short form: changes only)The 26 files from the second recheck were run again on both builds, with the same copies, edits and 900 s cap. Two changed:
The other 24 files behave as in the second recheck:
Findings
Also noted, unchanged from development:
Unitless modelsThe same probe as before, with no reference quantities, was run on both builds. Its The new testsOn the PR, the four new items in
Run against development, all four fail, as they should. The corrected What was run
Not run:
The runs shared the machine with other jobs. Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
…form The parallel review of #1197 at 5bac99b: - Min, Max and Piecewise read as pure numbers, so a viscosity floor, cap or layer beside a viscosity was refused as a mismatched sum. They now take the units their branches share (refused if those disagree), Abs and its kin keep their argument's, and sign and Heaviside are pure numbers. The rule is one helper, shared with a sum. - A dimensionless constant in any form (a number, uw.quantity(0.5, "dimensionless"), a non-dimensionalised value) beside a dimensional term is read in model units; two terms that depend on the model and carry different dimensions are still refused. The hint names the units to give. - A mismatched sum inside a named expression's value was swallowed by get_units's lookup of the value, so a sum made mismatched by a later reassignment ran at the solve. It is refused there now. (A sum of constants only is folded into one constant when set, and does not follow its parts at all.) - Session codes are gone from test_0760's comments. Underworld development team with AI support from Claude Code
…ex-and-transcendental # Conflicts: # docs/examples/fluid_mechanics/advanced/Ex_Stokes_Cartesian_SolNL.py
The yield-stress floor is max(tau_y, tau_y_min); with Max now keeping its arguments' units, evaluate returns the effective viscosity in Pa s, as the dimensional gateway should, where the test read a bare model-unit number that came from Max dropping them. It reads Pa s and divides by eta_0 for its closed forms; the projected values, in a field without units, are unchanged. Underworld development team with AI support from Claude Code
What changes for users:
degree=2.exp,logorsinof an argument that carries units is refused: atevaluate, when a constitutive parameter or the body force is set, when an integral is made, and at every solve.sin(pi*x)must be writtensin(pi*x/W)withWa length.This is the follow-up to #1182. Every part follows Louis's "more willing to raise errors":
Runs were on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).
P1 velocity on simplices
P1/P0 locks, and P1/P1 is unstable. On simplices,
degree=1is in Louis's words "almost an incomplete specification".SNES_Stokes_SaddlePt), before any field is created. This covers Stokes, NavierStokes, VE_Stokes and Stokes_Constrained, whether the velocity comes fromdegree=1or is passed in as a P1 field.degree=2(P2/P1).isSimplex, which all ranks agree on at construction, so every rank refuses together.Function arguments must be dimensionless
exp(eta1)has no meaning. In a model with reference quantities these are now refused:By rule, not by a list. Any applied sympy function needs a dimensionless argument:
exp,log, the trigonometric and hyperbolic functions and their inverses,erfanderfc.Exempt: functions that pass units through:
Abs,Min,Max,Piecewise,sign,Heaviside,floor,ceiling,re,im,conjugate,DiracDelta, and mesh-variable functions.Powers: the exponent must be dimensionless.
Functions of a ratio:
atan2's two arguments must share a dimension, not each be dimensionless. The library's polar, spherical and geographic angles are built from it, somesh.CoordinateSystem.R[1]on an annulus evaluates in a units model.Coordinates are lengths.
How dimension is judged: Units contract: evaluate refuses mixed units and far points; Stokes fields carry units (#771, #904, #881, #786, #844, #1001) #1182's reduction decides.
exp(eta1/eta0),exp(-E/(R*T0))andsin(pi*x/W)are dimensionless and accepted.Where it is checked:
evaluate;Integral,CellWiseIntegralorBdIntegralis made;f, essential and natural boundary values, and constitutive parameters. A named expression reassigned after it was set (k.sym = 1e21 Pa sinsideeta0*exp(k)) is caught there.Exempt work: library work inside the internal context, as for Units contract: evaluate refuses mixed units and far points; Stokes fields carry units (#771, #904, #881, #786, #844, #1001) #1182's refusals.
Cost: the verdict is cached on the expression and the current value and units of every named expression in it, and so is the units reduction of each argument, in bounded LRUs of 512 entries. A reassigned value is a new key. On a 40-term viscosity the check costs:
The units of a sum (
compute_expression_units, behinduw.get_units). A sum of dimensionless terms returnedNone, meaning unknown, andget_unitsthen took the units of the first field in it. SoT/T0 - 1,E/(R*T) - E/(R*T0)andT/T0 + x/Wcame back in kelvin: the normalised Arrhenius factor was refused, whileE*(1/T - 1/T0)/Rwas accepted. This is on development too.T/T0 + kandbeta*C - gamma*T/T0are dimensionless.test_0850,test_0851).get_unitsno longer falls back to the first field's units for a sum.uw.quantity(0.5, "dimensionless"), a non-dimensionalised value), may sit beside a dimensional term, and is read in model units.MismatchedSumError, naming them. The hint names the units to give.Functions that pass units through:
Min,MaxandPiecewisetake the units their branches share, and are refused if those disagree;Absand its kin keep their argument's units;signandHeavisideare pure numbers.So viscosity floors, caps and layers, such as
eta_min + Min(eta1*exp(...), eta_max)andeta0 + Piecewise((eta1, x > W/2), (eta0, True)), keep the units of a viscosity. One helper does this for sums and for these functions. The message prints a constant as its number, and says to give a dimensionless quantity its units. This check also runs where an expression is set and at the solve, outside functions too, so a viscosityeta0 + Tis refused when set. A sum made mismatched by a later reassignment is refused at the solve:get_unitshad swallowed the error inside a named expression's value. A sum of constants only is folded into one constant when it is set, on development too, so it never follows its parts.The message names the fix.
x/W, with an exampleW = uw.expression("W", uw.quantity(1000, "km"), "width").2**(... N.x/W ...).T/T0,eta1/eta0,E/(R*T0)). A field's own coordinates do not count, soexp(T)is pointed toT/T0.Tests
tests/test_0762_stokes_p1_on_simplices_refused.py, 9 tests.degree=1alone; a passed P1 velocity.tests/test_0760_evaluate_units_contract.py, 42 new tests:exp,log,sinandtanhof a viscosity;erfc,asinhandatanhof one, which tests the rule;2**eta1;sin(pi*x)refused, with the message naming the coordinate and showingx/W;eta1/eta0,E/(R*T0)andx/W;atan2(y, x)is an angle, andatan2(y, eta1)is refused;Integralis refused when it is made;exp(T)namesT/T0, not a coordinate;2**xshows the power;T/T0 + kandbeta*C - gamma*T/T0evaluate to the hand value,eta0 + Tis refused at the setter, and the message prints a negated constant as its number;exp(Max(T, T0)/T0 - 1)gives its value;Minof different dimensions is refused;T/T0 - 1,E/(R T) - E/(R T0),T/T0 + x/WandE (1/T - 1/T0)/Rare dimensionless arguments; the two normalised Arrhenius forms both evaluate to the hand value, 25.0722; andT + Wis refused, naming both terms.E/Rwas not divided by it, so the activation term was 1000 times too large. That was fixed separately by A dimension with no reference has the SI base unit as its scale (E/R met the temperature reference) #1284, now in development. These tests use a model without a temperature reference.Existing tests and examples that changed
tests/_units_helpers.model_length(), which is 1 without reference quantities. Every argument keeps its value, and no assertion changed.test_1148_changing_timestep_keeps_the_snes:sin(pi*x);test_0770_mesh_move_in_a_units_model: a Gaussian inr;test_1057_ddt_transport_plugin: a Gaussian inx,y;test_0033_adjoint_gradients_in_a_units_modeland the paralleltest_0035_adjoint_datum_sensitivity_parallel:sin(pi*x)in the body force, traction and misfit. The parallel file has no helper, so it writes the length as an expression of its reference;test_0745_two_models_in_one_processandtest_1131_rotated_nullspace_from_mesh's units-model box:sin(pi*x)in the body force.test_1059_yield_stress_min_unitsread the evaluated viscosity as a bare model-unit number. That number came fromMaxdropping the units. It now reads Pa s and divides byeta_0, and its closed forms are unchanged.test_0033and the paralleltest_0035measuredu_1*sin(pi*x/L) + u_0*y. That is a velocity plus a velocity times a length, now refused as a mismatched sum where theIntegralis made. The second term isu_0*y/L, which has the same value.docs/examples/tutorials/geographic/Ex_Geographic_Meshes.pysubtracted the anomaly centre, a dimensionless quantity in model lengths, from the coordinates, and divided by a non-dimensional radius insideexp. The centre is now given its length (float(c) * L_0, withL_0the 1000 km length reference), and the Gaussian divides by the dimensional radius. The run gives development's velocities: min -3.42e+02, max +2.09e+03, mean -1.14e+01, maximum upwelling at lon 140.6°, lat -33.6°, depth 230 km.docs/examples/adjoint/fault_segments/fault_friction.pyand.ipynb. These build their fault geometry and observation weights fromx/Dandy/D, withDthe model depth as an expression.evaluate: at (0.3, 0.65) the position along the fault is 0.3, the distance to it is 0.35, and the point weight is 1.0000007.Ex_Stokes_Cartesian_SolNL.pybuilt a P1 velocity with a P0 pressure on a simplex box. It is now P2/P1. A search of the other examples found no P1 velocity in a Stokes solver on simplices.Regression runs
tests/test_*.pyexcept tier C, 6 xdist workers, on 179dfa2 (development 1e10c63 merged in). 4547 passed, 12 failed:test_1059_yield_stress_min_units(9): it read the viscosity as a model-unit number that came fromMaxdropping its units. Changed (199955d), it gives 11 passed.test_1086_mmpde_seam_matches_serial(3): its spawned runs timed out under load. Run alone on 199955d it gives 20 passed.scripts/test.sh --parallel-only --p 2on 199955d: all passed.scripts/check_test_coverage.pypasses.Checklist (UW3 Style Charter)
level_*andtier_*markers (S8)isSimplex; np 2 pass clean (S11)Underworld development team with AI support from Claude Code