Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
metric_surface_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Comparable metric surface validation for performance evidence.
3 
4 Verifies that counted and diagnosis-only benchmark cases share one comparable
5 metric vocabulary, including auditable repeated-timing fields for the
6 representative review set.
7 
8 Run with:
9  python benchmarks/density_matrix/performance_evidence/metric_surface_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_metric_surface"
36 ARTIFACT_FILENAME = "metric_surface_bundle.json"
37 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("metric_surface")
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_metric_surface_cases() -> list[dict]:
51 
52 
53 def build_metric_surface_bundle(cases: list[dict]) -> dict:
54  metric_surface_pass = all(
55  case["runtime_ms"] is not None
56  and case["peak_rss_kb"] is not None
57  and case["planning_time_ms"] is not None
58  and case["partition_count"] is not None
59  and case["max_partition_span"] is not None
60  and case["runtime_path"] is not None
61  for case in cases
62  ) and all(
63  (
64  case["representative_review_case"]
65  and case["timing_mode"] == "median_3"
66  and len(case["sequential_runtime_ms_samples"]) == 3
67  and len(case["fused_runtime_ms_samples"]) == 3
68  )
69  or (not case["representative_review_case"] and case["timing_mode"] == "single_run")
70  for case in cases
71  )
72  status = "pass" if metric_surface_pass else "fail"
73  summary = {
74  "total_cases": len(cases),
75  "representative_review_cases": sum(case["representative_review_case"] for case in cases),
76  "counted_supported_cases": sum(case["counted_supported_benchmark_case"] for case in cases),
77  "diagnosis_only_cases": sum(case["diagnosis_only_case"] for case in cases),
78  "single_run_cases": sum(case["timing_mode"] == "single_run" for case in cases),
79  "median_timed_cases": sum(case["timing_mode"] == "median_3" for case in cases),
80  }
81  bundle = assemble_record_schema_case_bundle(SUITE_NAME, status, summary, cases)
82  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Metric surface bundle")
83  return bundle
84 
85 
86 def main(argv: list[str] | None = None) -> int:
87  return run_case_slice_cli(
88  argv,
89  build_cases=build_metric_surface_cases,
90  build_artifact_bundle=build_metric_surface_bundle,
91  artifact_filename=ARTIFACT_FILENAME,
92  default_output_dir=DEFAULT_OUTPUT_DIR,
93  description=__doc__ or "",
94  output_dir_help="Directory to write the metric surface bundle into.",
95  quiet_report=lambda b: print(
96  "median_timed_cases={median_timed_cases}, single_run_cases={single_run_cases}".format(
97  **b["summary"]
98  )
99  ),
100  )
101 
102 
103 if __name__ == "__main__":
104  raise SystemExit(main())
def build_performance_evidence_benchmark_records()