193 Commits
Author SHA1 Message Date
Vijay Janapa Reddi 53169381ec Add semantic unit formatters and close LEGO unit warnings 2026-06-01 08:57:19 -04:00
Vijay Janapa Reddi e7c3f7e34f Fix TFLOP/s per W rate integrity and add L011 lint rule.
GpuEfficiencyTrajectoryRecap now divides Pint quantities through OUTPUT;
L011 blocks magnitude-ratio rate reattachment without preserved denominators.
2026-05-31 19:35:08 -04:00
Vijay Janapa Reddi 5c2d9bfcd2 Fix L014 closed-name fmt detection and refresh honest baseline.
The linter silently missed *_unit_str = fmt(...) assignments; replace the broken
space-strip check with L014_CLOSED_FMT and allowlist 81 known cases until 8½-B.
2026-05-31 19:28:18 -04:00
Vijay Janapa Reddi 758e5ddfce Clear lego-units lint debt and add closure codemods.
Zero the warning baseline, retire L017 false positives, add L019 blocking and
lint tests, and ship codemods for glued fences and bulk lint fixes.
2026-05-31 19:13:23 -04:00
Vijay Janapa Reddi 60710adadd Promote L019 to block .m_as() and refresh lint baseline post-migration.
Adds error-severity L019, --write-baseline, and fixes six regressions
(NS→nanosecond, Waymo closed-fixed names); baseline now 411 warnings.
2026-05-31 19:02:36 -04:00
Vijay Janapa Reddi 9548af10e4 Add bulk .m_as() migration script and mark Step 14+ complete.
The script converts LEGO .m_as(unit) to .to(unit).magnitude with guards for
US (microsecond), byte vs Bparam, and comment-only leftovers.
2026-05-31 18:58:43 -04:00
Vijay Janapa Reddi c37b99034e book: allow domain formatters in math check and scope lego-units to staged files
Pre-commit lego-units now lints only staged QMDs with per-file baseline so
parallel WIP does not block atomic migration commits; full-repo baseline remains for CI.
2026-05-31 17:53:05 -04:00
Vijay Janapa Reddi 8154f90099 book: add lego-units linter with warning-only baseline and CI hook
Wire lint_lego_units.py into binder check code --scope lego-units and
book-check-lego-units pre-commit with a committed warning baseline.
2026-05-31 17:47:25 -04:00
Vijay Janapa Reddi dcf1b668ad Merge dev into feat/margin-elements for retire
# Conflicts:
#	book/quarto/contents/vol2/security_privacy/security_privacy.qmd
#	book/tools/scripts/audit/svg_audit.py
2026-05-30 18:48:39 -04:00
Vijay Janapa Reddi 91b2ae5dc1 fix(book): correct misleading margin figures and harden generator
Visual QA of all 207 margin figures surfaced figures that contradicted
their own captions/labels. Fixes:

- 6 ladder inversions where bar length taught the opposite of the data
  (P99 vs mean, Image vs Text bandwidth, FHE vs AES latency, HBM vs
  register energy, training vs inference memory, radio vs arithmetic).
  Regenerated via margin_devices with consistent-unit / mlsysim SSOT
  values.
- 5 trend/threshold figures whose shape did not match the relationship
  (cloud-edge crossover, FPS collapse, burst-vs-sustained levels) plus
  two caption reframes (retraining knee, training power).
- 7 segmented-bar figures whose labels were truncated to 4 chars and two
  whose highlight contradicted the caption (egress, optimizer state);
  regenerated readable with full labels.
- 10 passive/meta captions rewritten as declarative takeaways.

Root cause hardened in generate_margin_figures.py: _parse_number now
unit-aware (ms vs s, MB/s vs GB/s, pJ vs nJ) instead of mis-reading the
first letter of a unit as a k/M/B/T multiplier; ironbar label cap raised
from 5 chars so words are no longer chopped.
2026-05-30 18:44:55 -04:00
Vijay Janapa Reddi c8b887249c docs: generalize internal rule-file references in comments
Replace pointers to the private project rules/docs tree (relative .claude/rules
and .claude/docs paths) in code comments and docstrings with neutral phrasing
("the project prose style guide", etc.). Load-bearing runtime paths that the
tooling reads or writes are left intact.
2026-05-30 17:32:19 -04:00
Vijay Janapa Reddi 714e74b02c chore: remove hardcoded private config paths from tooling
Drop absolute references to the author's private config repo (home-dir paths
into an external AIConfigs tree) from audit/newsletter tooling, and resolve the
prose-rule file in scan.py via the repo root instead of a hardcoded $HOME path
(also makes it portable across machines). No behavior change: the SHA lookup
keeps its graceful 'unknown' fallback when the file is absent.
2026-05-30 17:32:16 -04:00
Vijay Janapa Reddi 74860f3427 fix(book): clarify margin rooflines and thresholds 2026-05-30 17:05:52 -04:00
Vijay Janapa Reddi 64b466e548 feat(book): add curated margin figures 2026-05-30 16:49:16 -04:00
Vijay Janapa Reddi 6339322363 feat(book): add margin figure system 2026-05-30 14:54:58 -04:00
Vijay Janapa Reddi 6860c2459f Centralize book checks in Binder CLI 2026-05-30 13:41:34 -04:00
Vijay Janapa Reddi 8d0678b6f0 chore: capitalize 1,021 sentence-start crossrefs across vol1+vol2
With crossref prefixes set to lowercase, sentence-start refs need
the Quarto capitalized syntax (@Fig-, @Tbl-, @Sec-, @Eq-, @Lst-)
to render uppercase at sentence starts while staying lowercase
mid-sentence.

