tools: d3d12_ab_compare reads an A/B of the D3D12 runtime (D3D12-AB-COMPARE) #2783

Merged
TheGeogeo merged 3 commits from upstream-pr/2783 into main 2026-11-30 21:05:31 +00:00
TheGeogeo commented 2026-11-30 19:44:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T19:44:36Z.


Claimed in the coordination issue as: D3D12-AB-COMPARE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7289787850)

Depends on: #2782 for gate run folders (summary.json). Logs work without it. #2779 adds the A/B counters line that phases reads when present.

What and why

docs/measuring_fps.md tells how to read an A/B: neighbouring pairs, the effect with its standard error, and ABBA after a throwaway run. But the scripts it named (ab_pair.py, ab_eff.py) were never in the repository, so everyone computed it by hand. Testers' verdicts from two runs a side turned out to be noise (enlighted on the bridge).

tools/d3d12_ab_compare.py (standard library, reusing tools/d3d12_run_fps.py's reader):

  • abba A:<run> B:<run> B:<run> A:<run> ... takes the runs in the order they ran: a gate folder, whose summary.json gives the world median of the presents and leaves out runs that did not PASS, or a log, whose frame lines at 1,000 draws a frame or more count as the world.
    • The unit is the run: one value each, its median frame time. Frames within a run are not independent.
    • Neighbouring runs pair up and give B − A.
    • It needs at least 4 pairs, as many with A first as with B first, so a linear drift (a cache warming, a machine heating) cancels.
    • It gives the mean difference, its standard error and a 95 % t interval, the median of the differences, and how many pairs agree in sign.
    • With 3 runs a side and no balanced pairs, it fits the side plus a linear trend instead.
    • It says "B faster" or "B slower" only when the interval leaves 0 out and all pairs but one agree in sign. One odd run cannot carry a verdict.
  • phases <log> does the same inside one LEONIDA_AB run, per switch: blocks of 2^s phases off and on, one difference per pair of blocks. It covers the median frame time and every counter of the A/B counters line (#2779). It leaves out a pair whose draws a frame differ by more than a tenth (a change of scene, not of the switch); --keep-draw-jumps keeps it.
  • plan --pairs 4 [--switch] prints a balanced order: two warm-ups, then a discarded run that ends on the first measured side, then ABBA.
  • Text output, or --json. Numbers only: never a log line, a path or an argument's text.

docs/measuring_fps.md sections 2 and 3 now point to it instead of to the missing scripts.

Tested

On Windows 11:

  • tests/test_d3d12_ab_compare.py, 13 tests, all passing, on synthetic numbers and logs:

    • a worked example with a drift: effect −1.225 ms, standard error 0.149, 95 % [−1.70, −0.75], "B faster";
    • a pure drift in an ABAB order with no effect, which naive pairs would read as "B slower": no clear difference;
    • one odd run: no verdict;
    • three pairs: not the pairs method;
    • three runs a side with a trend: the effect is recovered exactly;
    • a failed gate leaves its pair out;
    • gate folders and logs (menus only, the world);
    • phases with counters, and a scene change left out;
    • plan orders;
    • the command prints no path.

    The file runs in the standard-library CI loop.

  • test_d3d12_run_fps.py, test_docs_design_rows.py, test_ci_registration.py, check_no_game_data.py and git diff --check are clean.

GPUs tested: n/a (a standard-library tool; checked on Windows 11 Pro 10.0.26300).

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5572519087 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T19:44:36Z. --- Claimed in the coordination issue as: D3D12-AB-COMPARE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7289787850) Depends on: #2782 for gate run folders (`summary.json`). Logs work without it. #2779 adds the `A/B counters` line that `phases` reads when present. ### What and why `docs/measuring_fps.md` tells how to read an A/B: neighbouring pairs, the effect with its standard error, and ABBA after a throwaway run. But the scripts it named (`ab_pair.py`, `ab_eff.py`) were never in the repository, so everyone computed it by hand. Testers' verdicts from two runs a side turned out to be noise (enlighted on the bridge). `tools/d3d12_ab_compare.py` (standard library, reusing `tools/d3d12_run_fps.py`'s reader): - **`abba A:<run> B:<run> B:<run> A:<run> ...`** takes the runs in the order they ran: a gate folder, whose `summary.json` gives the world median of the presents and leaves out runs that did not PASS, or a log, whose frame lines at 1,000 draws a frame or more count as the world. - The unit is the run: one value each, its median frame time. Frames within a run are not independent. - Neighbouring runs pair up and give B − A. - It needs at least 4 pairs, as many with A first as with B first, so a linear drift (a cache warming, a machine heating) cancels. - It gives the mean difference, its standard error and a 95 % t interval, the median of the differences, and how many pairs agree in sign. - With 3 runs a side and no balanced pairs, it fits the side plus a linear trend instead. - It says "B faster" or "B slower" only when the interval leaves 0 out **and** all pairs but one agree in sign. One odd run cannot carry a verdict. - **`phases <log>`** does the same inside one `LEONIDA_AB` run, per switch: blocks of 2^s phases off and on, one difference per pair of blocks. It covers the median frame time and every counter of the `A/B counters` line (#2779). It leaves out a pair whose draws a frame differ by more than a tenth (a change of scene, not of the switch); `--keep-draw-jumps` keeps it. - **`plan --pairs 4 [--switch]`** prints a balanced order: two warm-ups, then a discarded run that ends on the first measured side, then ABBA. - Text output, or `--json`. Numbers only: never a log line, a path or an argument's text. `docs/measuring_fps.md` sections 2 and 3 now point to it instead of to the missing scripts. ### Tested On Windows 11: - `tests/test_d3d12_ab_compare.py`, 13 tests, all passing, on synthetic numbers and logs: - a worked example with a drift: effect −1.225 ms, standard error 0.149, 95 % [−1.70, −0.75], "B faster"; - a pure drift in an ABAB order with no effect, which naive pairs would read as "B slower": no clear difference; - one odd run: no verdict; - three pairs: not the pairs method; - three runs a side with a trend: the effect is recovered exactly; - a failed gate leaves its pair out; - gate folders and logs (menus only, the world); - `phases` with counters, and a scene change left out; - `plan` orders; - the command prints no path. The file runs in the standard-library CI loop. - `test_d3d12_run_fps.py`, `test_docs_design_rows.py`, `test_ci_registration.py`, `check_no_game_data.py` and `git diff --check` are clean. GPUs tested: n/a (a standard-library tool; checked on Windows 11 Pro 10.0.26300). AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not applicable.)
OreoFR commented 2026-11-30 19:51:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T19:51:50Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main 0f86bd594 merged with head 76b543a09.

  • MEASURED, green: tests/test_d3d12_ab_compare.py 13 passed. Red (main + only the test): 1 error at import, as expected for a new tool.
  • python -I scripts/check_no_game_data.py on tools/d3d12_ab_compare.py and docs/measuring_fps.md: clean.
  • MEASURED, one docs test fails with this PR (5/5 on main): tests/test_docs_repo_paths.py::DocsRepoPaths::test_docs_name_existing_paths, ('docs/measuring_fps.md:67', 'scripts/game-gate.ps1'). That script comes from #2782, which is not merged, so this PR depends on it: either Depends on: #2782 in the body and merge after it, or drop the path from line 67 here.
  • Not covered: a real A/B log from the game.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290049132 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7290049132). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T19:51:50Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, `main` `0f86bd594` merged with head `76b543a09`. - MEASURED, green: `tests/test_d3d12_ab_compare.py` **13 passed**. Red (`main` + only the test): 1 error at import, as expected for a new tool. - `python -I scripts/check_no_game_data.py` on `tools/d3d12_ab_compare.py` and `docs/measuring_fps.md`: clean. - **MEASURED, one docs test fails with this PR** (5/5 on `main`): `tests/test_docs_repo_paths.py::DocsRepoPaths::test_docs_name_existing_paths`, `('docs/measuring_fps.md:67', 'scripts/game-gate.ps1')`. That script comes from #2782, which is not merged, so this PR depends on it: either `Depends on: #2782` in the body and merge after it, or drop the path from line 67 here. - Not covered: a real A/B log from the game. AI-assisted: Claude Code
