Skip to content

The Eulerian split advection corrects every component of a symmetric tensor; the commit checks its frozen source - #1248

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/eulerian-split-advection-tensor
Nov 20, 2026
Merged

lmoresi merged 1 commit into
developmentfrom
bugfix/eulerian-split-advection-tensor

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

This is the follow-up to #1231, from its second-desk review. No issue was filed, so this body is the report.

1. The Eulerian split advection on a symmetric tensor

Eulerian._apply_split_advection corrects psi_star[0] -= dt (V . grad) psi component by component. For a 2×2 symmetric tensor it walked two data columns with the flat entries psi[0], psi[1] (xx, xy). A 2×2 symmetric tensor stores three components, laid out xx, yy, xy. So the yy column took xy's correction, and xy took none.

This was found by reading the code and confirmed by test_1109. The reach is a plain Eulerian history, with V_fn set and split advection, on a symmetric tensor. EulerianSUPG, which the grid stress history uses, transports through _transport_history and was not affected.

The correction now walks the stored components through the variable's own layout, as EulerianSUPG._transport_history does. A symmetric tensor contributes its upper triangle. Scalars and vectors keep their previous flat columns unchanged.

Test: test_1109 compares each stored column with the correction a scalar Eulerian history of that component alone takes: $x^2$, $xy$, $y^2$ under a rigid rotation, P2. They agree to 3e-8; the bound is 1e-6, and a misplaced column is off by about 0.1. Before the fix the test fails at (0, 1), where it measured that the yy column carries xy's correction.

2. The commit's frozen source

#1231's review noted two latent gaps in the snapshot substitution. Neither changes a result today; both are now made safe.

  • .subs does not reach psi_star[0] inside a UWexpression (at yield the viscosity reads E_eff_inv_II, which contains it), so that occurrence reads the history live. This is harmless only while the snapshot equals psi_star[0] at the commit. commit_flux_to_history now checks exactly that, collectively (MAX of the difference), and raises if anything wrote the history after the refresh. test_1109 checks the refusal.
  • The nodal history's record fallback (an L2 projection, taken when psi_fn cannot be evaluated pointwise) read the snapshot as last refreshed: after the previous trace-back, not the last commit. It now refreshes the snapshot before its projection. The path is reached only when the pointwise evaluation of psi_fn fails. Stokes passes store_result=False, and with store_result=True a Stokes history evaluates pointwise and does not fall back; the parallel review had to force the fallback to reach it.

The three TODO(BUG) notes #1231 added are gone. The tracking entry was item 11 in issue-sweep/UNFILED-FINDINGS.md of the campaigns repository.

Tests

Measured by H7 (the stress-history desk, a Claude session on a 96-thread Linux workstation: Intel Xeon Gold 6240R, MPICH).

test_1109 passes, and fails on the code before this PR. The 30 stress-history and viscoelastic files (the second-desk set plus test_1109), on 4 xdist workers: 240 passed, 1 failed.

The one failure predates this PR. test_1061, the forward history on Waters and King to t 6.5, level 3, reads 0.52651 against its pinned 0.5185. Development at 4ab522a, before #1231, gives exactly the same value (0.526506539677034). The pin predates a later change on development, which I have not bisected.

Checklist (UW3 Style Charter)

  • Style Charter followed (S2); no drive-by changes (S9)
  • Regression test written first, with level_1 and tier_a markers; it fails before the fix (S8)
  • No hedging names, commented-out code or exception swallows (S3, S4)
  • Parallel: the commit check is a collective MAX (S11)
  • No coordinates identify entities (S12); no dependency changes
  • AI-assisted

Underworld development team with AI support from Claude Code

…metric tensor; the commit checks its frozen source

Eulerian._apply_split_advection walked a 2x2 symmetric tensor as two flat entries: the yy
column took xy's correction and xy took none. It now walks the stored components through
the variable's layout, as EulerianSUPG._transport_history does (test_1109, against a scalar
history of each component).

The commit projection's snapshot substitution does not reach psi_star[0] inside a wrapped
expression; that is harmless only while the snapshot equals psi_star[0] at the commit, which
commit_flux_to_history now checks, collectively. The nodal history's record fallback refreshes
the snapshot before its projection reads it. Both were noted as TODO(BUG) in review of #1231.

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

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

