Skip to content

Timestep estimates read model units; timestep setters keep or refuse their input (#891, #1031, #978 part) - #1049

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/estimate-dt-bundle-b
Nov 10, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/estimate-dt-bundle-b

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

The timestep estimates now read the model's units, and the timestep setters either keep what they are given or refuse it. This is bundle B of the issue sweep: #891, #1031, and the estimate_dt part of #978.

Timestep estimates in a model with units (#891)

In a model with reference scales, mesh.X.coords is dimensional. Two estimates read it as model units:

  • The semi-Lagrangian solver's direction-aware crossing time came out the length scale times too long: 2.2e6 on the test annulus. It now reads mesh._coords.
  • The Eulerian solver's first accuracy estimate evaluated the velocity at dimensional points, far outside the mesh, and returned 0.61 of the right step. It now reads the coordinate DM's local nodes.

The Eulerian accuracy estimate also mixed frames when the variables carry units, which is the usual set-up in a model with units. The field range came from u.array (dimensional) and the velocity was taken at its dimensional magnitude, while the gradient and the change rate are non-dimensional. With V in cm/yr and T in K, the first estimate was 5.5e15 times too long, and each one after a solve was 2500 times too long (the temperature scale). The range now comes from u.data, and the velocity is non-dimensionalised.

A model with units and its dimensionless twin now give the same three estimates to 1e-9, with and without units on the variables.

The accuracy estimate on a degree-2 mesh (#978)

The Eulerian accuracy estimate evaluated the velocity at the vertices, while the Clement gradient recovery returns values at the coordinate DM's nodes, edge midpoints included. On a degree-2 mesh it raised ValueError (714 gradient values into 98 vertices). Both now use the coordinate DM's nodes. On degree 2 the estimate equals the P1 estimate to 1e-16. This is the estimate_dt part of #978; its FVM and boundary-normal parts stay open.

Timestep setters (#1031)

The setters of TransientDarcy and Richards, NavierStokesSLCN, the semi-Lagrangian and Eulerian solvers and Diffusion share _nondimensionalise_timestep. It now:

  • returns a UWexpression as it is, so a later E.sym = ... reaches the solve. TransientDarcy unwrapped it, freezing the value.
  • refuses a quantity or expression that is not a time. A length was taken as a timestep.
  • refuses a time quantity or time-valued expression when the model has no reference scales. A bare 600 kyr was taken as 600 model units.
  • reduces a dimensionless quantity before taking its magnitude, as development did: (600 kyr) / (20 Myr) is 0.03.
  • and the history managers do the same (ddt._as_float): NavierStokesSLCN.solve hands them the raw timestep, and on development they read (600 kyr) / (20 Myr) as 30.
  • takes a single-element array as a number. A 0-d array was stored as an array and rewired the kernels on every step.

Tests

tests/test_1153_timestep_estimates_and_setters.py (level_1, tier_b) has 18 cases: the units twin with and without units on the variables, the degree-2 estimate against its analytic value, and the setter cases on TransientDarcy and NavierStokesSLCN. It fails on development. Six mutants, each undoing one fix, are each caught. The 112 timestep-related test files on wombat (serial, not level_3): 923 passed, 0 failed.

Not covered

Reviewed on hyperion before opening (record below).

Underworld development team with AI support from Claude Code

…their input

- #891: the semi-Lagrangian direction-aware crossing time and the Eulerian
  accuracy estimate read mesh coordinates in model units (mesh._coords, and
  the coordinate DM's local array), so a units model and its dimensionless
  twin give the same estimates.
- #978 (estimate_dt part): the Eulerian accuracy estimate evaluates the
  velocity at the coordinate DM's nodes, which match the gradient recovery
  on a degree-2 mesh.
- #1031: _nondimensionalise_timestep keeps a UWexpression live (TransientDarcy
  no longer unwraps it), turns a 0-d array into a float, and refuses a
  non-time quantity or a dimensional time with no reference scales.

test_1153 (level_1, tier_b): 10 pass here, 9 fail on development. The 112
timestep-related test files: 915 passed, 0 failed.

Underworld development team with AI support from Claude Code
… model units

- F1: a dimensionless timestep quantity is reduced before its magnitude is
  taken; (600 kyr) / (20 Myr) was read as 30, not 0.03.
- F2 (#891): the Eulerian accuracy estimate takes the field range from
  u.data and non-dimensionalises the velocity; with V and T carrying units
  it was 5.5e15 times too long before a solve and 2500 times after one.
- F3: a time-valued UWexpression is refused when the model has no
  reference scales, as the bare quantity is.
- A single-element array is a number; the helper's Returns docstring.

test_1153: 17 pass; five mutants, one per fix, each caught. The 112
timestep-related test files: 922 passed, 0 failed.

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

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 10, 2026

Copy link
Copy Markdown
Member Author

Review record, round 1 of 2: b4b5426

This is the pre-PR round, on the branch's first commit. 7d376b8 answers F1–F3. Round 2 follows in the next comment. Paths under runs/ are on hyperion.


Pre-PR adversarial review: bugfix/estimate-dt-bundle-b at b4b5426

One commit (W1, bundle B) on development abe5e0c. Scope: systems/solvers.py,
systems/advection_diffusion_eulerian.py, scripts/test.sh,
tests/test_1153_timestep_estimates_and_setters.py. Reviewed in whole-code
context on hyperion: wt-bB is the branch, wt-devabe is the base. Both are
prebuilt, and neither was rebuilt. Tests ran from git archive copies under
review/arch-*. Probes are in review/probes/, and logs are in review/logs/.
Method: docs/developer/guides/adversarial-review.md.

Verdict

Not ready to merge as it stands. Two findings must be fixed in this branch first.

The three fixes do what they say. Each one is caught by test_1153 (8 mutants,
all caught), and the #891 twin check holds to round-off at np 1 and 2.

The blockers:

Both fixes are a few lines each. F2 is in the same function as the #891 fix.

Answers to the author's questions

Q1. Parallel: is the Eulerian estimate rank-symmetric, and equal to serial?

Rank-symmetric: yes, always. Equal to serial: not always. The difference
was already on the base, and the branch does not change it.

  • probes/ppar.py covered box, annulus and degree-2 box, with T at P1 and P2, and 3
    fields each, 18 cases. At np 1, 2 and 4 the dt is bit-identical on every
    rank and equal to serial. The base (np 1 and 2) gives the same numbers on the
    P1 meshes.

  • probes/ppar2.py used an annulus with cellSize 0.05, T = xy and V = (-y, x).
    The dt was the same on every rank, but it depended on np:

    • np 1: 0.020271;
    • np 2: 0.020152;
    • np 4: 0.020005.

    Base and branch give identical numbers.

  • Cause. The global maximum comes from a ghost vertex (np 2: rank 0,
    argmax_is_ghost: true, rate 0.99213 against 0.98632 over owned vertices).
    The Clement recovery runs on the local DM, which has no overlap cells, so a
    partition-boundary vertex gets a one-sided gradient (error 0.033 against 0.021
    inside). The owner's value is also partial at np 4. The effect is O(h): about
    1.3% here.

  • Ghost nodes at the velocity sample points are harmless. The velocity
    evaluated at ghost coordinates is exact (error ≤ 6e-16), and duplicated nodes
    do not change a MAX reduction.

  • See F4.

Q2. Do any callers use the new refusals?

None found that are refused.

  • Grep. We searched docs/, tests/ and src/ for delta_t =, .solve(timestep=,
    estimate_dt and time quantities. 28 files pass a dimensional time somewhere. Every one also sets reference
    quantities (count of set_reference_quantities|fundamental_scales ≥ 1). The
    src callers (model.py:1863, adjoint.py:668, level_set.py:434,
    free_surface.py:1531) pass the user's dt straight through [read].
  • Doc scripts run on both builds (serial):
    • Tutorial_Thermal_Convection_Units.py, Ex_Convection_Annulus_Recorded.py
      and adjoint/sinker_transcript/forward_sinker_transcript.py run with rc 0 on both
      builds. Notebook 14 (as a script under IPython) also runs with rc 0 on both.
    • Notebook 15 fails on both builds at line 129 (uw.meshing.Annulus
      with km cellSize: DimensionalityError km → dimensionless). That is before
      any timestep, so it is unrelated to this branch.
    • Outputs are identical between builds except one. Ex_Convection_Annulus_Recorded
      (Eulerian, units model, variables without units) starts with dt 0.2748 Myr on
      the branch against 0.1950 Myr on the base
      . That is Units model: estimate_dt's crossing time and first accuracy estimate read dimensional mesh coordinates as model units (dt 3.4x too large, silently) #891's fix showing in a documented
      example. No doc quotes the old numbers (grep for 0.195 / 0.2748).
  • Tests. The tests that use time quantities (test_0814, 1053, 1054, 1056 ×2, 1057, 1064, 1148, 0013, 0009, 0003,
    0005 ×2, 0114) are all in the np 2 run below.
  • Not refused, but now wrong: the unreduced-dimensionless input in F1.

Q3. Should the expression branch also check an expression that holds a quantity?

Yes. What happens now (probes/p1031.py, p1031solve.py, pmisc.py):

  • With no reference scales. uw.expression("dt", uw.quantity(1, "kyr")) is
    accepted and kept live. The solve then treats 1 kyr as 1.0 model time unit:

    • Darcy, Diffusion and NS give the same state as timestep=1.0;
    • the same input as a bare uw.quantity(1, "kyr") is refused.

    So the refusal can be bypassed by wrapping the quantity, and the result is the same silent
    misreading the refusal exists to stop. Composite expressions do the same
    (expression(2 * E(1 kyr)) → 2 [kiloyear], accepted).

  • With reference scales. It is correct. An expression of 600 kyr, later set to 1000 kyr,
    solves identically to timestep=600 kyr, 1000 kyr (difference 7e-16 for Darcy and Diffusion,
    2e-12 for NS).

  • Fix. In the UWexpression branch, when dims == [time] and the model has no
    time scale, raise the same ValueError. The live expression is kept in every
    other case.

  • Eulerian AdvDiffusion. Its setter does float(...) and so cannot take any
    UWexpression ("Cannot convert expression to float", on both builds). That is a
    pre-existing gap and should be documented (F6).

Q4. Issue verdicts

issue verdict evidence
#891 Fixed only for unitless variables; still live with unit-carrying variables (F2). Do not write Closes #891 until F2 is fixed. p891.py, np 1 and 2. Variables without units: every estimate (SLCN da0/da1 and dt_adv, Eulerian accuracy, resolution da0/da1, accuracy after a solve) matches the dimensionless twin with rel 0.0. The base was 3.23× / 2.2e6× / 0.61×. With V in m/s and T in K: Eulerian first estimate rel 5.5e15, after a solve rel 2499. The base was also wrong, by 3.3e15 and 2499.
#978 (estimate_dt part) Fixed by this branch. The computeCellGeometryFVM and boundary_normal parts of #978 are not in this branch and stay live [read: not probed]. Write "Refs #978", not Closes. p978.py, annulus at degree 1 and 2, cellSize 0.1 and 0.05, np 1 and 2. The degree-2 result equals the P1 result to 1e-16. T = x with V = (1, 0): dt = 0.04 against a hand value of 0.04 (rel 6e-15). T = xy with V = (-y, x): 0.02062, 0.02027 against 0.02 (O(h) recovery error, converging). The recovery returns 0 at the edge nodes, so the maximum is over vertices. The base raises ValueError. Base np 4 on degree 2 hung (one rank's reshape error before a collective; the supervisor killed it). On the branch the SL direction-aware estimate on degree 2 equals P1 (box and annulus).
#1031 Fixed by this branch (the four cases in the table), with F1 and F3 as follow-ups. p1031.py: the table across 5 solvers × 14 inputs × with and without scales. p1031solve.py: a changed UWexpression reaches the solve for Darcy, Diffusion and NS (E == F, ≠ C). On the base, Darcy's E == C (frozen); with scales, the base Darcy expression-quantity solved at dt 600 (norm 2e-7 against 4.2). A 0-d array gives a Float with no rewire on every setter. A non-time value is refused (UWQuantity, Pint, and UWexpression). A time with no scales is refused.
#1025 Still live. The branch leaves it on purpose. _advective_diffusive_dt still returns min(dt_diff, dt_adv), with dt_diff = h²/κ_max, for SLCN [read]. Waiting on Louis.

Findings

F1 (high, regression introduced here). solvers.py:250-252, the new
if not value.dimensionality: return float(magnitude) branch takes the
magnitude of an unreduced dimensionless quantity.

  • uw.quantity(600,"kyr") / model.fundamental_scales["time"] (= 0.03) becomes
    9.506e-13.

  • (600 kyr)/(20 Myr) becomes 30.0.

  • Solve comparison against timestep=0.03 (probes/pidiom2.py):

    solver base branch
    Diffusion 5.6e-16 0.55
    SLCN 5.0e-16 0.64
    NS 0.027 0.66
    Darcy 0.55 0.55

    The branch solves at dt 9.5e-13 with no warning.

  • Fix: float(value.to("dimensionless").magnitude) (or to_reduced_units(), as the time path
    already does), and add both inputs to test_1153.

F2 (high, #891 incomplete). advection_diffusion_eulerian.py, estimate_dt and
_advective_rate:

  • The field range comes from self.u.array, which is dimensional (K) when T has units.
  • The velocity is getattr(vel, "magnitude", vel): the dimensional magnitude (m/s) when V has
    units.
  • The gradient (_lvec) and _last_change_rate (u.data) are nondimensional.

Result with V in m/s, T in K, and scales set: the first estimate is 6.7e13 against
0.0121 (×5.5e15), and every estimate after a solve is 30.2 against 0.0121 (×2500).

Fix:

  • read the range from self.u.data, as the change rate does;
  • nondimensionalise the velocity as _centroid_velocities_nd does
    (uw.non_dimensionalise when it has units).

test_1153's twin test should also run with unit-carrying V and T: it passes
today because its variables have no units. NS-Eulerian estimate_dt reads range and rate
from u.array consistently, so it is unaffected [read].

F3 (medium). An expression holding a time quantity with no scales is
accepted and read as model units. This is the Q3 bypass of the new refusal. Fix it in the
UWexpression branch, and add a case to test_1153.

F4 (low, pre-existing, base identical). The Eulerian accuracy estimate
depends on np: 0.020271, 0.020152 and 0.020005 at np 1, 2 and 4 on the annulus at
cellSize 0.05. The cause is a one-sided Clement gradient at partition-boundary vertices
(Q1). It is not a blocker. File it if the estimate should be partition-independent.
Possible fixes: assemble the Clement numerator and weights globally, or recover the gradient on a DM
with overlap.

F5 (low, pre-existing).

  • A 1-element 1-D array (np.array([0.03])) still
    stores an ImmutableDenseNDimArray and rewires on every step (Darcy, NS, SLCN,
    Diffusion). The Eulerian setter raises TypeError for it.
  • With scales set, a negative time quantity (-1 kyr) is accepted as dt -5e-5 by every setter
    except the Eulerian one.

Either is a one-line extension of the same helper.

F6 (low, pre-existing). AdvDiffusion.delta_t does float(...), so a
UWexpression timestep raises TypeError on both builds. The docstring for
_nondimensionalise_timestep now says that a UWexpression is returned "so that a later
E.sym reaches the solver". That is true for every setter except this one. Either say so
or accept the expression.

F7 (nit).

  • The _nondimensionalise_timestep "Returns" section still says
    "otherwise value unchanged". It now also returns a float for 0-d arrays and for
    dimensionless quantities.
  • The trailing try/except still swallows a reduction
    failure and returns the quantity, so a time quantity can still reach the kernels unreduced.
    That is pre-existing, and the Charter-sanctioned comment is present.
  • In test.sh, test_1153 sits before 1151. That is cosmetic. CI reach is fine: it is listed
    in batch 4, and the level_1 and tier_b markers are run there.

Attacks that failed

Regression run at np 2 (branch against base)

We ran 93 files at np 2 on both builds, one mpirun per file under the supervisor
(silence 600 s, lowered to 180 s part-way through, the same for both builds):

  • 86 serial-suite files: the timestep, estimate_dt and transient-solver tests, without level_3;
  • 7 tests/parallel timestep files.

Results (np2-results.txt, logs/np2-*):

  • No regression. Every file has the same per-rank outcome on both builds, with two
    exceptions:
    • test_1153: the branch passes 10 on both ranks. The base fails, then hangs: the degree-2 reshape
      error happens before the allreduce on one rank only, and the supervisor killed it.
    • test_1070_free_surface_plume: the base has 1 failure
      (ring_quadrature_is_exact_in_parallel) and the branch has 0. Both builds hit the silence
      limit, so we read this as timing, not code.
  • Summed over ranks: branch 562 passed, 56 failed, 8 skipped; base 557, 56, 8.
    The difference is test_1153 and test_1070. The 56 failures are the same tests on both builds.
  • 16 files hit the supervisor on both builds. Most of the serial suite is not
    written for MPI (for example test_0017, 0075, 0114, 1052, 1054, 1064, 1100, 1101, 1105).
    They are equally hung on base and branch.

Merge conditions

What we could not test

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review record, round 2 of 2: 7d376b8

Verdict: ready to merge. F1, F2 and F3 are fixed. The branch was rebuilt and re-run on hyperion with round 1's own probes.

F1, the unreduced dimensionless timestep (probes/pidiom2.py, serial). uw.quantity(600,"kyr")/time_scale now solves like timestep=0.03:

solver round 1 (b4b5426) 7d376b8
Diffusion 0.55 5.6e-16
SLCN 0.64 5.0e-16
Darcy 0.55 5.6e-16
NavierStokesSLCN 0.66 0.027
  • The NavierStokesSLCN setter now stores exactly 0.03 for the float, for 600 kyr / time_scale and for 600 kyr, without rewiring (round2/ns_dt.py).
  • The remaining 0.027 comes from solve(timestep=600 kyr / time_scale). Development abe5e0c shows the same 0.027 (round 1), so it is pre-existing and outside this PR. The cause is not traced; a likely candidate is the solve-path timestep reaching the semi-Lagrangian trace-back without reduction.
  • solve(timestep=600 kyr) matches to 2.8e-16. Worth a follow-up issue.

F2, the Eulerian estimate with unit-carrying variables (probes/p891.py 1, np 1 and np 2). Every estimate, before and after a solve, equals the no-units twin with relative difference 0.0, on every rank. Round 1 had 5.5e15× and 2500×.

F3. Covered by the author's new tests on Darcy and NS. It was not re-probed separately here.

Tests. test_1153: 17 passed at np 1 and at np 2.

Underworld development team with AI support from Claude Code

NavierStokesSLCN.solve hands its raw timestep to the characteristic trace
and to the DDt managers, whose _as_float went through non_dimensionalise
and left a dimensionless ratio unreduced: (600 kyr) / (20 Myr) was 30,
600 kyr over the time scale 1.2e-16. _as_float now reduces a
dimensionless quantity first, as the solvers' setter helper does (F1).

test_1153: two Navier-Stokes steps with the ratio equal two with 0.03
(one step from rest cannot show it: the trace-back is empty and the
first-order coefficients do not depend on the step); the mutant is caught
by the solve comparison alone. 18 pass; the 112 timestep-related test
files: 923 passed, 0 failed.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review record, round 3: aef4cf1

Verdict: ready to merge. aef4cf1 fixes the NavierStokesSLCN solve-path residual that round 2 left open. It is a 6-line change in ddt._as_float, plus a test.

Rebuilt and re-run on hyperion with round 1's probe, probes/pidiom2.py. The ratio uw.quantity(600,"kyr")/time_scale solves like timestep=0.03:

solver 7d376b8 (round 2) aef4cf1
NavierStokesSLCN 0.027 2.8e-16
Diffusion 5.6e-16 5.6e-16
SLCN 5.0e-16 5.0e-16
Darcy 5.6e-16 5.6e-16

test_1153: 18 passed at np 1 and at np 2.

The author's mutant (the reduction undone) is caught by the solve comparison and by the _as_float check, per the author; it was not re-run here.

_as_float feeds every DDt manager. The author's 112-file run gives 923 passed. Here, the four solver families above give identical answers to round 2 apart from the NS fix.

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.

2 participants