TheGeogeo commented 2026-11-30 19:57:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T19:57:20Z.


Thanks for the Mac run. test_docs_repo_paths failed here too: docs/measuring_fps.md named scripts/game-gate.ps1, which only #2782 adds. Fixed in c05f43403 by naming the game gate's run folders instead (doc and the tool's docstring), so this PR stays independent of #2782.

On Windows at c05f43403: tests/test_docs_repo_paths.py OK, tests/test_docs_cli_flags.py OK, tests/test_d3d12_ab_compare.py OK (13), scripts/check_no_game_data.py on the changed files OK, merge with current main clean.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290188851 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7290188851). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T19:57:20Z. --- Thanks for the Mac run. `test_docs_repo_paths` failed here too: `docs/measuring_fps.md` named `scripts/game-gate.ps1`, which only #2782 adds. Fixed in c05f43403 by naming the game gate's run folders instead (doc and the tool's docstring), so this PR stays independent of #2782. On Windows at c05f43403: `tests/test_docs_repo_paths.py` OK, `tests/test_docs_cli_flags.py` OK, `tests/test_d3d12_ab_compare.py` OK (13), `scripts/check_no_game_data.py` on the changed files OK, merge with current `main` clean.
OreoFR commented 2026-11-30 20:02:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T20:02:57Z.


