35 Commits

Author SHA1 Message Date
Vijay Janapa Reddi
8789d68780 Add typed FPS formatter 2026-06-11 23:49:47 -04:00
Vijay Janapa Reddi
92f9165d03 fix(book): harden LEGO formatting across volumes
Add native Binder checks for LEGO formatting/unit/prose contracts, extend mlsysim formatter helpers, and normalize Vol1/Vol2 LEGO output strings through typed formatters.

Validate precision-sensitive prose rendering across both volumes and promote direct math/string assembly to fmt_math, fmt_display_math, fmt_text, and domain-specific helpers.
2026-06-11 14:36:35 -04:00
Vijay Janapa Reddi
c3517c589f Add fmt_length and km/h rate support for LEGO prose exports.
Closed-formatter cells need dedicated helpers for distance and speed so prose can use bare refs without duplicate unit suffixes.
2026-06-06 14:03:37 -04:00
Vijay Janapa Reddi
9c3dce60dc Delete the core/constants.py compat shim; migrate the whole corpus
No-backward-compat sweep, part 2. The module had been reduced to a
units-only re-export ('retired, do not add values'); per policy it is
now gone and every consumer reads the real home:

- 32 internal modules, the package __init__, and core/__init__ import
  core.units (physics modules keep their own physics/constants)
- 43 book chapters' LEGO cells migrated (star imports, named imports,
  and the appendix attribute style 'constants.VIDEO_*' -> units.*);
  lego_focal_verify confirms identical pass/flag state to pre-sweep
  (8 pre-existing structural flags, A/B-verified unchanged)
- tutorial/tools/test imports migrated (incl. binder test_units.py);
  book tests' legacy-symbol scanner treats a missing constants.py as
  'nothing defined'
- test_constants_allowlist.py rewritten as a deletion pin: the module
  (and any shim for it) must never return; core.units must keep the
  measurement surface (ureg, Q_, GB, BYTES_FP16, PRECISION_MAP, ...)
- test_mlsysim_registry_parity.py deleted: it compared registry values
  against legacy constants 'before deletion' — that migration is
  complete (registry gate list updated)
- Docs prose (DATA_MODEL, architecture, contributing) states the
  deletion instead of describing a retired shim

749 passed; binder registry gate green; star import intact.
2026-06-06 11:34:47 -04:00
Vijay Janapa Reddi
7a71939cb0 Fix fmt boundary bugs: silent zeros, scale promotion, label drift
- fmt_int: nonzero values that round to 0 now raise (the allow_zero
  removal left fmt_int as a silent-zero path: fmt_int(0.4) rendered
  '0'); rounding switched from banker's to half-away-from-zero so
  adjacent halves agree (2.5 -> 3, was 2)
- Auto-scale counts promote at the rounding boundary:
  fmt_params(999_999_999) -> '1B' (was '1000.0M'),
  fmt_params(999_999_999_999) -> '1T' (was '1000B'); top scale falls
  back to commas ('2,000T')
- fmt_unit now routes through the shared _UNIT_LABEL_NORMALIZATION
  table (its divergent local map missed EFLOPs/KFLOPs rates and bare
  work units), so fmt_val/fmt_unit table columns always match fmt_qty
  prose suffixes. Visible alignment effects: 'Gbps' -> 'Gb/s',
  'B' -> 'bytes' in a handful of table cells (now consistent with
  adjacent fmt_qty prose)
- fmt_pp(-1) -> '-1 percentage point' (singular checked on magnitude)
- fmt_usd(-500) -> '-$500' (sign before currency glyph; approx and
  scale/per variants handled)

