A (per-base read-and-sum per 80-step interval), W (window + step(80) + one read) and W1 (window + 80 x step(1)) over equal simulated duration from the same fresh state and warm-up, 3 interleaved repeats. Bitwise populations and per-interval total impulses (documented engineering tolerance) are compared outside timing; health checks untimed. Records candidate source identity (revision, dirty flag, file hashes) and does not use or modify frozen refined-DFG manifests/results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
"""CPU contract of the A-versus-window timing harness (no CUDA)."""
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "validation"))
|
|
import time_window_dfg as w # noqa: E402
|
|
|
|
|
|
class WindowTimingContract(unittest.TestCase):
|
|
def test_interval_and_variants(self):
|
|
self.assertEqual(w.INTERVAL, 80)
|
|
self.assertEqual(w.VARIANTS, ("A", "W", "W1"))
|
|
|
|
def test_components(self):
|
|
obs = dict(total=dict(impulse=np.array([1., 2.]), angular_impulse=3., mass_into_fluid=4.))
|
|
np.testing.assert_array_equal(w.components(obs), [1., 2., 3., 4.])
|
|
|
|
def test_interval_comparison(self):
|
|
ref = np.array([[1., -1., 0., 0.]])
|
|
scale = np.array([[10., 10., 1., 1.]])
|
|
self.assertEqual(w.compare_intervals(ref, scale, ref.copy()), 0.)
|
|
near = ref + np.array([[5e-9, 0., 0., 0.]])
|
|
self.assertLessEqual(w.compare_intervals(ref, scale, near), 1.)
|
|
far = ref + np.array([[1e-7, 0., 0., 0.]])
|
|
self.assertGreater(w.compare_intervals(ref, scale, far), 1.)
|
|
zero = np.zeros((1, 4))
|
|
self.assertGreater(w.compare_intervals(zero, zero, zero + 1e-12), 1.) # floor, no div-by-0
|
|
|
|
def test_candidate_identity_records_files(self):
|
|
identity = w.candidate_identity(Path(__file__).resolve().parents[2])
|
|
self.assertIn("checkout_revision", identity)
|
|
self.assertEqual(set(identity["sha256"]), set(w.CANDIDATE_FILES))
|
|
|
|
|
|
if __name__ == "__main__": unittest.main()
|