Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
benchmark_bundle_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Shared benchmark package validation for performance evidence.
3 
4 Packages counted, diagnosis-only, and excluded evidence together with explicit
5 boundary records for downstream publication consumers.
6 
7 Run with:
8  python benchmarks/density_matrix/performance_evidence/benchmark_bundle_validation.py
9 """
10 
11 from __future__ import annotations
12 
13 import argparse
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.bundle import (
22  build_performance_evidence_benchmark_package_payload,
23 )
24 from benchmarks.density_matrix.performance_evidence.common import (
25  PERFORMANCE_EVIDENCE_BENCHMARK_PACKAGE_SCHEMA_VERSION,
26  build_package_software_metadata,
27  performance_evidence_output_dir,
28  write_artifact_bundle,
29 )
30 from benchmarks.density_matrix.validation_scaffold import require_bundle_fields
31 
32 SUITE_NAME = "performance_evidence_benchmark_package"
33 ARTIFACT_FILENAME = "benchmark_package_bundle.json"
34 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("benchmark_package")
35 ARTIFACT_CORE_FIELDS = (
36  "suite_name",
37  "status",
38  "schema_version",
39  "software",
40  "selected_candidate",
41  "summary",
42  "required_artifacts",
43  "cases",
44  "negative_cases",
45 )
46 
47 
50  bundle = {
51  "suite_name": SUITE_NAME,
52  "status": "pass"
53  if payload["summary"]["total_cases"] == len(payload["cases"])
54  and payload["summary"]["correctness_evidence_boundary_cases"] == len(payload["negative_cases"])
55  else "fail",
56  "schema_version": PERFORMANCE_EVIDENCE_BENCHMARK_PACKAGE_SCHEMA_VERSION,
57  "software": build_package_software_metadata(),
58  "selected_candidate": payload["selected_candidate"],
59  "summary": dict(payload["summary"]),
60  "required_artifacts": list(payload["required_artifacts"]),
61  "cases": payload["cases"],
62  "negative_cases": payload["negative_cases"],
63  }
64  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Performance evidence benchmark package")
65  return bundle
66 
67 
68 def main(argv: list[str] | None = None) -> int:
69  parser = argparse.ArgumentParser(description=__doc__)
70  parser.add_argument(
71  "--output-dir",
72  type=Path,
73  default=DEFAULT_OUTPUT_DIR,
74  help="Directory to write the benchmark package bundle into.",
75  )
76  parser.add_argument(
77  "--quiet",
78  action="store_true",
79  help="Suppress console output.",
80  )
81  args = parser.parse_args(argv)
82 
84  output_path = write_artifact_bundle(bundle, args.output_dir, ARTIFACT_FILENAME)
85 
86  if not args.quiet:
87  print(
88  "counted_supported_cases={counted_supported_cases}, diagnosis_only_cases={diagnosis_only_cases}, excluded_cases={excluded_cases}".format(
89  **bundle["summary"]
90  )
91  )
92  print("Wrote {}".format(output_path))
93 
94  return 0 if bundle["status"] == "pass" else 1
95 
96 
97 if __name__ == "__main__":
98  raise SystemExit(main())
def build_package_software_metadata()
def build_performance_evidence_benchmark_package_payload()