Skip to content

Tests start with non-dimensional scaling off (#1001) - #1045

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/reset-model-scaling-flag-1001
Nov 11, 2026
Merged

lmoresi merged 1 commit into
developmentfrom
bugfix/reset-model-scaling-flag-1001

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member

A test that sets reference quantities no longer leaves non-dimensional scaling switched on for the next test. This fixes the test-isolation half of #1001.

What was wrong

set_reference_quantities switches the global scaling flag on. reset_default_model leaves the flag as it was. That behaviour is deliberate: test_0816::test_flag_state_persistence pins it, because the flag is global and does not belong to the model. conftest's isolation fixtures reset only the model. So a test that set reference quantities handed the next test a fresh model with none, but with scaling still on.

The change

Both isolation fixtures in tests/conftest.py, the per-test one and the module-scoped one (#567), now call one helper, _reset_global_units_state. It resets the model and switches the flag off. The library is unchanged.

Left open on #1001

Should reset_default_model itself switch the flag off? Doing so breaks test_0816::test_flag_state_persistence, which asserts the opposite, so it is the maintainer's call. #1001 stays open for that.

Tests

  • tests/test_0743_reset_default_model_clears_scaling.py (tier B) runs two tests under the live conftest with pytester. The second test saw the flag on before this change. It fails on 8f0ed0a, and also fails with the flag line removed.
  • 66 serial files that set reference quantities or the flag, at -n 6: 580 passed, 0 failed.
  • Adversarial review (H1, posted below):
    • no test depends on the flag staying on;
    • serial and np 2 outcomes are identical to base.
  • Low, not addressed: test_0743 does not pin the module-scoped fixture's call. A two-module pytester case would.

Checklist (UW3 Style Charter)

  • I have read the Style Charter and followed it over the surrounding code
  • No drive-by refactors, renames, or cleanups
  • The bug fix ships its regression test, written first, with level_* and tier_* markers
  • No hedging names, and no commented-out code
  • No new exception swallows
  • No data-access changes
  • Parallel: np 2 checked (by H1)
  • No dependency changes
  • AI-assisted work carries the attribution line

Underworld development team with AI support from Claude Code

set_reference_quantities switches the global scaling flag on, and
reset_default_model leaves it as it was: test_0816 pins that the flag is
global, not the model's. conftest's isolation fixtures reset only the
model, so a test that set reference quantities handed the next test a
model with none and scaling still on.

Both isolation fixtures now go through one helper that resets the model
and switches the flag off. The library is unchanged; whether
reset_default_model itself should clear the flag is left open on #1001.

test_0743 runs two tests under the live conftest with pytester: the
second saw the flag on before this change.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 10, 2026 15:06
@lmoresi

lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Adversarial review (H1 worker), from runs/2026-11-10-h3review/r1001/1001-review.md on hyperion

Adversarial review: 1259232 (#1001), bugfix/reset-model-scaling-flag-1001

FROM H1 worker TO H3 units | ORIGIN C1 (H3 review request 2026-11-10) | RE 1259232

Base 8f0ed0a. Builds wt-h1001 and wt-dev8f, tests from git archive copies. Scripts, logs and conftest variants
are in runs/2026-11-10-h3review/r1001/.

Verdict

Ready to open. The change is test-only and correct. We found no test that depends on the flag staying on. Our one
finding (F1, Low) is that test_0743 does not pin the module-scoped half of the fix.

The author's key question: does any test depend on the flag staying on across tests?

No. The evidence:

  • Census (scan_fixtures.py → scan_fixtures.out). 101 files in tests/ match use_nondimensional_scaling,
    set_reference_quantities, reference_quantities or Model(.
    • Fixtures broader than function scope: five, all module-scoped and none touching the flag or the references. They
      are in test_0022_unwrap_memoised, test_0024_jit_graph_lowering, test_0505_projection_smoothing_length,
      test_1056 and test_1057, and each builds a mesh or a law.
    • No class or session scope, and no xunit setup_module or setup_class. The six setup_methods are per test.
    • The only conftest is tests/conftest.py. tests/parallel/ has none.
    • Module-level code mentioning the flag or the references appears only in string literals: the pytester payloads of
      test_0742 and test_0743, and docstrings.
    • Every use_nondimensional_scaling(True) is inside a test or a function-scoped fixture. Each of those sets the flag
      itself before relying on it: test_0505, 0753, 0755, 0756, 0757, 0759, 0816, 0817 and 0818.
    • The function-scoped reset already cleared the references before every test on base. So a test that "relies on the
      flag but not the refs" from an earlier test would have been running scaled with no references even on base. We
      found none.
  • Runs, base against branch, per test (junit_compare.py):
    • Serial, one process over the 95 non-parallel files (plus test_0743 on the branch), 800 tests collected
      (compare_serial.out):
      • The first 666 tests in collection order give identical outcomes on both builds, test by test: 650 pass,
        8 xfail, 1 xpass, 6 skip and 1 fail. The fail is test_0023's source read, an artefact of our tests/-only
        archive.
      • Both runs then stalled at
        test_1060_stress_store_smoothing::test_the_store_smoothing_holds_..._integration_point_history for more than
        40 minutes. Run alone on the branch it produced no result in 900 s either, and we interrupted both runs. This is
        pre-existing and unrelated: the library is identical on both builds.
      • The remaining files, with that test deselected (compare_rest.out): 64 more tests, all passing on both builds
        with identical outcomes. Both runs then stalled again, after more than ten minutes without progress, at the
        sphere tests (test_1081_objective_step_sphere) on a loaded machine. We stopped them there.
      • Covered: 730 of 800 tests, with no difference between base and branch. Not covered: 69 tests from
        test_1081 onward (1084, 1092, 1094, 1100-1148, 1450, jit_cache), plus the deselected test. test_0743 passed on
        its own and under every conftest variant below.
    • np 2, the five tests/parallel/ files in the census (ptest_0010, test_0750, test_0780, test_0785, test_1062):
      28 tests per rank on both builds, 26 passed and 2 skipped, 0 outcome differences on either rank.
    • np 2, the serial files that set the flag or the references in a test or fixture (np2_summary.out):
      • Run one file per mpirun, base against branch: 28 files with identical outcomes. Some fail at np 2 on both builds
        (test_0753, 0755, 0756 coordinate, 0817 and others), because they are serial tests.
      • One file differed, test_0505_rbf_swarm_mesh [2-3-2]. It is flaky at np 2 on both builds and changes from rank to rank. Over four runs of each,
        counting either rank, [2-3-2] failed in 4 of 4 runs on base and 3 of 4 on the branch, and [3-4-2] failed in
        every run on both (rbf_rerun.out, np2/).
      • test_0114_swarm_save hangs at np 2 in save() on both builds, so we left it out.

Order of the helper

The order doesn't matter. reset_default_model builds Model(name="default") and calls use_strict_units(True). In
model.py the flag is touched only by set_reference_quantities (model.py:2317) [read]. Run: a conftest with the two
lines swapped passes test_0743 and the module-scope check below (mutants_1001.out, "swapped").

The test, and mutants

All runs use a copy of the live conftest, test_0743, and two small modules: test_m1 sets the references, and
test_m2 builds a module-scoped fixture and asserts the flag is off (mut/, mutants_1001.out).

conftest test_0743 module-scope check
branch pass pass
base (8f0ed0a) fail fail
helper without the flag line fail fail
function fixture doesn't call the helper fail pass
module fixture doesn't call the helper pass fail
lines swapped pass pass

Findings

# sev finding
F1 Low test_0743 pins only the function-scoped reset. If isolate_module_state stops calling the helper, test_0743 still passes, yet a module-scoped fixture is then built with scaling on after a module that set references. That is the #567 route, and the reason the module fixture exists. A second pytester case (two modules, and a module-scoped fixture that records the flag) closes it. Our mut/*/test_m1_sets_refs.py and test_m2_module_fixture.py are that case.
F2 Info The collection guard's fingerprint (_global_state_fingerprint) records references, strict units and the object count, but not the scaling flag. A module that calls use_nondimensional_scaling(True) at import would pass the guard. The branch's module-scoped reset now cleans up after it, so this is not a defect, but adding the flag to the fingerprint would make the guard complete.
F3 Info [read] set_reference_quantities also writes the global COEFFICIENTS dict in scaling/_scaling.py, and reset_default_model does not clear that either. It is the same class as #1001 but a different global, and outside this branch. Worth a line on #1001.

Merge conditions

  • None blocking. F1 should be added as a test, before or after opening.

Issue verdicts

What we could not test

  • The full suite under xdist's own distribution at CI worker counts. We ran serially and at np 2 only.
  • The last 69 serial tests in collection order (test_1081 onward), because of the two stalls above. Those files use
    only function-scoped fixtures that reset the flag themselves (reset_model_state in 1100/1110/1120/jit_cache) or
    set the references per test (1148). We ran 1148 per file at np 2, with identical outcomes.
  • F3: [read] only.

Underworld development team with AI support from Claude Code

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.

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