Verdict on 22ca45a: ready to merge on green from this review.

  • The split advection now corrects each of xx, yy and xy with its own term, serially and at np 2 and 3. Development corrects xx only, puts xy's correction into yy, and leaves xy untouched.
  • The commit's snapshot check raises the same error on every rank, with no hang, including with a rank that holds no cells.
  • The record fallback now reads the history as it is, which is a correct change of answer, and it is the same on every rank.
  • Scalar and vector Eulerian histories are bitwise unchanged.
  • test_1061 fails on development's own CI with the identical value, and the forward history does not reach any of the changed code.

The findings below are low only.

Method

The PR changes Python files only. Both the PR and development at the merge base (2079fdf) were run as Python overlays on a fresh build of 2079fdf:

  • The build's compiled sources are those of 2079fdf.
  • The tree is clean, and the build was made after checkout.
  • Its installed Python files match the tree.

Every run printed underworld3.__file__ to confirm which overlay was loaded.

The parallel layouts are a test-only shell partition of the gmsh mesh:

  • default: PETSc's own partition.
  • band: horizontal bands of cells.
  • emptyband: bands over np-1 ranks, so the last rank holds no cells.

Results

1. The split correction. The test case is a degree-2 SYM_TENSOR Eulerian history holding (x², xy, y²) on a 1/6 simplex box over [-1, 1]², with V_fn the rigid rotation (-y, x) and Δt = 0.05. The change each stored column takes through update_pre_solve is compared with the hand-computed -Δt V·∇f at the nodes: 2Δt·xy for xx, -Δt(x² - y²) for xy, and -2Δt·xy for yy. Each cell gives the largest |change - exact| over all ranks. The column size is 0.1 for xx and yy and 0.05 for xy.

component (column) np layout development PR
xx (0) 1, 2, 3 default, band, emptyband 3.8e-4, correct 3.8e-4, correct
yy (1) 1, 2, 3 default, band, emptyband 1.0e-1: it carries xy's correction (agrees with xy's term to 4.3e-4) 3.8e-4, correct
xy (2) 1, 2, 3 default, band, emptyband 5.0e-2: left unchanged (largest change 0) 4.3e-4, correct

The residual of about 4e-4 is the same on the xx column before and after the PR. It comes from evaluating the gradient at the nodes, not from this change. test_1109 measures it more tightly by comparing each column with a scalar history taken through the same evaluation.

2. The snapshot check, a collective MAX. The test writes psi_star[0] after the pre-solve refresh. Every rank performs the write, because a .data write is itself a PETSc sync, but only one rank's values change, by 1e-3. The commit then runs.

case np layout PR
values changed on the last rank 2, 3 default, band the same RuntimeError ("psi_star[0] was written after the source snapshot…, largest difference 0.001") on every rank; no hang
values changed on rank 0, while rank 2 holds no cells 3 emptyband the same error on every rank; no hang
a clean commit 1, 2, 3 all commits
cost 1, 2, 3 – 0.015 to 0.056 ms for the local comparison, plus one scalar allreduce, against 120 to 170 ms for the commit's projection

3. The record fallback. The case is a Maxwell Stokes solve with the semi-Lagrangian history, where Stokes enables the snapshot, for 2 steps at Δt = 0.1. Then DFDt.update_pre_solve(0.1, store_result=True) is called.

  • Forcing the fallback: the VE flux turned out to be pointwise evaluable here, so the record did not fall back on its own. The fallback was forced by making the record's _history_evaluate raise once, on every rank. Counters confirmed the fallback projection ran on every rank.
  • The snapshot was stale: before the record, the snapshot and psi_star[0] differed by up to 8.3e-2.
case np development PR development, with the snapshot refreshed by hand first
∫σxy² of the record 1 3.012e-2: built from the stale snapshot 6.1846424e-2 6.1846424e-2
the record, compared array by array 1, 2 – bitwise equal to the column to its right –
the record, compared array by array 3 – equal to 2e-16, which is this layout's run-to-run noise (development against itself differs as much) –
for comparison, the pointwise record (no fallback) 1 6.1845733e-2 the same –

