mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 18:28:19 +00:00
test(valid-detection-benchmark): add the opt-in full-scale rehearsal
One test runs the whole lifecycle at 840 inputs with every planned arm and the per-population review subject, so a correctly reviewed full-scale run completes for the first time. It is skipped unless OPENULTRASAST_FULL_SCALE_REHEARSAL=1 and records per-stage wall-clock seconds. The default path is unchanged: the new ScaleLifecycle arguments default to None and the timing wrapper always calls its stage.
This commit is contained in:
@@ -8,12 +8,18 @@ per-batch nonzero read receipts, cold/warm and per-arm runtime receipts, a
|
|||||||
bounded execution lane whose busy refusal is an impairment rather than a
|
bounded execution lane whose busy refusal is an impairment rather than a
|
||||||
detector result or an infrastructure diagnosis, and truncated streams that
|
detector result or an infrastructure diagnosis, and truncated streams that
|
||||||
report impairment instead of a partial clean result.
|
report impairment instead of a partial clean result.
|
||||||
|
|
||||||
|
One opt-in rehearsal (OPENULTRASAST_FULL_SCALE_REHEARSAL=1) runs the whole
|
||||||
|
lifecycle at the full 840-input scale with per-stage wall-clock times; it is
|
||||||
|
skipped by default because it takes twenty minutes or more.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import tracemalloc
|
import tracemalloc
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
@@ -32,6 +38,7 @@ from valid_benchmark_scale_support import ( # noqa: E402
|
|||||||
CORE_REPLAY_DECLARATION,
|
CORE_REPLAY_DECLARATION,
|
||||||
EXECUTION_TIER_INPUTS,
|
EXECUTION_TIER_INPUTS,
|
||||||
EXECUTION_TIER_PUSHES_PER_ECOSYSTEM,
|
EXECUTION_TIER_PUSHES_PER_ECOSYSTEM,
|
||||||
|
SCALE_INPUTS,
|
||||||
SCALE_REQUIRED_PER_POSITIVE,
|
SCALE_REQUIRED_PER_POSITIVE,
|
||||||
ScaleLifecycle,
|
ScaleLifecycle,
|
||||||
StreamFault,
|
StreamFault,
|
||||||
@@ -55,10 +62,13 @@ from valid_benchmark_scale_support import ( # noqa: E402
|
|||||||
)
|
)
|
||||||
|
|
||||||
from benchmarks.valid import run # noqa: E402
|
from benchmarks.valid import run # noqa: E402
|
||||||
from benchmarks.valid.workflow_outcome import WorkflowStatus # noqa: E402
|
from benchmarks.valid.workflow_outcome import WorkflowReasonCode, WorkflowStatus # noqa: E402
|
||||||
from openultrasast.core.custody import PopulationStatus # noqa: E402
|
from openultrasast.core.custody import PopulationStatus # noqa: E402
|
||||||
from openultrasast.core.evaluation_measurement import MetricId # noqa: E402
|
from openultrasast.core.evaluation_measurement import MetricId # noqa: E402
|
||||||
|
|
||||||
|
FULL_SCALE_REHEARSAL_VARIABLE = "OPENULTRASAST_FULL_SCALE_REHEARSAL"
|
||||||
|
FULL_SCALE_REHEARSAL_TIMINGS = Path("/tmp/opencode/item9-full-scale-timings.json")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def population():
|
def population():
|
||||||
@@ -277,6 +287,23 @@ def test_incomplete_scale_stream_reports_impairment_never_partial_clean(fault: S
|
|||||||
assert vocabulary_findings(report.decode("ascii")) == ()
|
assert vocabulary_findings(report.decode("ascii")) == ()
|
||||||
|
|
||||||
|
|
||||||
|
def test_full_scale_rehearsal_completes_the_lifecycle_at_840_inputs() -> None:
|
||||||
|
"""Opt-in rehearsal of the real population size, skipped by default: twenty minutes or more."""
|
||||||
|
if os.environ.get(FULL_SCALE_REHEARSAL_VARIABLE) != "1":
|
||||||
|
pytest.skip(f"set {FULL_SCALE_REHEARSAL_VARIABLE}=1 to opt in: two 840-input executions, 20 minutes or more")
|
||||||
|
population = scale_population()
|
||||||
|
identity = _population_identity(population)
|
||||||
|
timings = _RehearsalTimings()
|
||||||
|
started = time.perf_counter()
|
||||||
|
try:
|
||||||
|
chain = ScaleLifecycle(population=population, timings=timings)
|
||||||
|
finally:
|
||||||
|
timings["total_s"] = round(time.perf_counter() - started, 3)
|
||||||
|
assert SCALE_INPUTS == 840, "the rehearsal no longer names the real population size"
|
||||||
|
_assert_full_scale_lifecycle(chain, SCALE_INPUTS)
|
||||||
|
assert _population_identity(population) == identity, "the rehearsal changed the cached scale population"
|
||||||
|
|
||||||
|
|
||||||
def _operator_environ():
|
def _operator_environ():
|
||||||
from test_valid_benchmark_run import _environ # noqa: E402
|
from test_valid_benchmark_run import _environ # noqa: E402
|
||||||
|
|
||||||
@@ -317,3 +344,63 @@ def _saturated_lane():
|
|||||||
lane = BoundedExecutionLane(maxsize=2)
|
lane = BoundedExecutionLane(maxsize=2)
|
||||||
record = stream_with_lane(probe_objects_factory(840), 60, 840, lane)
|
record = stream_with_lane(probe_objects_factory(840), 60, 840, lane)
|
||||||
return lane, record
|
return lane, record
|
||||||
|
|
||||||
|
|
||||||
|
def _assert_full_scale_lifecycle(chain: ScaleLifecycle, inputs: int) -> None:
|
||||||
|
"""Every stage returned its product, the replay is published, nothing is impaired or interrupted."""
|
||||||
|
assert len(chain.population.manifest.input_digests) == inputs
|
||||||
|
assert chain.execution.refusal_reason is None and chain.execution.impaired_outcome is None
|
||||||
|
assert chain.admission_review.subject_digest == chain.execution.manifest_subject_digest
|
||||||
|
assert chain.execution.admission_manifest is not None
|
||||||
|
assert chain.release is not None and chain.release.refusal_reason is None
|
||||||
|
assert chain.replay is not None
|
||||||
|
assert chain.publication is not None and chain.publication.replay_reference is not None
|
||||||
|
assert chain.publication.outcome.status is WorkflowStatus.COMPLETED
|
||||||
|
assert chain.publication.replay_digest == chain.replay.replay_digest
|
||||||
|
outcome = chain.result.outcome
|
||||||
|
assert outcome.status is WorkflowStatus.COMPLETED
|
||||||
|
assert outcome.status is not WorkflowStatus.IMPAIRED and WorkflowReasonCode.INTERRUPTED not in outcome.reason_codes
|
||||||
|
assert outcome.reason_codes == () and outcome.labels_spent is True
|
||||||
|
assert outcome.counts.completed_arms == outcome.counts.planned_arms == len(PLANNED_ARMS)
|
||||||
|
assert outcome.evaluation_replay_ref is not None
|
||||||
|
assert {arm for arm, runtime_ms in chain.arm_runtimes if runtime_ms > 0} == set(component_arm_ids(chain.population))
|
||||||
|
assert tuple(report.baseline.arm_id for report in chain.replay.reports) == PLANNED_ARMS
|
||||||
|
unique = {case.underlying_push_digest for group in chain.replay.cases_by_arm for case in group.cases}
|
||||||
|
assert chain.replay.whole_population_coverage.underlying_push_count == len(unique) == inputs
|
||||||
|
first = chain.result.report_bytes
|
||||||
|
assert first == chain.render_again()
|
||||||
|
assert redaction_findings(first) == ()
|
||||||
|
document = json.loads(first)
|
||||||
|
assert document["status"] == "completed"
|
||||||
|
assert {arm["arm_id"] for arm in document["replay"]["arms"]} == set(PLANNED_ARMS)
|
||||||
|
receipt = run_streaming_validation(case_objects_factory(chain.population), 64, inputs)
|
||||||
|
assert receipt.status is WorkflowStatus.COMPLETED and receipt.reason_codes == ()
|
||||||
|
assert receipt.consumed_objects == inputs and receipt.all_batches_nonzero
|
||||||
|
|
||||||
|
|
||||||
|
def _population_identity(population) -> tuple:
|
||||||
|
"""What the other tests of this module read from the cached scale population."""
|
||||||
|
return (
|
||||||
|
population.freeze.population_digest,
|
||||||
|
population.freeze.freeze_digest,
|
||||||
|
population.manifest.manifest_digest,
|
||||||
|
population.plan.plan_digest,
|
||||||
|
population.plan_manifest.manifest_digest,
|
||||||
|
population.labels,
|
||||||
|
len(population.cases),
|
||||||
|
len(population.selection.pushes),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class _RehearsalTimings(dict):
|
||||||
|
"""Stage wall-clock seconds, written through after every stage so a killed rehearsal leaves its numbers."""
|
||||||
|
|
||||||
|
def __setitem__(self, key: str, value: float) -> None:
|
||||||
|
super().__setitem__(key, value)
|
||||||
|
FULL_SCALE_REHEARSAL_TIMINGS.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
FULL_SCALE_REHEARSAL_TIMINGS.write_text(_timings_text(self), encoding="ascii")
|
||||||
|
print(f"full-scale rehearsal wall-clock seconds, {key}: {value}")
|
||||||
|
|
||||||
|
|
||||||
|
def _timings_text(timings: dict[str, float]) -> str:
|
||||||
|
return json.dumps(timings, indent=2, sort_keys=True) + "\n"
|
||||||
|
|||||||
@@ -608,20 +608,24 @@ def _execution_subject(environment: E2EEnvironment, case: E2EPopulation) -> str:
|
|||||||
|
|
||||||
|
|
||||||
class ScaleLifecycle:
|
class ScaleLifecycle:
|
||||||
"""One execution-tier lifecycle: timed arms, spend, release, projection, replay, reporting.
|
"""One lifecycle over one population: timed arms, spend, release, projection, replay, reporting.
|
||||||
|
|
||||||
A single committed run-command lifecycle over the execution-tier
|
A single committed run-command lifecycle over the population (the
|
||||||
population: the preflight harvest mints the admission-review subject,
|
execution-tier population unless the caller supplies another, such as the
|
||||||
the run stages execute every planned arm (per-arm runtime receipts are
|
full 840-input scale population): the preflight harvest mints the
|
||||||
retained through the timing adapter proxy), commit the one shared spend,
|
admission-review subject for that population, the run stages execute every
|
||||||
derive the exact-scope projection inputs, publish the one validated core
|
planned arm (per-arm runtime receipts are retained through the timing
|
||||||
replay, and render the deterministic redacted operator report.
|
adapter proxy), commit the one shared spend, derive the exact-scope
|
||||||
|
projection inputs, publish the one validated core replay, and render the
|
||||||
|
deterministic redacted operator report. A caller-supplied timings record
|
||||||
|
receives the wall-clock seconds of each stage.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self, population: E2EPopulation | None = None, timings: dict[str, float] | None = None) -> None:
|
||||||
self.population = execution_tier_population()
|
self.timings = timings
|
||||||
|
self.population = execution_tier_population() if population is None else population
|
||||||
harvest = E2EEnvironment(self.population)
|
harvest = E2EEnvironment(self.population)
|
||||||
subject = _execution_subject(harvest, self.population)
|
subject = self._timed("execution_harvest_s", lambda: _execution_subject(harvest, self.population))()
|
||||||
self.environment = E2EEnvironment(self.population)
|
self.environment = E2EEnvironment(self.population)
|
||||||
self.case = self.population
|
self.case = self.population
|
||||||
self.admission_review = _attestation(subject, _digest("scale-admission-producer"), self.population.disclosure)
|
self.admission_review = _attestation(subject, _digest("scale-admission-producer"), self.population.disclosure)
|
||||||
@@ -643,7 +647,20 @@ class ScaleLifecycle:
|
|||||||
)
|
)
|
||||||
self.execution = self.environment.last_execution
|
self.execution = self.environment.last_execution
|
||||||
self.arm_runtimes = tuple(self.environment.adapter.arm_runtimes)
|
self.arm_runtimes = tuple(self.environment.adapter.arm_runtimes)
|
||||||
self.projection = self._projection()
|
self.projection = self._timed("projection_s", self._projection)()
|
||||||
|
|
||||||
|
def _timed(self, stage_name: str, stage):
|
||||||
|
"""Wrap one stage, always called as before; its wall-clock seconds land in the record when one was supplied."""
|
||||||
|
|
||||||
|
def timed(*args):
|
||||||
|
started = time.perf_counter()
|
||||||
|
try:
|
||||||
|
return stage(*args)
|
||||||
|
finally:
|
||||||
|
if self.timings is not None:
|
||||||
|
self.timings[stage_name] = round(time.perf_counter() - started, 3)
|
||||||
|
|
||||||
|
return timed
|
||||||
|
|
||||||
def _operator_context(self):
|
def _operator_context(self):
|
||||||
return run.bound_operator_context(
|
return run.bound_operator_context(
|
||||||
@@ -719,7 +736,12 @@ class ScaleLifecycle:
|
|||||||
)
|
)
|
||||||
return self.publication
|
return self.publication
|
||||||
|
|
||||||
return run.BenchmarkRunStagesV1(_execution, _spend, _replay, _publication)
|
return run.BenchmarkRunStagesV1(
|
||||||
|
self._timed("execution_s", _execution),
|
||||||
|
self._timed("spend_s", _spend),
|
||||||
|
self._timed("replay_s", _replay),
|
||||||
|
self._timed("publication_s", _publication),
|
||||||
|
)
|
||||||
|
|
||||||
def _projection(self):
|
def _projection(self):
|
||||||
assert self.release is not None
|
assert self.release is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user