Applied 515 changes in vol1 (22 files) and 506 in vol2 (24 files).
Verified by rendering vol1/conclusion, vol1/introduction, and
vol2/introduction: capitalization correct in all contexts.

Also updated book/cli/commands/validate.py to recognize the
capitalized crossref prefixes in label/ref/citation checkers
(LABEL_REF_PATTERN, EXCLUDED_CITATION_PREFIXES, narrative_cite,
no_space_before_bracket).

Classification script added at book/tools/scripts/maintenance/
for future use and verification.
2026-05-26 20:08:59 -04:00
Vijay Janapa Reddi 4031e26652 Merge dev into codex/notation-audit-mlsysim (dev-sync 2026-05-25)
# Conflicts:
#	book/quarto/contents/vol1/introduction/introduction.qmd
#	book/quarto/contents/vol1/ml_systems/ml_systems.qmd
#	book/quarto/contents/vol1/nn_architectures/nn_architectures.qmd
#	book/quarto/contents/vol1/nn_computation/nn_computation.qmd
#	book/quarto/contents/vol1/training/training.qmd
#	book/quarto/contents/vol2/compute_infrastructure/compute_infrastructure.qmd
#	book/quarto/contents/vol2/data_storage/data_storage.qmd
#	book/quarto/contents/vol2/distributed_training/distributed_training.qmd
#	book/quarto/contents/vol2/fault_tolerance/fault_tolerance.qmd
#	book/quarto/contents/vol2/sustainable_ai/sustainable_ai.qmd
#	book/tests/test_units.py
2026-05-25 10:27:42 -04:00
Vijay Janapa Reddi f741a12103 Refactor inline-python chapters to one LEGO focal point per cell.
Split mega-classes and break cross-cell reads across vol1/vol2, add lego_focal_verify.py, wire foundation-model amortization prose to computed exports, and repair compute_infrastructure inline python fences and table placement.
2026-05-24 13:17:40 -04:00
Vijay Janapa Reddi 05bdff6e68 Citation-reference audit: prose rewrites + author-form cleanup
Codex chapter-by-chapter audit findings applied across vol1 and vol2:
prose rewrites where the cited source supported only a narrower or
adjacent claim, plus new audit tooling
(book/tools/scripts/build_citation_reference_packets.py and the
companion workflow doc).