So the PR changes this answer, and correctly: the fallback's record now agrees with the pointwise record to the projection's accuracy, where development's was about half of it. The fallback refresh is a rank-local copy, taken on the same path on every rank.

4. Scalar and vector Eulerian histories. The cases are degree-2 SCALAR (sin 2x cos 3y) and VECTOR (x², sin xy) histories, order 2, with the same V_fn, over 3 steps. psi_star[0] was saved after each pre-solve, along with the final psi_star[1], on every rank.

np layout PR against development
1 – bitwise identical
2 default bitwise identical on both ranks
3 band, emptyband (scalar) bitwise identical
3 default, band equal to 2.2e-16. Development run twice against itself differs by the same amount, so this is run-to-run noise at this layout

5. Tests.

test np development PR
test_1109 (2) 1 2 failed (the xy column: 0.0500 against a 1e-6 bound; the check does not exist yet) 2 passed
test_1109 2 2 failed on both ranks 2 passed on both ranks
VE, SL and DDt slice, 26 files, serial 1 – 202 passed, 1 xpassed, 0 failed
parallel: test_0992, 1062, 1077 (advdiff SUPG), 1107 (fault guard) 2 – all passed
parallel: test_1236 (SLCN on an empty rank) 3 – passed (it is skipped at np 2)

The slice is test_0066, 0070, 0610, 0855, 0857, 1051, 1052 ×2, 1053 ×2, 1054 ×2, 1055, 1056, 1057, 1059 (stress transport), 1063 (stress-history restart), 1071, 1076, 1094, 1100 ×2, 1106, 1107, 1109 and 1164.

Findings

  1. Low: test_1061 is not this PR's.
    • It fails on development already: development's own CI tier-C job, on the push of c902390, reports assert 0.008006539677033686 < 0.003, which is u(6.5) = 0.526506539677. That is the value in the PR body, and the job's step still reports success, because tier C does not gate. The pin of 0.5185 predates that.
    • No changed code is on its path: ForwardSemiLagrangian overrides commit_flux_to_history, so the new check is not on its path, and it uses neither the Eulerian split advection nor the semi-Lagrangian record fallback.
    • Not reproduced here: my own runs of it on both builds were stopped by a 50-minute limit on a loaded machine, so I did not reproduce the number locally.
    • Next step: the pin needs an owner and a bisect, separately.
  2. Low: the non-symmetric TENSOR case also changes, and nothing covers it.
    • The new loop walks a TENSOR history's four components through _data_layout. The old code corrected only max(shape) = 2 flat columns of it.
    • This looks right, but nothing here or in test_1109 exercises it. A TENSOR case in test_1109 would cover it.
  3. Low, for the PR body only: "No caller reaches this path with the snapshot enabled today" is right for Stokes. Here, with store_result=True on a Stokes history, the record evaluated pointwise and did not fall back. So the fallback refresh is reachable only when evaluate itself fails, which this review had to force.

Confirmed correct

  • The split correction walks (i, j) over the upper triangle for SYM_TENSOR and writes through psi_star[0]._data_layout(i, j), as EulerianSUPG._transport_history does. A scalar or vector keeps its flat columns. Each .data write and each _history_evaluate is made the same number of times on every rank, including a rank with no cells.
  • _check_snapshot_is_level_0 is called only on the multi-component commit path, which is the one that reads the snapshot. It is called on every rank, its exact != 0.0 comparison is right for a copy, and its MAX makes the raise collective.
  • The three TODO(BUG) notes are replaced by accurate comments.
  • The test changes are the new test_1109 and two lines in test_1106.

Run and not run

  • Run: everything in the tables, with each parallel run under an MPI supervisor with a 300 s silence limit, and nothing above 3 ranks.
  • Not run:
    • test_1061 to completion (finding 1);
    • test_0780, which needs np 4;
    • the slice on development, since nothing failed on the PR;
    • a TENSOR history;
    • 3-D;
    • the emptyband runs that build a second mesh in one process. These hang in the mesh load (labelsLoad) on development as well, the already-reported empty-rank issue, so each emptyband section here was run in its own process.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 1901a46 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