20 new boundary tests; fmt suite 175 passed, full suite 751 passed.
2026-06-06 09:19:10 -04:00
Vijay Janapa Reddi
fa9e65cfd5 Normalize fmt rate suffix outputs 2026-06-03 01:41:46 -04:00
Vijay Janapa Reddi
6dd3c04ebc Apply Design B multiplier formatting 2026-06-02 22:17:41 -04:00
Vijay Janapa Reddi
62a7014ddb Add semantic formatting audit support 2026-06-01 21:49:27 -04:00
Vijay Janapa Reddi
990adfdbbf Tighten LEGO math layout and unit grouping 2026-06-01 11:19:22 -04:00
Vijay Janapa Reddi
3847958f9a Harden LEGO currency formatting 2026-06-01 11:00:14 -04:00
Vijay Janapa Reddi
1f4c16fa89 Migrate LEGO outputs to semantic formatters 2026-06-01 09:49:47 -04:00
Vijay Janapa Reddi
53169381ec Add semantic unit formatters and close LEGO unit warnings 2026-06-01 08:57:19 -04:00
Vijay Janapa Reddi
d53c0b1c52 Add MLSysIM unit formatting anchors 2026-06-01 07:07:50 -04:00
Vijay Janapa Reddi
8a4bc970e6 Default fmt_percent and range helpers to auto precision.
precision=None delegates to _resolve_display_precision so integer-like
percentages no longer hit the spurious-trailing-zero guard at render time.
2026-05-31 19:37:29 -04:00
Vijay Janapa Reddi
34a71ef144 mlsysim: add domain formatters and fix fmt_usd_range, fmt_multiple
Add fmt_power, fmt_energy, fmt_emissions, assert_qty_close, and auto-precision
for fmt_multiple; fix fmt_usd_range repeat_symbol scale handling.
2026-05-31 17:47:15 -04:00
Vijay Janapa Reddi
8192657159 Migrate direct quantity unit suffixes 2026-05-31 13:22:24 -04:00
Vijay Janapa Reddi
8535ba27fe Migrate compound scale suffixes 2026-05-31 12:45:31 -04:00
Vijay Janapa Reddi
8cd9290914 Migrate unit denominator suffixes 2026-05-31 12:30:02 -04:00
Vijay Janapa Reddi
8d156c2a38 Migrate time compound suffixes 2026-05-31 12:23:39 -04:00
Vijay Janapa Reddi
933429ea05 Add attributive time formatting 2026-05-31 12:16:49 -04:00
Vijay Janapa Reddi
965a328981 Migrate exact scale-word suffixes 2026-05-31 11:36:11 -04:00
Vijay Janapa Reddi
ab3ae0086b Complete time unit suffix migration 2026-05-31 11:10:42 -04:00
Vijay Janapa Reddi
a92c316a07 Migrate ml_systems time suffixes to fmt_time 2026-05-31 10:02:19 -04:00
Vijay Janapa Reddi
39556d81a5 Migrate QPS suffixes to fmt_rate 2026-05-31 09:34:32 -04:00
Vijay Janapa Reddi
4d34957a66 Migrate USD scale and range suffixes 2026-05-31 09:30:20 -04:00
Vijay Janapa Reddi
651f545404 Add structured formatter APIs and audit plan 2026-05-31 09:15:05 -04:00
Vijay Janapa Reddi
8b9b62cfda Replace raw fmt prefixes with marker flags 2026-05-31 08:06:46 -04:00
Vijay Janapa Reddi
d0d851c651 Require quantities for fmt_qty 2026-05-31 07:53:22 -04:00
Vijay Janapa Reddi
5c7367d52c fmt: make fmt_pp grammatically complete (singular/plural + attributive)
fmt_pp previously only emitted plural "N percentage points", which blocked
migrating the ~17 corpus sites that legitimately use the singular noun or the
hyphenated attributive adjective ("a 5 percentage-point gap").

Now:
- noun form agrees with the rendered number ("1 percentage point" vs
  "0.9 percentage points"); exact 1 renders singular.
- attributive=True yields the hyphenated compound-adjective form
  "N percentage-point" (style='prose' only; rejected for symbol).

