Skip to content

test_0022 runs on a sixth shard until #911's floor lands - #1008

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/shard-six-test-0022
Nov 8, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/shard-six-test-0022

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

test_0022 runs alone on a sixth shard, so a slow runner no longer pushes shard 4 past the job's 70-minute cap. This holds until #911's linear floor lands, which should bring it back.

What was wrong

On a Xeon 8370C runner, #964's shard 4 test_00[0-4]* batch took 55:38 at 01a82dc, mostly test_0022_rotated_adjoint.py, and the job was cancelled at the 70-minute cap. At the commit before, d7548b3, on the same CPU and kernel, it took 26:37; development's took 27:50 on an EPYC 7763. Why it varies this much is not established: #985 shows the BLAS kernel matters, and the integration session is measuring whether #964's r5 commit does. Either way, one file can push shard 4 over the cap, so it gets a shard of its own until #911.

The fix

  • batch 4 tests/test_00[0-4]*py --deselect=test_0022_rotated_adjoint.py
  • batch 6 tests/test_0022_rotated_adjoint.py

--print-shards gives [1,2,3,4,5,6], so CI grows a sixth job. The comment names #911 and says what to remove when it merges.

It is --deselect, not --ignore. The glob names the file on the command line, and pytest collects a named file even under --ignore: with --ignore=tests/test_0022_rotated_adjoint.py, all 7 of its tests were still collected. The node id is relative to tests/, the rootdir that tests/pytest.ini sets.

Tests

  • Collect-only with -m "not tier_c": batch 4 has 399 of 406 (7 deselected, all test_0022_rotated_adjoint.py), and batch 6 has 7.
  • check_test_coverage.py: OK, 399 files reachable.
  • check_test_coverage.py now honours a whole-file --deselect on the line that carries it, a fix from the review. Deleting only the batch 6 line now fails the check, naming tests/test_0022_rotated_adjoint.py; before, it stayed green.
  • Under real xdist sessions (--setup-plan -n 2, from the review), batch 4 has 399 items and batch 6 has 7. Collect-only proves nothing under xdist, which turns itself off then.
  • Shard 6 carries the file's whole cost, which can be 57 to 60 minutes on a slow runner against the 70-minute cap, until Rotated solve past round-off fails its last linear solve; since #907 a time loop rebuilds its KSP every step #911 shortens it.
  • To check on this PR's run: six shard jobs, shard 6 reporting 7 passed, and shard 4's time.

Refs #911, #985, #964

Underworld development team with AI support from Claude Code

On a Xeon 8370C runner, #964's shard 4 serial phase took 55:38, mostly
test_0022, and the job hit the 70-minute cap. Development's took 27:50 on an
EPYC 7763. test_0022 is deselected from shard 4's band and runs alone on
shard 6. --deselect, because pytest collects a file named on the command line
even under --ignore.

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

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

Copy link
Copy Markdown
Member Author

Review record

Author's checks only. The independent review is the integration session's cross-review, requested now; given the urgency, no separate review agent ran first.

  • The first version did not work. --ignore=tests/test_0022_rotated_adjoint.py left all 7 of its tests collected in batch 4, because pytest collects a file named on the command line even when it is ignored. Caught by a collect-only check before pushing. The same flaw was in an earlier unpushed branch of mine, so it never ran in CI.
  • --deselect=test_0022_rotated_adjoint.py: 7 deselected from batch 4 (399 of 406); batch 6 collects the same 7.
  • Mutant, deleting the batch 6 line: check_test_coverage.py still reports OK, since it does not parse --deselect. A blind spot, noted in the body.
  • --print-shards: [1,2,3,4,5,6]. The workflow takes the matrix from it, as CI gets a fifth shard: test_108*/test_109* leave shard 3 #997's review established.

Not checked here: a CI run (pending on this PR), and any other --ignore in scripts/test.sh that might have the same flaw. A quick grep finds none in the batch lines.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #1008 at 7ede456

Scope: scripts/test.sh at 7ede456 (base development fe494b1), scripts/check_test_coverage.py, tests/pytest.ini, tests/conftest.py, .github/workflows/build_uw3_and_test.yaml, and the shard-4 logs of five CI runs. Probes ran on a git archive of 7ede456 in a scratch directory, serial, OMP_NUM_THREADS=1, pytest 8.4.2 and xdist 3.8.0 (the versions pixi.lock pins for every env, dev included). No tracked file was modified.

Findings

Medium: the 2x the comment attributes to the CPU was not the CPU

The comment says #985's last Newton step "put shard 4's serial phase at 55:38 on a Xeon 8370C ... against 27:50 on an EPYC 7763". #964's previous run, one commit earlier, ran the same batch on the same CPU model and the same OpenBLAS kernel in half the time:

job            tree      CPU                    OpenBLAS core   test_00[0-4]* batch
128568741869   d7548b3c  Xeon Platinum 8370C    SkylakeX        1597.05s (0:26:37)   shard 4/5 passed
128573052932   01a82dc5  Xeon Platinum 8370C    SkylakeX        3338.76s (0:55:38)   shard 4/5 cancelled at 70 min
128581062899   fe494b14  AMD EPYC 7763          Zen             1670.29s (0:27:50)   development, shard 4/5 passed
128552414435   99c8b050  AMD EPYC 7763          Zen             1615.72s (0:26:55)
128566626131   15f13d0c  AMD EPYC 9V74          Cooperlake       810.19s (0:13:30)

git log d7548b3c..01a82dc5 is one commit, 01a82dc "Rotated workspace: a tolerance change drops the KSP context, not the geometry (#964 r5)". It changes rotated_bc.py's cross-solve workspace (a tolerance change, tol_ok, now drops only the KSP context, and a workspace persists with no context when a solve built none), which is test_0022's code path: four forward rotated solves whose last linear solve fails hard (#911, #985). Two samples cannot separate runner noise from that commit; #985 records 30:10 to 52:14 for one tree and kernel under load. Either way the CPU model does not explain the 55:38. If r5 doubled test_0022, moving the file to its own shard hides a #964 regression rather than a balance problem. Before relying on this PR for #964, compare test_0022 at d7548b3 and at #964's head on one host by iteration counts (#985's overlay), and reword the comment to state what was measured.

Medium: shard 6 inherits the whole cost, with about 10 minutes of headroom on the run that motivated it

The PR moves the cost; it does not reduce it, which #985 already says. On the cancelled run the batch's last 46 of 406 results took 51:58 (the [ 88%] line at 00:23:07, [100%] at 01:15:05), and under --dist loadfile a batch cannot finish before its slowest file. Pre-test steps on that job took 4:36 (job start 00:14:48, Running serial test suite 00:19:24). A shard 6 on that runner and tree would therefore run about 57 to 60 minutes against the 70-minute cap and the 60-minute budget the workflow comment describes. On development's tree it is about 32 minutes on an EPYC 7763 (27:50 batch), and this PR's own shard 6 measured 15:44 on an EPYC 9V74. The PR is sound while #964 is unmerged; whether shard 6 stays under the cap after #964 merges depends on the first finding.

Medium: the coverage check cannot see the deselect, and the fix is +7 -2 lines

globs_run_by takes every tests/... token on a batch line and ignores --deselect. Deleting only the batch 6 line leaves test_0022 unrun, the check green, and the shard count silently one smaller:

$ grep -v '^  batch 6 tests/test_0022_rotated_adjoint.py$' scripts/test.sh > blind/scripts/test.sh
$ python3 scripts/check_test_coverage.py      # in the blind copy
OK: all 399 test files are reachable from scripts/test.sh (0 deferred by decision); ...
rc=0
$ bash scripts/test.sh --print-shards
[1,2,3,4,5]

That is the #721 class the check exists for, and the removal the comment asks for when #911 lands is a two-line edit where removing one line is the natural mistake. We consider it worth closing in this PR. Subtracting a whole-file --deselect from its own line's globs is +7 -2 in check_test_coverage.py:

         if re.search(r"\$\{?PYTEST", line) or re.match(r"\s*batch\s+\d+\s", line):
-            patterns.update(re.findall(r"tests/[A-Za-z0-9_\[\]*.\-]+", line))
+            # A whole-file --deselect (node id relative to tests/, the rootdir) takes
+            # that file back out of THIS line's globs.
+            dropped = frozenset(re.findall(r"--deselect[= ]([^\s:\"']+)(?=\s|$)", line))
+            for pattern in re.findall(r"tests/[A-Za-z0-9_\[\]*.\-]+", line):
+                patterns.add((pattern, dropped))
     return patterns
 ...
-    for pattern in globs_run_by(REPO / "scripts" / "test.sh"):
-        covered.update(glob.glob(str(REPO / pattern)))
+    for pattern, dropped in globs_run_by(REPO / "scripts" / "test.sh"):
+        gone = {str(REPO / "tests" / d) for d in dropped}
+        covered.update(set(glob.glob(str(REPO / pattern))) - gone)

Measured with the patched check: the PR tree gives OK ... 399, rc 0; development gives OK ... 399, rc 0; the copy without batch 6 gives 1 test file(s) match no glob in scripts/test.sh: tests/test_0022_rotated_adjoint.py, rc 1. Node-level deselects (::) are left alone, and a deselect spelled tests/..., which pytest does not match, subtracts nothing, so the check agrees with pytest in both cases. The docstring's list of spellings would want one line for it.

Low: the header still says test_0022 stays on shard 4

scripts/test.sh:156, in the 2026-11-08 header block the PR leaves untouched: "test_0022 stays on shard 4 until #911's fix, which should shorten it." The new comment at line 310 says the opposite. Line 21's example --shard 1/5 now errors (asked for shard 4 of 5, but the batches below are assigned to 6 shards, rc 1); its own text says N must match --print-shards, so it is only a stale example.

Low: "serial phase" is the first batch

Both times in the comment are pytest's own total for the test_00[0-4]* batch (406 passed ... in 3338.76s (0:55:38); in 1670.29s (0:27:50)), not the serial phase. On the cancelled job the serial phase ran from 00:19:24 to the cancel at 01:25:07 and had not finished; on development's job it ran 00:53:21 to 01:31:09, 37:48. The PR body uses the same wording.

Low: "test_0022" names three files

tests/ holds test_0022_adjoint_operator_from_kernels.py, test_0022_rotated_adjoint.py and test_0022_unwrap_memoised_matches_fixed_point.py. Only the second moves. The code line is exact; the comment and the PR title would read better with the full name.

Checked and clean

  • The deselect matches, in-process. In-process collect-only of batch 4's command line (pytest --config-file=tests/pytest.ini -m "not tier_c" tests/test_00[0-4]*py ...), 52 files on the command line: development line 406 tests collected, 7 of them test_0022_rotated_adjoint.py::; PR line 399/406 tests collected (7 deselected), none. The diff of the two id lists is exactly the 7 test_0022_rotated_adjoint.py:: ids. rootdir: .../tests, so the bare filename is the node id.
  • The deselect matches under xdist. --collect-only does not exercise xdist: xdist/plugin.py:269 returns early under collectonly, so a collect-only run with -n 2 collects in-process and proves nothing. We ran real distributed sessions instead: --dist loadfile -n 2 --setup-plan on batch 4's PR line gives created: 2/2 workers and 2 workers [399 items]; on development's line [406 items]; on batch 6 [7 items]; and tests/test_0022_rotated_adjoint.py --deselect=test_0022_rotated_adjoint.py -n 2 gives 2 workers [0 items], rc 5.
  • The other spellings fail as the comment says. --deselect=tests/test_0022_rotated_adjoint.py deselects nothing (406 collected, 7 test_0022); --ignore=tests/test_0022_rotated_adjoint.py also collects all 7, because the file is named on the command line.
  • The prefix match reaches nothing else. pytest deselects by nodeid.startswith(prefix) (_pytest/main.py:448). No other node id starts with test_0022_rotated_adjoint.py: the other two test_0022_* files diverge at character 10, and tests/parallel/ ids start with parallel/.
  • Batch 6 fails loudly if it ever collects nothing. A renamed file is a literal missing path (pytest rc 4); seven deselected or tier_c tests give rc 5. Both set status=1.
  • The shard count reaches CI. --print-shards gives [1,2,3,4,5] on development and [1,2,3,4,5,6] on the PR. The PR's plan job logged shards: [1,2,3,4,5,6], and run 42436740990 created jobs shard 1/6 to shard 6/6. The workflow hard-codes no shard count or number: the matrix is fromJSON(needs.plan.outputs.shards), the job name and --shard use strategy.job-total, the artifact is hang-stacks-shard-${{ matrix.shard }}, and the test aggregator reads needs.shards.result. The development/main ruleset has no required status checks, so renamed check names block nothing.
  • Each route runs test_0022 once. With an echo stub in place of pytest (scratch copy only), no --shard: the file is named on 2 command lines, one of which deselects it. Per shard (WORKERS=4 --shard K/6): shards 1, 2, 3 and 5 never name it, shard 4 names it with the deselect, and shard 6 runs pytest --config-file=tests/pytest.ini --dist loadfile -n 4 -m not tier_c tests/test_0022_rotated_adjoint.py. --shard 4/5 is refused. ./uw test and pixi run test go through scripts/test_levels.sh, which selects by level marker over tests/ and does not read test.sh; this PR does not change them.
  • The coverage check runs on every shard. It is outside the batch gate, so shard 6 runs it too, and it reports OK: all 399 test files are reachable.
  • Nothing assumes test_0022 shares shard 4 or a process. The file builds its own state in one module-scoped fixture (rotated_gradient), reads no file written by another test, and imports only underworld3 and its own helpers. tests/conftest.py keys its mesh cache by xdist worker (UW_MESH_CACHE_DIR=.meshes/<worker>), not by shard, and isolates module state with an autouse module fixture. No test, conftest, doc or script outside test.sh and the workflow refers to a shard number or count. docs/developer/CHANGELOG.md describes the four-shard history only. On shard 6 the file runs alone in a fresh worker, with three idle workers beside it.
  • The other mechanics in the comment hold. Removing the --deselect and the batch 6 line returns --print-shards to [1,2,3,4,5], because the shard count is the highest batch N number. The node id is relative to tests/, the rootdir --config-file=tests/pytest.ini sets. -m "not tier_c" deselects nothing in batch 4, so the 7 deselected are all the file's.

This PR's CI run (42436740990), as of 02:32 UTC

Shards 3/6, 4/6 and 6/6 had finished; 1/6, 2/6 and 5/6 were still running, so we have no verdict for them.

shard 6/6  EPYC 9V74, Cooperlake  "4 workers [7 items]"   7 passed in 689.69s (0:11:29)   job 15:44   success
shard 4/6  EPYC 9V74, Cooperlake  "4 workers [399 items]" 399 passed, 1 skipped in 282.99s (0:04:42)   job 29:15   success
shard 3/6                                                                                               job 16:44   success

On the same CPU and kernel, development's run 15f13d0 took 13:30 for the batch with test_0022 in it. Here it takes 4:42 without the file plus 11:29 for the file alone, which matches. Shard 4/6 logs Running parallel tests at 02:19:27, so it still owns the MPI phase. Shard 6/6 logs Parallel tests belong to shard 4; this is shard 6. and OK: all 399 test files are reachable.

Issues

Underworld development team with AI support from Claude Code

… name the file and stop attributing the 55:38 to the CPU

From the review of #1008. Deleting only the batch 6 line used to leave the
check green with test_0022_rotated_adjoint.py unrun; it now reports the file.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

The review is addressed at the new head.

  • Medium 3: the coverage fix is applied as given. Deleting only the batch 6 line now fails the check, naming tests/test_0022_rotated_adjoint.py; the real tree is OK on 399 files.
  • Medium 1: the comment and the body no longer attribute the 55:38 to the CPU. They give the 55:38 and the 26:37 on the same Xeon and kernel, and say the cause is not established. Your r5-in and r5-reverted counts will settle it.
  • Medium 2: the body says shard 6 can reach 57 to 60 minutes on a slow runner until Rotated solve past round-off fails its last linear solve; since #907 a time loop rebuilds its KSP every step #911. No change.
  • Lows: the header line saying test_0022 stays on shard 4 is updated, the file is named in full in the comment, and "serial phase" is now "the test_00[0-4]* batch".

Underworld development team with AI support from Claude Code

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

#964's r5 commit is ruled out as the cause of the 26:37 against 55:38 spread. The integration session ran test_0022_rotated_adjoint.py on wombat, serially at OMP_NUM_THREADS=1, on #964's 31d47c5, with r5 in place and with r5 reverted at run time. Both arms logged every rotated solve.

solve tol linear its per Newton step time, r5 / reverted
1 1e-11 [1,1,1,1,1,32] 73.2 / 73.3 s
2 1e-11 [1,1,1,1,1,300] 334.3 / 334.3 s
3 1e-11 [1,1,1,1,1,300] 331.8 / 332.0 s
4 1e-11 [1,1,1,1,1,12] 13.8 / 13.8 s
5 1e-9 [1] 0.03 / 0.04 s
6 1e-10 [1,1,1,1,1,1] 0.23 / 0.23 s

Both arms: 7 passed, in 758.5 s and 758.7 s. workspace_reused is False on every solve, so r5's paths are never taken. 666 of the 758 s are the two last Newton steps capped at 300 outer iterations, which is #911 and #985.

So the spread on the Xeon comes from the runner or its load, not from #964. The comment's "not established" stands; this note records what was excluded. No code change, so CI on fb0f7ef is not restarted.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

First six-shard run, 42436740990 at 7ede456 (the change itself; later heads touch only comments and the coverage check), all green:

shard time CPU
1 44:19 EPYC 7763
2 35:17 Xeon 8370C
3 16:44 EPYC 9V45
4 29:15 EPYC 9V74
5 31:50 EPYC 7763
6 15:44 EPYC 9V74

Shard 6 reports 7 passed in 689.69s (0:11:29) for test_0022_rotated_adjoint.py. Shard 4, without it, ran 29:15 on a 9V74, where it used to run 43:58 with it. Shard 6 has not yet run on a slow runner.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 06c574e into development Nov 8, 2026
10 checks passed
gthyagi pushed a commit to gthyagi/underworld3 that referenced this pull request Nov 10, 2026
…e#1008) into feature/convergence-reference-policy

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