mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
Add optimization O05: batched random-direction kernels that reproduce the reference loops, plus validated low-rank sketches with an explicit error budget. The reference loops stay the default. - Batched gate, discovery and subspace nulls keep draw order, generator state, norm matching, pooling, orientation folding and percentile semantics; identical rows are projected once so exact ties survive. Declared tolerance 1e-12 with identical decisions; observed 0.0. - select_rank keeps both residual variance and class-contrast loss within budget, measured exactly, and reports the variance-only rank; it returns inconclusive when no rank qualifies. - The sketch gate null is approximate only when the spectrum test passes, an exact audit stays within 0.005 AUC and no threshold falls inside the band; otherwise it recomputes exactly. It is refused in enforce mode. The observed AUC is never approximated. - A benchmark module reports wall time, peak memory, subspace angles, null errors and decision disagreement (timings host-specific). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
3.0 KiB
Python
68 lines
3.0 KiB
Python
"""The O05 benchmark report: produced, complete and agreement-checked (timings not asserted)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from obliteratus.analysis import kernel_benchmark as kb
|
|
from obliteratus.analysis import kernel_fixtures as kf
|
|
|
|
pytestmark = pytest.mark.cpu
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def report():
|
|
return kb.run_benchmark(quick=True)
|
|
|
|
|
|
def test_report_covers_every_arm_with_host_labelled_costs(report):
|
|
assert report["schema"] == kb.SCHEMA and "host-specific" in report["host_note"]
|
|
assert [case["fixture"] for case in report["gate"]] == list(kf.GATE_FIXTURES)
|
|
for case in report["gate"]:
|
|
for arm in (case["reference"]["cost"], case["batched"]["cost"], case["sketch"]["cost"]):
|
|
assert len(arm["wall_seconds"]) == 1 and "peak_rss_growth_bytes" in arm
|
|
json.dumps(report)
|
|
|
|
|
|
def test_batched_arms_agree_and_sketch_never_flips_a_gate_decision(report):
|
|
for case in report["gate"]:
|
|
batched = case["batched"]["agreement"]
|
|
assert batched["within_tolerance"] and batched["decision_disagreements"] == 0
|
|
assert case["batched"]["gate_decision"] == case["reference"]["gate_decision"]
|
|
sketch = case["sketch"]
|
|
if sketch["status"] == "approximate":
|
|
assert sketch["agreement"]["decision_disagreements"] == 0
|
|
assert sketch["gate_decision"] == case["reference"]["gate_decision"]
|
|
else:
|
|
assert sketch["status"] == "inconclusive" and sketch["reason"]
|
|
assert report["subspace"]["subspace_null"]["within_tolerance"]
|
|
assert not report["subspace"]["verdict_disagreement"]
|
|
assert report["discovery"]["agreement"]["within_tolerance"]
|
|
|
|
|
|
def test_tail_fixture_reports_the_signal_variance_alone_would_lose(report):
|
|
tail = next(case for case in report["low_rank"] if case["fixture"] == "tail_signal")
|
|
assert tail["variance_only_signal_loss"] > report["budget"]["signal"]
|
|
assert tail["exact"]["selected_rank"] > tail["exact"]["variance_only_rank"]
|
|
assert not tail["rank_disagreement"] and max(tail["subspace_angles_deg"]) < 1.0
|
|
flat = next(case for case in report["low_rank"] if case["fixture"] == "flat")
|
|
assert flat["exact"]["status"] == "inconclusive" and "subspace_angles_deg" not in flat
|
|
|
|
|
|
def test_measure_without_proc_and_cli_output(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(kb, "_rss", lambda: None)
|
|
result, cost = kb.measure(lambda: 7, repeats=2, warmup=0)
|
|
assert result == 7 and len(cost["wall_seconds"]) == 2
|
|
assert cost["peak_rss_growth_bytes"] is None
|
|
monkeypatch.setattr(kb, "run_benchmark", lambda **kw: {"called": kw})
|
|
threads = []
|
|
monkeypatch.setattr(kb.torch, "set_num_threads", threads.append)
|
|
out = tmp_path / "bench.json"
|
|
assert kb.main(["--output", str(out), "--quick", "--threads", "1"]) == 0
|
|
assert json.loads(out.read_text()) == {"called": {"quick": True, "repeats": 1}}
|
|
assert threads == [1]
|
|
with pytest.raises(SystemExit):
|
|
kb.main(["--output", str(out), "--repeats", "0"])
|