Author-form cleanup pass on top of the audit:
- 19 narrative @key conversions where prose already named the author
  (e.g., "Sambasivan et al. describe ... [@sambasivan2021]" -> narrative
  "@sambasivan2021 describe ...", rendering "Sambasivan et al. (2021)
  describe ...") - removes the citeproc duplication that the
  manual-bracket regex did not catch.
- 4 [-@key] suppressed-author conversions for possessive eponyms
  (Han et al., Vaswani et al., Patarasuk and Yuan, Linnainmaa).
- 2 [-@key] conversions where the prose names an author/entity that
  matches the cited author (Patterson and Hennessy's iron law,
  Google's data centers + Google whitepaper).
- 1 Horowitz footnote rewritten to narrative so the inline year
  replaces a duplicated "(ISSCC 2014, ...) (Horowitz 2014)" pair.
- 1 narrative @russell2021 anchoring "As Russell argues" that was
  previously a bare attribution.
- 1 pre-existing narrative fix for "Graham et al. report ..." in
  collective_communication that had no cite on the line.

Pre-commit cleanups landing with this commit:
- subramanya2019diskann: add publisher = Curran Associates (NeurIPS
  proceedings, per bib-check rule 3).
- Remove orphaned @misc{Wu2016} GNMT bib entry in vol2; it had no
  citations and collided case-insensitively with @inproceedings{wu2016}
  (the cited Quantized CNNs paper) under bibtex-tidy's normalization.
- vol1/training/training.qmd: drop the dead UtilizationGap LEGO cell
  (gpu_real_tflops_*, cluster_*_tflops_*) and the dead
  TrainingModels.{gpt3_gpu_years,gpt3_compute_cost}_str exports plus
  their unused upstream values.
- vol2/distributed_training/distributed_training.qmd: anchor the
  orphaned [^fn-parameter-server] footnote on the body-prose mention
  of "parameter-server systems" rather than deleting the definition.

manual-bracket hook (book-check-refs) green at this tip.
2026-05-23 13:35:14 -04:00
Vijay Janapa Reddi 22d1b9a62c Merge math audit workflow updates
# Conflicts:
#	book/quarto/contents/vol1/benchmarking/benchmarking_concepts.yml
#	book/quarto/contents/vol1/conclusion/conclusion_concepts.yml
#	book/quarto/contents/vol1/data_engineering/data_engineering_concepts.yml
#	book/quarto/contents/vol1/data_selection/data_selection_concepts.yml
#	book/quarto/contents/vol1/frameworks/frameworks_concepts.yml
#	book/quarto/contents/vol1/hw_acceleration/hw_acceleration_concepts.yml
#	book/quarto/contents/vol1/introduction/introduction_concepts.yml
#	book/quarto/contents/vol1/ml_ops/ml_ops_concepts.yml
#	book/quarto/contents/vol1/ml_systems/ml_systems_concepts.yml
#	book/quarto/contents/vol1/ml_workflow/ml_workflow_concepts.yml
#	book/quarto/contents/vol1/model_compression/model_compression_concepts.yml
#	book/quarto/contents/vol1/model_serving/model_serving_concepts.yml
#	book/quarto/contents/vol1/model_serving/serving_concepts.yml
#	book/quarto/contents/vol1/nn_architectures/nn_architectures_concepts.yml
#	book/quarto/contents/vol1/nn_computation/nn_computation_concepts.yml
#	book/quarto/contents/vol1/responsible_engr/responsible_engr_concepts.yml
#	book/quarto/contents/vol1/training/training_concepts.yml
#	book/quarto/contents/vol2/edge_intelligence/edge_intelligence_concepts.yml
#	book/quarto/contents/vol2/responsible_ai/responsible_ai_concepts.yml
#	book/quarto/contents/vol2/robust_ai/robust_ai_concepts.yml
#	book/quarto/contents/vol2/security_privacy/security_privacy_concepts.yml
#	book/quarto/contents/vol2/sustainable_ai/sustainable_ai_concepts.yml
2026-05-21 10:45:35 -07:00
Vijay Janapa Reddi 8694aee73f Audit MLSys book math calculations 2026-05-21 10:21:45 -07:00
Vijay Janapa Reddi 6e2f99a524 tools: add glossary_gap_review.py audit-packet generator
Builds per-chapter review packets that compare concept-map entries
against the existing glossary headwords, classifying each missing
candidate by category and priority so editorial decisions
(add / already covered / too composite / methodology-formula-application
/ rename / needs review) can be made deliberately.

Outputs CSV + per-chapter Markdown packets + per-volume summary JSON
under .mlsysbook/glossary-pass/latest/. Pure stdlib + PyYAML; no LLM
calls. Pairs with .claude/rules/glossary.md.
2026-05-21 09:50:03 -07:00
Vijay Janapa Reddi 97594ab9d7 Add MLSysBook math audit workflow and fixes 2026-05-20 18:56:52 -07:00
Vijay Janapa Reddi 87fb526b05 Merge dev into mdmath-analysis (round 2)
Sync of 34 additional dev commits since the previous merge
(beb9e80ec). Conflict surface this round: 2 files / 6 blocks
(nn_computation, inference) — much smaller than round 1.

Resolution highlights:
- nn_computation: kept HEAD's canonical `_str` suffix exports and
  MarkdownStr-wrapped mnist_arch_str; absorbed dev's space-around-arrow
  prose style; fixed the missing `MnistFlopsCalc.inference_kb_display`
  reference (which was removed as dead code earlier) to use the
  existing `MNISTMemory.inference_kb_str` instead.
- inference: absorbed dev's callout-tip wrapper for "Debugging high
  P99 latency"; took dev's deletion of the redundant callout-example
  block (the dev callout-audit refactor extracted that material);
  preserved HEAD's `_str` suffix discipline on all attribute refs
  (e.g., HardwareSetupSharding.h100_mem_gb_str).

The bulk of dev's incoming changes auto-merged cleanly: 30+ commits of
callout refactors (table promotions, LEGO extraction, ID renames),
layout-check tooling, pre-commit autoformat sweep, and various polish
passes.

audit_math_canonical at the synced tip: 0 violations.
2026-05-20 01:37:40 -07:00
Vijay Janapa Reddi beb9e80ec4 Merge dev into mdmath-analysis
Sync of 16 dev commits into mdmath-analysis's math-helper cleanup
branch. Conflict surface: 31 chapter QMDs with 156 conflict blocks,
plus the optimizations/ -> model_compression/ directory rename and
~100 image-file relocations.

Resolved in two phases:

1. Conflict resolution (31 parallel agents, 5 batches): each agent
   merged HEAD's math-helper-cleanup discipline with dev's prose
   tightening, structural cleanups, new exports, and formatter passes.
   Standard rule: keep canonical _str/_math/_eq/_frac suffix discipline,
   precision bumps, MarkdownStr escape-hatches, and fmt-family imports
   from HEAD; absorb dev's prose/structural changes; merge orthogonal
   changes; prefer HEAD's canonical-math form on direct conflicts
   unless dev was a content correction.

2. Post-merge canonical-math cleanup (18 parallel agents, 3 batches):
   the auto-merged regions of dev's commits brought in 183 bare
   f-string anti-pattern violations (math.md §6 #1) and 4 dead-code
   exports (lego-dead-code). Each agent fixed its file's violations
   per math.md §3 format-spec mapping. Specific fixes:
   - bare f-strings for _str/_math exports -> canonical fmt()
   - _md suffix -> _math rename (variable + prose refs)
   - inline-ref missing suffix -> rename underlying attribute
   - precision=0 on non-integer literal floats -> bump precision OR
     wrap with int(round(...)) when integer rounding is intended
   - removed unreferenced LEGO exports (nn_computation.qmd grad_l1_str
     etc., ml_ops.qmd RetrainingInterval _str aliases)

Preserved critical math-helper fixes from earlier session:
- benchmarking utilization_peak_str p=2, m_params_str p=1,
  imagenet_error_2015_pct_str p=2
- model_compression EnergyCosts MarkdownStr escape-hatch (4 sub-unit pJ)
- ml_workflow edge_inference_cost_str p=3
- ml_systems devops_fte_str p=1
- performance_engineering weight_int4_gb_str p=2
- sustainable_ai grid_ci_us_kg_str p=3, asic_pj_per_flop_str p=1
- inference serving_cost_total_str / training_cost_total_str (single
  fmt() with commas + USD prefix)
- fleet_orchestration es_s3p2_math pre-computed math expression
- responsible_engr repr_group_fraction_str p=2

Verification at merged tip: audit_math_canonical reports 0 violations
across both volumes; lego-dead-code clean. Next phase: HTML+PDF
builds + per-chapter agent verification.
2026-05-20 00:38:48 -07:00
Vijay Janapa Reddi 1bc3440703 Merge dev into refactor/callout-audit for retire 2026-05-19 21:41:59 -07:00
Vijay Janapa Reddi d456a5a962 refactor(vol1): rename optimizations/ folder to model_compression/ for consistency
Every other vol1 chapter folder name matches its qmd slug; this aligns the
last outlier so folder == qmd stem across the volume. Also matches the slides
folder name (slides/vol1/10_model_compression).

- git mv contents/vol1/optimizations → contents/vol1/model_compression
- Update path refs in 4 quarto configs (html, pdf, pdf-copyedit, epub)
- Update path refs in index_prune_candidates.yml, build_locator_bins.py,
  format_tables.py, learning_objectives_bolding_parallel.sh
- Update chapter-id refs (vol1/optimizations → vol1/model_compression) in
  vol2 quiz integration strings (ops_scale, robust_ai, sustainable_ai)
- Update CHAPTER_DIRS, READING_ORDER, and stale "outlier" docstrings in
  fix_abbreviations.py, build_prior_vocab.py, build_audit_context.py,
  generate_quizzes.py (fallback logic kept as defensive code)
- Rename _audit/optimizations_audit.json → model_compression_audit.json
  and fix its stale source_file/chapter fields
- Update vol1/README.md chapter table
2026-05-19 19:53:30 -07:00
Vijay Janapa Reddi 652e17590a refactor(validators): retire latex_math/latex_adjacent inline-python checks
These two patterns lived in both book/cli/commands/validate.py and the
legacy book/tools/scripts/maintenance/validate_inline_refs.py. They were
created to flag inline `{python}` substitutions inside `$..$` math mode
that would silently corrupt commas/decimals via Quarto's auto-escape.

Both checks carried an explicit `_str`-variable exemption (negative
lookahead `(?!\w+(?:\.\w+)?_str)`) in the regex — the convention assumed
pre-formatted `_str` substitutions were safe in math contexts. That
assumption was wrong: Quarto escapes the substituted text regardless of
the variable's Python type, and the exemption let 639 latent corruption
sites slip through (catalog in .claude/_reviews/math_audit_2026-05-19/).

The previous commit (1022ffc2c0) eliminated the underlying bug class by
making fmt() return a MarkdownStr that renders verbatim through Quarto's
markdown-detection path. With the bug class gone, these checks generate
no signal and add noise to the validator. Removing them.

71/71 binder checks continue to pass.
2026-05-19 08:36:38 -07:00
Vijay Janapa Reddi 9ca2895c55 docs: drop dead glossary/README.md link surfaced by dev-sync
Pre-commit's check-internal-links hook flagged book/tools/scripts/README.md:27
referencing glossary/README.md, which dev removed in 5706f2c9ba
("Retire glossary JSON pipeline"). Drops the orphan row from the
subfolder-docs table.
2026-05-19 07:37:33 -07:00
Vijay Janapa Reddi 5706f2c9ba Retire glossary JSON pipeline 2026-05-19 07:08:01 -07:00
Vijay Janapa Reddi a57c6d7eb9 Introduce ML systems design grammar 2026-05-18 02:06:05 -04:00
Vijay Janapa Reddi 2719c0d05f Add caption/label-required checks for tables, figures, and listings
Three new native binder scopes (`tables.caption-required`,
`figures.label-required`, `listings.caption-required`) catch the
silent gap PR #1744 surfaced: pipe tables in body prose with no
`: caption {#tbl-X}` line, markdown-image figures with no
`{#fig-X}` label, and `::: {#lst-X ...}` listing divs without
`lst-cap`. All three feed into the existing pre-commit hooks
(`book-check-tables`, `book-check-figures`, new `book-check-listings`)
and skip tables nested inside `::: {.callout-*}` divs, frontmatter,
and backmatter, matching the surrounding editorial conventions.

Pre-existing corpus violations (48 tables, 207 figures, 0 listings)
are grandfathered via book/tools/audit/baselines/captions_baseline.json
following the bib_lint_baseline.json pattern: per-file count budgets
that block only NEW violations beyond the recorded budget. Regenerate
with book/tools/scripts/maintenance/regen_captions_baseline.py after
shrinking the debt.
2026-05-15 14:34:52 -04:00
Vijay Janapa Reddi dcac6d8979 cleanup: remove stale AI-workflow scaffolding from repo
Removed orchestration code, prompt templates, and one-off LLM scripts
that were either zero-referenced, self-referencing, or already retired:

book/tools/audit/
  - subagent_lane.py + subagent_prompts/sentence_case_h3.md
    (audit-driver scaffolding, no external callers)

book/tools/scripts/
  - gemini_review.py, figure_audit_gemini.py
  - testing/gemini_math_check.py
    (zero external references; one-off audit utilities)

scripts/cross-references/
  - agent-playbook.md (prompt template; only referenced by one
    print line in audit_crossrefs.py, scrubbed)

periodic-table/scripts/archive/
  - entire directory (14 files): iteration-loop scripts and
    panel-debate runners used to produce v0.2 of the periodic
    table. README labeled it research provenance only; not part
    of any active build.

No CI workflows, Makefiles, or active scripts touch any of the
removed files. Net: -2,523 lines.
2026-05-14 11:36:42 -04:00
Vijay Janapa Reddi 59d328bb11 chore: move bib_mitpress_openai.py from repo root to book/tools/scripts/
Branch added bib_mitpress_openai.py at the repo root, but the convention
for these standalone bibliography utilities is book/tools/scripts/ —
that's where the predecessor it replaces (bib_verify_gemini.py) lived,
and where its sibling tools (check_bib_boundaries.py,
check_bib_qmd_integrity.py, figure_audit_gemini.py, etc.) live.

Moved the file and updated its REPO_ROOT computation from
'Path(__file__).resolve().parent' (which only worked at repo root) to
'Path(__file__).resolve().parents[3]' (correct for the new location).
Smoke-tested with --help; runs cleanly. Nothing else in the repo
references this script by path.
2026-05-05 18:38:14 -04:00
Vijay Janapa Reddi ba2942f4f8 chore: sweep bibs to MIT Press expectations 2026-05-04 13:24:23 -04:00
Vijay Janapa Reddi 28b2d6cafa feat(tools): add per-scope bib check + fix cite-extraction regex
The bib/qmd integrity check now enforces a static scope mapping (vol1
qmds resolve only against vol1's bib, vol2 against vol2's, companion
papers against their own) so cross-volume citation leaks become a hard
failure. The pooled "any bib counts" mode is preserved behind
--no-scope-check for legacy callers.

The cite-extraction regex was also masking real problems: the buggy
fence-stripping pattern (matching any pair of triple-backticks) was
swallowing prose between unrelated fences when an HTML-commented figure
contained a stray ```. Anchored fences to line-start and added HTML
comment stripping. The fix surfaces 14 keys that were falsely flagged
as orphan, 5 unresolved citations, and 1 scope violation that were
hidden by the regex.
2026-05-03 19:04:39 -04:00
Vijay Janapa Reddi f77cc30dfc chore(refs): ignore index tags ending in underscore in boundary check 2026-05-03 15:55:49 -04:00
Vijay Janapa Reddi de776df481 build: add pre-commit hook to prevent LEGO dead code 2026-05-03 15:38:48 -04:00
Vijay Janapa Reddi da45f6a0fd Merge fix/bib-audit-fixes into dev — phase 1 (249 fixes) + phase 2 (orphan triage) 2026-05-03 15:32:03 -04:00
Vijay Janapa Reddi a37340aefe feat(refs): scan paper.tex citations in cross-repo integrity check
The previous scope was .qmd only, which made every paper-bib entry not
cited from a chapter look orphan even when paper.tex cited it. Adds
\cite/\citep/\citet/\citeauthor/\citeyear pattern matching for the four
paper.tex files (interviews, tinytorch, periodic-table, mlsysim).

Also fixes 6 broken links in tinytorch/paper/paper.tex caused by earlier
bib-audit deletions of keys that had year/surname mismatches. Restored
these entries with corrected keys (appel2002tiger, reddi2021widening,
pfaff2009pintos, rush2020minitorch, zhang2023dive) and updated the .tex
file to match. Replaced kannan2022astrasim with won2023astrasim2.
2026-05-03 15:26:05 -04:00
Vijay Janapa Reddi 286b13201b feat(refs): cross-repo bib/qmd link integrity check
New script: book/tools/scripts/check_bib_qmd_integrity.py

Closes a real gap in the existing `binder check refs --scope citations`
check, which only validates `vol1/**/*.qmd` against vol1 bib and
`vol2/**/*.qmd` against vol2 bib — and skips `interviews/`,
`tinytorch/`, `mlsysim/`, `periodic-table/` entirely.

This script does the comprehensive sweep:
- Walks every `.qmd` under book/quarto/contents, interviews,
  tinytorch, mlsysim, periodic-table (237 files in current tree).
- Checks every `[@key]` and narrative `@key` against the union of
  all 7 references.bib files (1,378 unique keys, 1,604 entries
  including duplicates).
- Reports two failure modes:
    1. Unresolved citations: `[@key]` in a .qmd with no matching
       bib entry anywhere. Hard error — broken link.
    2. Orphan bib entries: keys defined in a bib but cited nowhere.
       Soft warning — candidate for cleanup.

Filters false positives:
- Quarto cross-refs (`@sec-`, `@fig-`, `@tbl-`, etc.)
- CSS at-rules (`@media`, `@keyframes`, `@import`, ...)
- Python decorators (`@grad`, `@staticmethod`, ...)
- Math notation (`A@B` matmul, single-letter "keys" like `@B.T`)
- Negative lookbehind on `=@` / `(@` / `,@` to skip
  decorator/expression contexts entirely

Current state on this branch:
  qmd files scanned:    237
  bib files scanned:    7
  unique cited keys:    781
  unique bib keys:      1,378
  unresolved (broken):  0  ← every cite resolves
  orphans (uncited):    597 ← 38% of the bib is unused

The 597 orphans are not blocking but are a significant maintenance
surface — every audit pass re-checks them and many are exactly the
corrupted CrossRef-mining entries the recent fix passes have been
cleaning up. A separate `--prune-orphans` pass is the natural
follow-up.

Usage:
  python3 book/tools/scripts/check_bib_qmd_integrity.py
  python3 book/tools/scripts/check_bib_qmd_integrity.py --json
  python3 book/tools/scripts/check_bib_qmd_integrity.py --orphans-only
  python3 book/tools/scripts/check_bib_qmd_integrity.py --strict
                                          # exit 1 on orphans too

Exit codes:
  0 — every cite resolves (default; orphans don't fail)
  1 — at least one [@key] is missing from every bib
  2 — --strict mode and orphan bib entries exist
2026-05-03 14:13:10 -04:00
Vijay Janapa Reddi ee1b7f0641 fix(refs): tune bib_verify_gemini for real-world Gemini behavior
Empirical findings from running the script against all 7 bibs
(1,646 entries) on 2026-05-03:

1. **Empty-response failures with -p PROMPT.** The CLI's yargs parser
   re-tokenizes long prompts containing dash patterns and chokes,
   returning empty stdout in 3-4s. Switched to `--prompt=VALUE`
   form which binds tightly and keeps the parser out of the value.

2. **240s timeout was too short.** Gemini + Google Search round-trips
   regularly took 5-12 minutes for 50-entry batches. Bumped to 900s
   (15 min) and dropped retries to 1 — if a call times out at 15 min,
   retrying is throwing good money after bad.

3. **Burst rate-limit on parallel launch.** The original "stagger every
   max_parallel-th launch" pattern still fired N workers simultaneously,
   triggering Gemini's per-minute rate limit. Replaced with a true
   pipeline stagger: every batch waits STAGGER_SECONDS before launch,
   regardless of pool size. Default 25s × 4 workers ≈ one in-flight
   batch per 6s on the launch side.

4. **Batch size 25 was wasteful.** Gemini handles much larger contexts;
   bumped default to 50 to halve the call count without quality loss.

5. **Added --stagger CLI flag** so users can tune stagger independently
   of max_parallel.

These changes were validated end-to-end during the round-1 audit pass
(168 batches → 37 batches at the new defaults) before the script was
sidelined in favor of parallel Claude Agent invocations for the
production audit.
2026-05-03 13:38:43 -04:00
Vijay Janapa Reddi 71d076cc55 feat(refs): inline bib-check.md into Gemini prompt 2026-05-03 12:21:39 -04:00
Vijay Janapa Reddi 0260dac68a feat(refs): bib verification pipeline 2026-05-03 12:07:24 -04:00
Vijay Janapa Reddi 7de913cc34 fix: update quiz-generation.md path refs after context cleanup
The canonical spec moved from .claude/rules/ to .claude/docs/shared/.
Updated all 4 files that referenced the old path.
2026-04-27 14:32:22 -04:00
Vijay Janapa Reddi 3c95e3e67c refactor(quizzes): rename book/tools/scripts/genai/quiz_refresh to quizzes
The genai/ folder advertised an implementation detail (AI-driven) and
held only one tool. The siblings under book/tools/scripts/ are all
named by purpose (audit/, glossary/, mit_press/, publish/, ...) — this
brings the quiz pipeline into line with that convention.

Changes:
- git mv book/tools/scripts/genai/quiz_refresh -> book/tools/scripts/quizzes
- empty genai/ parent directory removed
- 4 path-string references rewritten (filters.yml comment, three
  internal docstrings/CLI examples in README/generate_quizzes/
  build_audit_context)
- 2 BUILD.md + DEVELOPMENT.md tree-listing entries updated to point at
  the new path
- README.md title and tagline updated (no longer "Quiz Refresh — runner";
  the "quiz-refresh pattern" label is replaced with "spec-plus-runner
  pattern" since the directory name now self-documents)
- generate_quizzes.py: meta["generated_by"] now writes
  "quizzes/generate_quizzes.py" (was "quiz-refresh/generate_quizzes.py");
  --skip-existing matcher loosened from "quiz-refresh" substring to
  "generate_quizzes" so it accepts both old and new descriptors
- 33 chapter quiz JSONs and 30 _audit/*_audit.json files: the
  generated_by metadata string updated to match new descriptor
- extract_anchors.py docstring: "quiz-refresh pipeline" -> "quizzes pipeline"

Verified post-rename:
- All scripts parse (ast.parse on all three .py files passes)
- validate_quiz_json.py works on sample chapters from each volume
- --skip-existing dry-run matches the new descriptor correctly
- git grep finds no remaining "genai/" or "quiz_refresh" references;
  the one remaining "quiz-refresh" reference is an intentional
  backwards-compat note in the --skip-existing comment block

The chapter quiz corpus and the spec at .claude/rules/quiz-generation.md
are unchanged in content — this is purely a directory + descriptor rename.
2026-04-25 08:09:47 -04:00
Vijay Janapa Reddi a2975e57f6 chore(quiz-refresh): remove agent-generated .md leftovers
The quiz-refresh pipeline accumulated 68 .md files of session-generated
documentation (handoff plans, per-chapter audit memos, master reports,
the legacy agent brief) that have all served their purpose now that the
A-grade corpus is committed at 9913a78d7.

Removed:
- PATH_TO_A_PLAN.md (handoff plan; plan is complete)
- _audit/MASTER_REPORT.md (gpt-5.4 audit; corpus has been replaced)
- _audit/opus_improved/MASTER_REPORT.md (Opus pass summary; commit body
  of 9913a78d7 already records the same facts)
- _audit/opus_improved/vol*_changes.md (33 per-chapter change logs from
  the Opus improvement pass; rationale captured in 9913a78d7's commit
  body, and the actual rewrites are visible via git diff against that
  commit's parent)
- _reviews/*_memo.md (31 generate_quizzes.py validator memos from older
  passes; superseded)
- prompts/agent_brief.md (legacy sub-agent brief; no code references it,
  the canonical spec at .claude/rules/quiz-generation.md replaced it)

Kept:
- README.md (human-authored runner documentation, still the entry point
  for anyone touching this directory)
- _audit/*_audit.json (31 gpt-5.4 audit JSONs; out of scope for this
  cleanup, which targeted .md leftovers only)
2026-04-25 07:57:46 -04:00
Vijay Janapa Reddi 9913a78d78 feat(quizzes): promote Opus sub-agent improvements for all 33 chapters
Replace the 33 gpt-5.4-improved quiz JSONs with claude-opus-4-7-improved
versions produced by 33 parallel sub-agents calibrated against §16 of
quiz-generation.md (25 gold-standard worked examples).

Corpus state after promotion:
- 33/33 chapters pass validate_quiz_json.py (schema + anchor validation,
  zero errors, zero warnings).
- 1,684 questions total across the two volumes (was 1,685; one net
  deletion from a §Mathematical Foundations trivia FILL on "arithmetic
  intensity" that was absorbed into a strengthened roofline MCQ).
- Self-reported grades: 2 chapters A, 31 chapters A-; every sub-agent
  identified and rewrote the audit-flagged issue patterns (trivia_fill,
  easy_tf, recall_only, throwaway_distractor, vague_lo,
  tautological_lo, build_up_violation) in its chapter.
- Zero Option/Choice/Answer [A-D] or ([A-D]) patterns anywhere in the
  corpus (§10 anti-shuffle-bug rule satisfied).
- Every MCQ distractor refuted by content, not by letter.
- Prior-vocabulary build-up enforced: questions that previously
  redefined prior-chapter terms (MLP inductive bias, attention
  mechanism, speculative decoding, fault vs error model, co-packaged
  optics) rewritten to test application in each chapter's specific
  context.

Artifacts committed alongside the quiz JSONs for traceability:
- book/tools/scripts/genai/quiz_refresh/build_audit_context.py — the
  new helper that packaged each chapter's identity, prior chapters,
  prior vocab, and per-section prose+questions+audit-issues bundle
  into a single Markdown context file read by each sub-agent.
- _audit/opus_improved/MASTER_REPORT.md — aggregated grade distribution
  and per-chapter roll-up.
- _audit/opus_improved/{vol}_{chap}_changes.md — per-chapter change log
  (sections rewritten vs kept, issue patterns fixed, substantial-rework
  sections, validator status) for every one of the 33 chapters.

Process note: the initial attempt to parallelize 32 agents in one wave
tripped server-side concurrency throttling; converged via retry batches
of 4 agents. The single outlier naming convention at vol1/optimizations
(stem model_compression) was handled during promotion.

Per Phase 2/3 of book/tools/scripts/genai/quiz_refresh/PATH_TO_A_PLAN.md,
with the substitution of sub-agent Opus calls for the direct Anthropic
API path (no ANTHROPIC_API_KEY was available in this session).
2026-04-24 19:20:45 -04:00
Vijay Janapa Reddi 62e18f5b32 fix(quiz-refresh): prefix memo and audit filenames with vol
vol1/conclusion and vol2/conclusion both passed chapter="conclusion" to
memo_path() and the audit-output builder, so the second write clobbered
the first. The same collision hit vol1/introduction vs vol2/introduction.
Verified by reading _audit/conclusion_audit.json and
_audit/introduction_audit.json: both currently contain vol2 content
(metadata.chapter reports "vol2/conclusion" / "vol2/introduction"),
confirming that the vol1 runs were silently overwritten during the
2026-04-24 audit pass.

Fix prefixes both filenames with {vol}_:
- memo_path(chapter) -> memo_path(vol, chapter), writes
  "_reviews/{vol}_{chapter}_memo.md"
- audit output writes "_audit/{vol}_{chapter}_audit.json"

Existing audit/memo files under pre-fix names remain on disk; Phase 2
will regenerate under the new names, at which point the orphaned
pre-fix files can be pruned.

Per PATH_TO_A_PLAN.md Phase 2 "also fix during this phase" bullet.
2026-04-24 18:05:00 -04:00