Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
positive_threshold_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Positive-threshold review surface validation for performance evidence.
3 
4 Evaluates the bounded representative structured review set against the sequential
5 baseline and records per-case positive-threshold verdicts without turning the
6 result into a universal acceleration claim.
7 
8 Run with:
9  python benchmarks/density_matrix/performance_evidence/positive_threshold_validation.py
10 """
11 
12 from __future__ import annotations
13 
14 import sys
15 from pathlib import Path
16 
17 REPO_ROOT = Path(__file__).resolve().parents[3]
18 if str(REPO_ROOT) not in sys.path:
19  sys.path.insert(0, str(REPO_ROOT))
20 
21 from benchmarks.density_matrix.performance_evidence.common import (
22  performance_evidence_output_dir,
23 )
24 from benchmarks.density_matrix.performance_evidence.records import (
25  build_performance_evidence_benchmark_records,
26 )
27 from benchmarks.density_matrix.performance_evidence.validation_support import (
28  assemble_record_schema_case_bundle,
29 )
30 from benchmarks.density_matrix.validation_scaffold import (
31  require_bundle_fields,
32  run_case_slice_cli,
33 )
34 
35 SUITE_NAME = "performance_evidence_positive_threshold"
36 ARTIFACT_FILENAME = "positive_threshold_bundle.json"
37 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("positive_threshold")
38 ARTIFACT_CORE_FIELDS = (
39  "suite_name",
40  "status",
41  "record_schema_version",
42  "software",
43  "selected_candidate",
44  "summary",
45  "cases",
46 )
47 
48 
49 def build_positive_threshold_cases() -> list[dict]:
50  return [
51  case
53  if case["representative_review_case"]
54  ]
55 
56 
57 def build_positive_threshold_bundle(cases: list[dict]) -> dict:
58  review_surface_pass = all(
59  case["sequential_median_runtime_ms"] is not None
60  and case["fused_median_runtime_ms"] is not None
61  and case["sequential_median_peak_rss_kb"] is not None
62  and case["fused_median_peak_rss_kb"] is not None
63  for case in cases
64  )
65  status = "pass" if review_surface_pass and len(cases) > 0 else "fail"
66  summary = {
67  "total_cases": len(cases),
68  "actual_fused_review_cases": sum(case["actual_fused_execution"] for case in cases),
69  "positive_threshold_pass_cases": sum(case["positive_threshold_pass"] for case in cases),
70  "diagnosis_candidate_cases": sum(
71  (not case["positive_threshold_pass"]) and case["counted_supported_benchmark_case"]
72  for case in cases
73  ),
74  "review_groups": sorted(
75  {case["review_group_id"] for case in cases if case["review_group_id"] is not None}
76  ),
77  }
78  bundle = assemble_record_schema_case_bundle(SUITE_NAME, status, summary, cases)
79  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Positive-threshold bundle")
80  return bundle
81 
82 
83 def main(argv: list[str] | None = None) -> int:
84  return run_case_slice_cli(
85  argv,
86  build_cases=build_positive_threshold_cases,
87  build_artifact_bundle=build_positive_threshold_bundle,
88  artifact_filename=ARTIFACT_FILENAME,
89  default_output_dir=DEFAULT_OUTPUT_DIR,
90  description=__doc__ or "",
91  output_dir_help="Directory to write the positive-threshold bundle into.",
92  quiet_report=lambda b: print(
93  "positive_threshold_pass_cases={positive_threshold_pass_cases}, diagnosis_candidate_cases={diagnosis_candidate_cases}".format(
94  **b["summary"]
95  )
96  ),
97  )
98 
99 
100 if __name__ == "__main__":
101  raise SystemExit(main())
def build_performance_evidence_benchmark_records()