test: portable few-ULP check for recomputed shear eps metadata

Cross-platform replay of the frozen assessor returned INVALID_SET because
recomputed eps(128) differed from the Horsea receipt by one ULP. Compare
only that derived float within 4 ULPs (close_ulps); hashes, case identity,
other metadata and scientific thresholds stay exact. Tests accept the
observed one/two-ULP differences and reject 1e-12 relative, 2x, string,
NaN and missing values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-10-19 01:15:59 +00:00
co-authored by Claude Opus 5.5
parent 5fb95f5f4d
commit 9748ef91ef
3 changed files with 35 additions and 1 deletions
@@ -13,6 +13,7 @@ Taylor-Green-specific checks are replaced by shear-wave metadata and physics.
import argparse
import hashlib
import json
import math
from pathlib import Path
import assess_projected_pairs as tg
@@ -36,11 +37,26 @@ PER_CASE = ("complete_times", "scales", "actual_builds", "reference", "runtime_s
"patch", "workload")
METADATA_ULPS = 4
def close_ulps(recorded, expected, ulps=METADATA_ULPS):
"""Portable check for recomputed float metadata only (e.g. eps = |k|^2).
The recorded value comes from another runtime/libm, so exact equality can
fail by one ULP (observed: 0.012047856934923534 Horsea vs ...532 here).
A few ULPs is far below any meaningful change; hashes, case identity and
scientific thresholds stay exact.
"""
return (isinstance(recorded, float) and math.isfinite(recorded)
and abs(recorded - expected) <= ulps * math.ulp(max(abs(recorded), abs(expected))))
def metadata_ok(record, n):
return (record.get("flow") == "shear_wave" and record.get("mode") == list(sw.MODE)
and record.get("polarization") == sw.E.tolist()
and record.get("angle_deg") == sw.ANGLE_DEG and record.get("phase") == sw.PHI
and record.get("eps") == sw.eps(n)
and close_ulps(record.get("eps"), sw.eps(n))
and record.get("numerics") == tg.NUMERICS
and record.get("initialization") == sw.INITIALIZATION
and record.get("limits") == sw.LIMITS
@@ -427,6 +427,19 @@ class ContractTests(unittest.TestCase):
self.assertTrue(result["contract_valid"], [k for k, v in result["checks"].items() if not v])
self.assertEqual(result["status"], "PASS")
def test_eps_metadata_is_portable_but_bounded(self):
import assess_shear_wave
self.assertTrue(assess_shear_wave.close_ulps(0.012047856934923534, 0.012047856934923532))
exact = sw.eps(128)
for value, ok in ((math.nextafter(exact, 1.0), True),
(math.nextafter(math.nextafter(exact, 0.0), 0.0), True),
(exact * (1 + 1e-12), False), (exact * 2, False),
(str(exact), False), (float("nan"), False), (None, False)):
records = [dict(r) for r in self.records]
records[2]["eps"] = value
status = self.assess(records, "r")["status"]
self.assertEqual(status == "PASS", ok, (value, status))
def test_reproduced_false_passes_are_rejected(self):
a = self.assess
self.assertEqual(a(self.records[:2], "r")["status"], "INVALID_SET") # empty refined