Repository navigation
site-compare: the PDF book and a GPU site's CPU fallback - #140
Conversation
…nits) Two checks QuantEcon/project-monorepo#26 names that the tool lacked: - pdf: the PDF book (_pdf/*.pdf in both builds), by its outline's parts and lectures. A section only in one build blocks. Each section's text is compared by its letters alone, less running headers, timings, environment paths and every line of the lecture's executed output on its HTML page; a chunk moved by a page break is no change. A section's difference is on _pdf/<book>.pdf#<slug>, the lecture its title names (from the pages' h1), so it can be lag; the page count is reported. Reads PDFs with pypdf (7.2.0, in the script's header and in tests.yml); without it, a run with two PDF books fails (exit 3) rather than skip the check. - gpu, with --gpu: a page whose outputs show a CPU fallback (JAX's "falling back to cpu", a failed nvidia-smi), or whose reference outputs show the GPU and its own none, blocks, and is never lag. The shared list gains the PDF bibliography's entry (the merged bibliography's months and corrections, typeset in LaTeX's Bibliography). From #131's review: a malformed figure address is no failure; an address starts a token and a size (1000x800) is two values; glued units (kB, GHz, h, us, s, it/s, M) and fractional seconds are values in a warning. Intermediate's calibration (publish-2026nov30b against the monorepo's build at 9728988) with --gpu: the PDF differs only in newton_method (lag) and the bibliography (expected); output-only sections are set aside; no fallback. dp builds no PDF, and its comparison is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…ders, Unicode)
- Sections are keyed by their title's letters and digits, and a title
that comes again by its occurrence: advanced's "How to Pay for a War:
Part 1/2/3" were one key, so Parts 2 and 3 were never compared. The
outline is compared in order, so a section lost, added, typeset twice or
moved blocks. A book with no outline is one section.
- The noise rules follow pypdf's real output: the running header is the
first line most pages share (the book's title), the footer a page's last
line in its real shapes ("82 Chapter5. Title", "5.9. Section 83"), the
continuation notes as pypdf gives them; timings anchored, memory
addresses set aside. The old rules matched only prose ("Chapter 6 of the
book", "has elapsed").
- Letters of any script: maths italic and Greek are compared.
- Executed output is set aside only where it isn't also the page's prose;
a moved chunk pairs with one deletion each.
- A page's h1 loses its chapter number before it names a section.
- GPU: NVML failure, zsh's "command not found", older JAX device names.
- requires-python 3.10 (pypdf 7.2.0's floor).
- Tests on pypdf's real shapes, and one for each guard: 39 mutations, all
caught. Intermediate's calibration is unchanged: newton_method lag, the
Bibliography expected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
- Tests for what the review's mutations got past:
- a change in the second of two same-titled sections, and a lecture
typeset twice keeping its lecture page;
- a title starting with a year ("1993 Prospects") keeping its page;
- maths italic and Greek letters;
- a chunk replaced in one place and inserted in another (not a move);
- a page's last line that isn't in a footer's shape;
- a heading in a footer's shape inside a page;
- the book's title as prose;
- a first line that starts with the title;
- a first line on fewer than half the pages;
- "Wall time:" and "continued from previous page" inside prose;
- letters glued to a memory address;
- a line that is prose in either build's page;
- an output line of exactly eight letters;
- a book with no outline read from its first page.
- GPU: back_prop's "JAX backend: gpu" is a marker too.
- 199 tests in test_site_compare.py. 66 mutations (40 of mine, each first
checked to parse, and the review's 26): 65 caught, and one equivalent
(footer read from page[-1] rather than body[-1], the same line whenever
body isn't empty). Intermediate's calibration and dp's comparison are
unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…ards pinned)
- A PDF line that is a date and time and nothing else, as nvidia-smi's
first line is ("Mon Nov 9 03:15:37 2026"), is set aside: it has too few
letters for the output rule, so it was compared as prose and blocked on
every GPU site's run date. On jax's real pair (release publish-2026nov11
against the monorepo's build) it raised 11 false defects and dated lines
in 5 more sections; now none. A date inside prose is still prose.
- Tests for the guards real data relies on:
- an output line inside a multi-line output;
- only the outline's top two levels being sections;
- two sections starting on one page;
- a chunk deleted once and inserted twice;
- the same letters broken differently (the early return; without it
difflib can report false lines);
- a fallback printed in several cells;
- environment paths under each prefix;
- "it/s" and both continuation notes;
- a seven-letter output line;
- last lines that aren't footers ("3 Chapter 5 …", "1.2. We use Python
3.10");
- the GPU sub-alternatives.
The maths-letters test now goes through letters().
- "JAX backend: gpu" is printed by the status pages as well as back_prop.
- 220 tests. 99 mutations across five sets, each checked to parse: 93
caught. The other six only make the GPU marker broader or the lag lookup
choose among same-titled pages, or are equivalent (the footer read from
page[-1]). Intermediate's calibration and dp's comparison are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
… last line)
- pypdf can glue a page's running footer onto its last line of text
("init).block_until_ready()46 Chapter4. Newton'sMethodviaJAX"). That
footer wasn't stripped, so where a page break moved between two builds a
section with no change of text blocked: jax's newtons_method did, against
its release. A footer-shaped tail is now stripped from a page's last line,
only straight after a character that is neither a space nor a digit, so
prose ending in a number is still prose. On jax's real pair the
newtons_method row goes and nothing else changes; intermediate's
calibration and dp's comparison are unchanged.
- Tests:
- glued even and odd footers;
- a glued footer's shape inside a page, and prose ending in a number
after a space, both still text;
- PDF_DATE over every weekday and month, spaceless and without seconds,
and lines that aren't dates;
- a run-date case whose letters differ (the Thursday case had none);
- each fallback line reported on its own;
- a change of case alone.
The prose-noise test's decorator sits on it again.
- 227 tests. 113 mutations across five sets, each checked to parse: 107
caught. The six others widen the GPU marker, choose among same-titled
pages' h1s for lag, or are the equivalent footer read from page[-1]
(twice).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
README.md's tools table conflicted on one row: this branch extends the site-compare row (the PDF book, --gpu), and #137 added the consumer-expected row below it, plus a line in the tree. The resolution keeps both: this branch's site-compare row, then #137's lines unchanged. Full tools suite on the merged tree: 859 passed, 1 skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
There was a problem hiding this comment.
🟡 Changes recommended
Active findings in tools/site-compare show that output filtering and size/address normalization can produce false blocking PDF and warning differences from output placement, line wrapping, or numeric-only changes.
3 open issues
What changed in this PR
Extends site-compare with PDF book comparison and optional GPU fallback detection for validating monorepo site builds.
Changes:
- Compares PDF outlines and section text, with layout and execution noise excluded.
- Detects CPU fallback with
--gpuand improves warning normalization and malformed URL handling. - Adds regression tests, PDF dependencies, documentation, and a bibliography exception.
| File | Description |
|---|---|
| tools/tests/test_site_compare.py | Adds PDF, GPU, and normalization regression tests. |
| tools/site-compare | Implements new checks and normalization fixes. |
| sites/compare-expected.yml | Allows expected PDF bibliography differences. |
| README.md | Documents PDF and GPU checks. |
| .github/workflows/tests.yml | Adds pypdf to test dependencies. |
Review effort: Balanced (adaptive)
| # size, factor, frequency, time or rate unit (512MB, 2.5x, 3GHz, 1.2h, it/s), | ||
| # which goes with the number. An address starts a token, and a size | ||
| # (1000x800) is two values. | ||
| WARN_NOISE = re.compile(OUTPUT_NOISE.pattern + r"|(?<![\w.])0x[0-9a-fA-F]+|(?<![\w.])\d+x\d+(?![\w.])|" |
There was a problem hiding this comment.
Fixed in 9ff14a6: the size alternative's lookahead is now (?!\w|.\d), as for a number, so a size may end a sentence ("figure is 1000x800.") and normalises; a dot followed by digits still doesn't end it. Test: the warnings parametrize gains "figure is 1000x800." against "figure is 1024x768.".
| # is ("Mon Nov 9 03:15:37 2026"): too few letters for the output rule. | ||
| PDF_DATE = re.compile(r"^\s*(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)" | ||
| r"\s*\d{1,2}\s*\d{1,2}:\d\d(?::\d\d)?\s*\d{4}\s*$") | ||
| PDF_ADDRESS = re.compile(r"0x[0-9a-fA-F]+") |
There was a problem hiding this comment.
Fixed in 9ff14a6, with a different guard: PDF_ADDRESS is now 0x[0-9a-fA-F]{8,}|(?<!\d)0x[0-9a-fA-F]+. WARN_NOISE's token-start guard would stop stripping the addresses pypdf glues to a word ("object at0x7f3a2b" loses its spaces), so the guard is a preceding digit: a size's x (1000x800) stays text, an address after a letter or space still goes, and a full address glued to a number (8 hex digits or more) still goes. Tests: sizes in a PDF line (spaced and glued) and a full address glued to a number give no PDF difference.
| if "".join(x) == "".join(y): | ||
| return [] | ||
|
|
||
| def output(line): | ||
| return len(line) >= 8 and line not in prose and any(line in o for o in outputs) |
There was a problem hiding this comment.
Fixed in 9ff14a6: section_changes now sets output lines aside before difflib aligns the lines, then compares the letters again, so an output line can't anchor the alignment. Test: your example gives no change, and a real prose change around the same output line is still reported.
…e's x in the PDF, output lines set aside before alignment)
- WARN_NOISE: a size may end a sentence ("figure is 1000x800."), as a
number may; a dot followed by digits still doesn't end it, as for a
number.
- PDF_ADDRESS: an address no longer starts straight after a digit, where
"0x800" is the end of a size (1000x800) and its x is text; a full
address (8 hex digits or more) glued to a number still goes. Copilot's
token-start guard would keep the addresses pypdf glues to a word
("at0x7f3a2b"), so the guard is a digit, not a word character.
- section_changes: output lines are set aside before difflib aligns the
lines, so one can't anchor the alignment and split the same prose into
a change; the letters are compared again after that.
Tests: 5 new cases (232 in the file). Mutations: 7, parse-checked; 5
caught; 2 survive by design: the size's lookahead without its ".digit"
clause (kept to match the number rule, as Copilot asked) and the second
early return (a shortcut: the loop gives the same empty result).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
☁️ Cloudflare Preview Ready! (intro)Preview URL: https://pr-140.qe-preview-intro.pages.dev Commit: Build Info
|
☁️ Cloudflare Preview Ready! (jax)Preview URL: https://pr-140.qe-preview-jax.pages.dev Commit: Build Info
|
☁️ Cloudflare Preview Ready! (advanced)Preview URL: https://pr-140.qe-preview-advanced.pages.dev Commit: Build Info
|
☁️ Cloudflare Preview Ready! (programming)Preview URL: https://pr-140.qe-preview-programming.pages.dev Commit: Build Info
|
☁️ Cloudflare Preview Ready! (dp)Preview URL: https://pr-140.qe-preview-dp.pages.dev Commit: Build Info
|
☁️ Cloudflare Preview Ready! (intermediate)Preview URL: https://pr-140.qe-preview-intermediate.pages.dev Commit: Build Info
|

Two checks that QuantEcon/project-monorepo#26 asks of
tools/site-compareand that it lacked: the PDF book, and a GPU site's CPU fallback. This PR also takes in the nits left from #131's review.pdf: the PDF book (_pdf/*.pdf, when both builds have one), a port of the hand validation'spdf-compare.py.init).block_until_ready()46 Chapter4. Title), only straight after a character that is neither a space nor a digit;nvidia-smi's first line is ("Mon Nov 9 03:15:37 2026"); a date inside prose is still prose;_pdf/<book>.pdf#<slug>: the lecture whoseh1, less its chapter number, the section's title names. So it can be lag, and an entry can name it. A section with no lecture page, such as LaTeX's own Bibliography, is keyed by its title.tests.yml. If two PDF books are present and pypdf is missing, the run fails (exit 3) rather than skipping the check.gpu, with--gpu. For a site that builds on a GPU, these block, and are never lag:nvidia-smifailed or not found, in bash's or zsh's words;cuda:0, thenvidia-smitable, and "JAX backend: gpu", which back_prop and the status pages print.A fallback blocks even when the reference fell back too. The shadow workflow (QuantEcon/project-monorepo#80) is to pass
--gpufor the matrix'sgpuleg.The shared list gains one entry. The PDF's Bibliography is the merged bibliography typeset by LaTeX, so its months are dropped and its entries corrected there too, as on
zreferences.html.From #131's review:
http://[) no longer fails the run (exit 3).0x…) must start a token, and a size (1000x800) counts as two values.kB,GHz,h,μs,s,it/s,512M) and fractional seconds.1-2) is a value.From Copilot's review (requested by the maintainer, at
fba4703; fixed in9ff14a6). Copilot made three points, each now fixed with a test:Calibration on intermediate. I compared release
publish-2026nov30bwith the monorepo's build at9728988(site-build run 47031722447), with--gpuand--lag newton_method:newton_method, which changed upstream: lag.jax (release
publish-2026nov11against the monorepo's build in the same run). This was not a matched pair, so most of its PDF rows are lag.nvidia-smi's date line had raised 11 false defects there and put dates into 5 more sections. With the date rule there are none, and nothing new appears. One more false row came from a footer glued onto a page's last line (newtons_method, whose page break moved); stripping a glued footer removes it, and changes nothing else on jax, intermediate or dp. Intermediate's calibration had missed it only because both its builds ran on a Thursday in November.dp builds no PDF, and its comparison is unchanged: 0 defects with #137's lists.
Tests.
tools/tests/test_site_compare.pyhas 113 new tests (45 functions, the rest parametrised cases), on PDFs a small writer in the test file makes in pypdf's real shapes:it/s), addresses, paths under each environment prefix, and run-date lines (every weekday and month, spaceless, without seconds);Mutations, run with
PYTHONDONTWRITEBYTECODE=1, each mutant first checked to parse. The last round ran 113 across five sets (mine and the reviews'; two appear in two sets), and 107 fail a test. The other six:JAX backendmarker match more widely, which on real outputs changes nothing;For Copilot's fixes, the delta review ran 10 mutations and caught 8 (mine ran 7 and caught 5). Two survive:
section_changes.9ff14a6's message calls it a shortcut that gives the same empty result, but that is wrong. With the output lines gone, a repeated prose line can anchor the alignment. For example,["wage", "iswage"]against["wageis", "wage", <an output line>]gives no change with the return, and a change without it. No test covers it yet; it is the first item below.The full suite, with CI's packages and pypdf, on the branch with main merged in, gives 864 passed, 1 skipped (the skip is a case-insensitive file-system test on macOS).
Left for a follow-up (the last reviews' nits; none changes a letter read from the four real PDFs):
section_changes' second early return (the case above).$anchor. The same goes for the date rule's weekday, month and year shapes.x = 45+46 Chapter4. Title) isn't stripped. It would block, never hide.Python 3.10.1. Then it said 5) loses its tail. None occurs in the real PDFs. Requiring a glued footer's page number to be the page's own printed number would close both gaps.Not compared.
-W) mostly prevents one.🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG