Files
SolitaryThinker db866dfb04 [misc] v2: simplify docstrings/comments + drop deleted-design-doc citations
Sweep all 296 v2 modules: simplify verbose docstrings/comments and remove 376 dangling
"(design_vN §X)" citations to the now-deleted design docs (v2/README.md is the source of
truth). Comment/docstring-only — AST-verified code-identical; the CPU suite holds at 237
passed / 5 pre-existing. Also applies yapf + ruff --fix auto-fixes (import ordering,
forward-ref annotation de-quoting under `from __future__ import annotations`; behavior-
neutral, suite-confirmed) and adds the legitimate domain terms mot/clen/te to the codespell
ignore-list. Remaining ruff (24) + mypy (68 no-untyped-call) findings are pre-existing v2
debt, untouched here.
2026-06-19 20:54:59 +00:00

46 lines
1.8 KiB
Python

"""ParityAligner + consistency ladder."""
from __future__ import annotations
import numpy as np
from v2.parity import ConsistencyLevel, ParityAligner, array_diff, bit_identical, within
def test_aligner_no_divergence_on_identical_runs():
ref, cur = ParityAligner(), ParityAligner()
for s in range(3):
v = np.ones((2, 2)) * s
ref.record_tap(s, "latents", v)
cur.record_tap(s, "latents", v.copy())
assert cur.first_divergence(ref) is None
def test_aligner_reports_first_divergence_in_step_order():
ref, cur = ParityAligner(), ParityAligner()
ref.record_tap(0, "l", np.zeros(2)); cur.record_tap(0, "l", np.zeros(2))
ref.record_tap(1, "l", np.zeros(2)); cur.record_tap(1, "l", np.ones(2)) # diverges here
ref.record_tap(2, "l", np.zeros(2)); cur.record_tap(2, "l", np.full(2, 9))
d = cur.first_divergence(ref)
assert d is not None and d.where == "l@1" # first, not the bigger step-2 diff
def test_aligner_respects_per_tap_tolerance():
ref, cur = ParityAligner(), ParityAligner()
ref.set_tolerance("l", atol=0.1)
cur.set_tolerance("l", atol=0.1)
ref.record_tap(0, "l", np.zeros(2)); cur.record_tap(0, "l", np.full(2, 0.05))
assert cur.first_divergence(ref) is None # within tolerance
cur.record_tap(0, "l", np.full(2, 0.05)) # idempotent re-record
def test_consistency_ladder_ranks_increase():
assert ConsistencyLevel.C0.rank < ConsistencyLevel.C1.rank < ConsistencyLevel.C2.rank
assert ConsistencyLevel.C2.rank < ConsistencyLevel.C3.rank < ConsistencyLevel.C4.rank
def test_numeric_helpers():
assert bit_identical(np.ones(3), np.ones(3))
assert within(np.ones(3), np.ones(3) + 1e-9, atol=1e-6)
abs_d, rel_d = array_diff(np.array([1.0]), np.array([2.0]))
assert abs_d == 1.0 and rel_d == 0.5