Re-checked by OreoFR on the new head c05f43403 merged with main 0f86bd594 (macOS 27.2.1, Apple M5, Python 3.12.16): tests/test_d3d12_ab_compare.py 13 passed; tests/test_docs_*.py 57 passed, 133 subtests passed (the test_docs_repo_paths failure is gone, and the PR no longer depends on #2782); check_no_game_data.py on the three changed files: clean. Not covered: a real A/B log from the game.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290325590 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7290325590). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T20:02:57Z. --- Re-checked by OreoFR on the new head `c05f43403` merged with `main` `0f86bd594` (macOS 27.2.1, Apple M5, Python 3.12.16): `tests/test_d3d12_ab_compare.py` 13 passed; `tests/test_docs_*.py` **57 passed, 133 subtests passed** (the `test_docs_repo_paths` failure is gone, and the PR no longer depends on #2782); `check_no_game_data.py` on the three changed files: clean. Not covered: a real A/B log from the game. AI-assisted: Claude Code
TheGeogeo commented 2026-11-30 20:30:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T20:30:05Z.


CI check and linux-python-and-viewer failed on tests/test_tool_stdout_encoding.py: tools/d3d12_ab_compare.py's __main__ block did not set errors="replace" on stdout. Fixed in e4318f01f with the same guard as tools/d3d12_run_fps.py. On Windows: test_tool_stdout_encoding.py OK, test_d3d12_ab_compare.py 13 OK, merge with current main clean.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7291021930 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7291021930). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T20:30:05Z. --- CI `check` and `linux-python-and-viewer` failed on `tests/test_tool_stdout_encoding.py`: `tools/d3d12_ab_compare.py`'s `__main__` block did not set `errors="replace"` on stdout. Fixed in e4318f01f with the same guard as `tools/d3d12_run_fps.py`. On Windows: `test_tool_stdout_encoding.py` OK, `test_d3d12_ab_compare.py` 13 OK, merge with current `main` clean.
OreoFR commented 2026-11-30 20:34:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T20:34:38Z.


Re-checked by OreoFR on the new head e4318f01f merged with main d8ca18240 (macOS 27.2.1, Apple M5, Python 3.12.16): tests/test_d3d12_ab_compare.py 13 passed; tests/test_tool_stdout_encoding.py 4 passed (the new stdout guard); tests/test_docs_*.py 57 passed.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7291142658 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7291142658). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T20:34:38Z. --- Re-checked by OreoFR on the new head `e4318f01f` merged with `main` `d8ca18240` (macOS 27.2.1, Apple M5, Python 3.12.16): `tests/test_d3d12_ab_compare.py` 13 passed; `tests/test_tool_stdout_encoding.py` 4 passed (the new stdout guard); `tests/test_docs_*.py` 57 passed. AI-assisted: Claude Code
MoonEyes commented 2026-11-30 21:05:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T21:05:01Z.