Adds 6 tests covering singular/plural agreement, fractional plural, attributive
hyphenation, and the symbol+attributive rejection. All 67 fmt tests pass.
2026-05-30 22:12:56 -04:00
Vijay Janapa Reddi
8f9d9434c5 fmt(WS1): adjudicate 5 signed/>100% percents — fmt_percent allow_negative
Add allow_negative= to fmt_percent (widens the domain to [-max_ratio, max_ratio]
when a percentage is a SIGNED rate of change — ROI, cost delta — rather than a
bounded proportion). Default still refuses negatives, keeping the common case
strict. Adjudicate the 5 queued sites, all byte-identical to HEAD:

  data_selection ROI cluster (-81.8% / -9.1% / +81.8% / +809.1%): store rois as
    ratios (drop the *100 that only fed suffix='%') and format all four
    consistently via fmt_percent(..., allow_negative=True, max_ratio=9).
  ml_systems battery budget (320%): fmt_percent(..., max_ratio=4).
  model_serving cost increase (300%): fmt_percent(..., max_ratio=4).

The percent value-kind is now 100% migrated corpus-wide. gitignore the
transient adjudication-queue artifact.
2026-05-30 21:36:54 -04:00
Vijay Janapa Reddi
056c06937f fmt: add fmt_range (MIT en-dash ranges, both endpoints in full)
Typed/guarded range formatter owning the en-dash so authors never type a
hyphen between two values. MIT Press style: en-dash (U+2013), endpoints
written in full (1992-1993, never 1992-93). kind='number'|'usd', optional
unit appended once. Guards: finite endpoints + hi>=lo (inverted range is a
bug). Exported from mlsysim; 8 unit tests. Unblocks the MarkdownStr->typed
range migration (WS3).
2026-05-30 20:48:53 -04:00
Vijay Janapa Reddi
52a91a188b fmt: add typed guarded formatters + semantic-suffix enforcement
Introduce semantic value-kind formatters (fmt_percent with 0-1 ratio
guard, fmt_pp, fmt_multiple, fmt_count, fmt_ratio) plus a universal
finite guard, moving away from generic fmt(prefix=/suffix=). Add the
fmt_semantic_suffix checker (forbids %/percent/x/scale glyphs in
suffix=) wired as an opt-in math scope, update math_canonical messaging
to the new style= API, and land the AST audit tooling.

Foundation for the corpus-wide formatting migration; no .qmd changes yet.
2026-05-30 19:57:04 -04:00
Vijay Janapa Reddi
e73682e2b8 Add fmt_usd helper and route all currency formatting through it
Currency was the only fmt_* value-kind without its own helper, so every
dollar amount carried a hand-escaped prefix="\$" -- the exact pattern that
silently breaks Pandoc/LaTeX when the escape is forgotten. Introduce
fmt_usd() (the currency sibling of fmt_percent): it owns the escaped \$,
the ~ approximation marker, and whole-dollar rounding, and never emits a
literal "USD".

- mlsysim.fmt: add fmt_usd; fmt_qty now refuses currency units (was a
  dormant " USD" leak); export fmt_usd from mlsysim.
- Migrate all 271 currency call sites across both volumes to fmt_usd.
- currency_style check: forbid $ in any prefix=/suffix= and enforce the
  fmt_usd path; register fmt_usd as a canonical helper in math_canonical.
- units.py: document dollar (magnitude) vs fmt_usd (display) split.
- Restore canonical $\times$ math notation in the vol2 glossary.

Validated: numbers/currency/math/code checks clean; 22 fmt + 9 checker +
499 mlsysim tests pass; 4 currency-heavy chapters render with $ output
and no leaked \$ or visible USD.
2026-05-30 18:43:36 -04:00
Vijay Janapa Reddi
3bb5d63d0f feat(mlsysim): add fmt_qty for LEGO unit-safe output
Canonical path from pint Quantity to display string with matched
magnitude and suffix, preventing W/mW class display bugs.
2026-05-25 20:03:54 -04:00
Vijay Janapa Reddi
e7f2221510 Add fmt_int and layered precision safety for narrative numbers
Introduce fmt_int() for explicit integer display, extend fmt() runtime
guards (zero loss, silent rounding, spurious .0), add unit tests, and
expand audit_math_canonical with static checks including fmt(round|int)
bypass detection. Update introduction call sites to fmt_int().
2026-05-24 10:39:40 -04:00