Files
cs249r_book/mlsysim/tests/test_schema_units.py
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

62 lines
2.0 KiB
Python

import pytest
from pydantic import ValidationError
from mlsysim.core.units import Q_, ureg
from mlsysim.hardware.types import ComputeCore, MemoryHierarchy
from mlsysim.models.types import TransformerWorkload
from mlsysim.systems.types import NetworkFabric
def test_memory_capacity_requires_storage_units():
with pytest.raises(ValidationError, match="capacity"):
MemoryHierarchy(capacity=80, bandwidth=Q_("1 TB/s"))
def test_memory_bandwidth_requires_rate_units():
with pytest.raises(ValidationError, match="bandwidth"):
MemoryHierarchy(capacity=Q_("80 GB"), bandwidth=Q_("1 second"))
def test_memory_bandwidth_rejects_operation_rate_units():
with pytest.raises(ValidationError, match="bandwidth"):
MemoryHierarchy(capacity=Q_("80 GB"), bandwidth=Q_("1 TFLOP/s"))
def test_compute_flops_rejects_data_rate_units():
with pytest.raises(ValidationError, match="peak_flops"):
ComputeCore(peak_flops=Q_("900 GB/s"))
def test_network_bandwidth_accepts_bit_and_byte_rates():
bit_rate = NetworkFabric(name="IB", bandwidth=Q_("400 Gbit/s"))
byte_rate = NetworkFabric(name="NVLink", bandwidth=Q_("900 GB/s"))
assert bit_rate.bandwidth.check(ureg.bit / ureg.second)
assert byte_rate.bandwidth.check(ureg.bit / ureg.second)
def test_network_fabric_rejects_unknown_fields():
with pytest.raises(ValidationError, match="Extra inputs|extra_forbidden"):
NetworkFabric(name="IB", bandwidth=Q_("400 Gbit/s"), stray_field=True)
def test_workload_parameters_require_count_units():
with pytest.raises(ValidationError, match="parameters"):
TransformerWorkload(
name="Bad LLM",
architecture="Transformer",
parameters=70e9,
layers=80,
)
def test_workload_flops_rejects_data_units():
with pytest.raises(ValidationError, match="inference_flops"):
TransformerWorkload(
name="Bad LLM",
architecture="Transformer",
parameters=Q_("70e9 param"),
layers=80,
inference_flops=Q_("80 GB"),
)