Verified by MoonEyes (another person than the author) on head e4318f01f merged with main d8ca18240: Windows 11, Python 3.14. tests/test_d3d12_ab_compare.py 13 OK. Docs and test_tool_stdout_encoding OK. Red: the test does not import without the new tool. No game run from me (#2782 was run by enlight3d on an RTX 3090).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7291890666 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7291890666). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T21:05:01Z. --- Verified by MoonEyes (another person than the author) on head `e4318f01f` merged with `main` `d8ca18240`: Windows 11, Python 3.14. `tests/test_d3d12_ab_compare.py` 13 OK. Docs and `test_tool_stdout_encoding` OK. Red: the test does not import without the new tool. No game run from me (#2782 was run by enlight3d on an RTX 3090). AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 21:05:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T21:05:27Z.


Merging. Head e4318f01f merges cleanly with main d8ca18240 and does not force a rebase of #2566. Tool and doc, not the runtime; checked by OreoFR and MoonEyes on this head. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7291900919 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7291900919). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T21:05:27Z. --- Merging. Head `e4318f01f` merges cleanly with `main` `d8ca18240` and does not force a rebase of #2566. Tool and doc, not the runtime; checked by OreoFR and MoonEyes on this head. Merged by MoonEyes. AI-assisted (Claude Code).
enlight3d commented 2026-11-30 21:54:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-30T21:54:38Z.


RUN (independent run on Windows, #2783 head e4318f01f, tested as it is; it merges cleanly into main 407f71a23 per git merge-tree --write-tree. CI on e4318f01f: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass. Since 76b543a09, the head I tested first, only one sentence of docs/measuring_fps.md, the module docstring, and the 4-line stdout guard in the __main__ block of tools/d3d12_ab_compare.py changed. The verdict and pairing code is the same.)

Commands, from the repository root, python -I (Python 3.13.12), at low priority:

  • python -I -m unittest discover -s tests -p test_d3d12_ab_compare.py on e4318f01f: 13 tests OK.
  • python -I -m unittest discover -s tests -p test_tool_stdout_encoding.py on e4318f01f: 4 tests OK. On c05f43403, without the guard, test_every_main_block_reconfigures_stdout fails and names tools/d3d12_ab_compare.py, so the guard is what that test asks for.
  • Red, import: on main with only the PR's test file added, the module does not import (ImportError, no d3d12_ab_compare).
  • Red, behavioural (verdict rule, tests kept):
    • Verdict also given when the 95 % interval contains 0 (the lo > 0 or hi < 0 condition removed): test_a_drift_alone_in_an_unbalanced_order_is_no_effect fails. Caught on 76b543a09 and again on e4318f01f.
    • Not caught: verdict given without the sign agreement (the e["agree"] >= e["k"] - 1 condition removed, so one odd pair no longer blocks "B faster"/"B slower"). All 13 tests still pass, on 76b543a09 and on e4318f01f. No test covers the "all pairs but one agree in sign" rule that the PR and docs/measuring_fps.md describe. That is a gap in coverage, not a bug seen. A test with 4 balanced pairs whose interval leaves 0 out but where two pairs go the other way would close it.
  • Neighbour: test_d3d12_run_fps.py (the reader this tool reuses) 22 OK.

Real data (RTX 3090, leonida.exe, in the order the runs ran): abba read three of our A/B series of 2 runs per side: the lot C split (main against two halves reverted), LEONIDA_REAPER=0 against default, and #2753's switch off against on. Its per-run median frame times match my own analysis (for example 63.2 ms for the run I measured at 15.8 fps). It answered 'not enough runs' for all three (2 pairs, under its 4), which agrees with what those series could support: no established difference between arms in any of them. plan --pairs 3 gives warm-ups and throwaway runs per side, then A B B A A B. (Those real-data runs used 76b543a09. Between 76b543a09 and e4318f01f, git diff shows only the doc sentence, the docstring and the stdout guard, none of which touches reading, pairing or the verdict, so they still hold.)

Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7293076655 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2783#issuecomment-7293076655). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-30T21:54:38Z. --- RUN (independent run on Windows, #2783 head e4318f01f, tested as it is; it merges cleanly into main 407f71a23 per `git merge-tree --write-tree`. CI on e4318f01f: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass. Since 76b543a09, the head I tested first, only one sentence of `docs/measuring_fps.md`, the module docstring, and the 4-line stdout guard in the `__main__` block of `tools/d3d12_ab_compare.py` changed. The verdict and pairing code is the same.) Commands, from the repository root, `python -I` (Python 3.13.12), at low priority: - `python -I -m unittest discover -s tests -p test_d3d12_ab_compare.py` on e4318f01f: 13 tests OK. - `python -I -m unittest discover -s tests -p test_tool_stdout_encoding.py` on e4318f01f: 4 tests OK. On c05f43403, without the guard, `test_every_main_block_reconfigures_stdout` fails and names `tools/d3d12_ab_compare.py`, so the guard is what that test asks for. - Red, import: on main with only the PR's test file added, the module does not import (`ImportError`, no `d3d12_ab_compare`). - Red, behavioural (verdict rule, tests kept): - Verdict also given when the 95 % interval contains 0 (the `lo > 0 or hi < 0` condition removed): `test_a_drift_alone_in_an_unbalanced_order_is_no_effect` fails. Caught on 76b543a09 and again on e4318f01f. - **Not caught: verdict given without the sign agreement** (the `e["agree"] >= e["k"] - 1` condition removed, so one odd pair no longer blocks "B faster"/"B slower"). All 13 tests still pass, on 76b543a09 and on e4318f01f. No test covers the "all pairs but one agree in sign" rule that the PR and `docs/measuring_fps.md` describe. That is a gap in coverage, not a bug seen. A test with 4 balanced pairs whose interval leaves 0 out but where two pairs go the other way would close it. - Neighbour: `test_d3d12_run_fps.py` (the reader this tool reuses) 22 OK. Real data (RTX 3090, leonida.exe, in the order the runs ran): `abba` read three of our A/B series of 2 runs per side: the lot C split (main against two halves reverted), LEONIDA_REAPER=0 against default, and #2753's switch off against on. Its per-run median frame times match my own analysis (for example 63.2 ms for the run I measured at 15.8 fps). It answered 'not enough runs' for all three (2 pairs, under its 4), which agrees with what those series could support: no established difference between arms in any of them. `plan --pairs 3` gives warm-ups and throwaway runs per side, then A B B A A B. (Those real-data runs used 76b543a09. Between 76b543a09 and e4318f01f, `git diff` shows only the doc sentence, the docstring and the stdout guard, none of which touches reading, pairing or the verdict, so they still hold.) Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2783
No description provided.