Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
performance_evidence/validation_pipeline.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Run and write every performance-evidence validation bundle (full pipeline) in one process.
3 
4 Run with:
5  python benchmarks/density_matrix/performance_evidence/validation_pipeline.py
6 """
7 
8 from __future__ import annotations
9 
10 import argparse
11 import sys
12 from pathlib import Path
13 from typing import Any
14 
15 REPO_ROOT = Path(__file__).resolve().parents[3]
16 if str(REPO_ROOT) not in sys.path:
17  sys.path.insert(0, str(REPO_ROOT))
18 
19 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
20  benchmark_bundle_validation as benchmark_package,
21 )
22 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
23  benchmark_matrix_validation as benchmark_matrix,
24 )
25 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
26  counted_supported_validation as counted_supported,
27 )
28 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
29  diagnosis_validation as diagnosis,
30 )
31 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
32  metric_surface_validation as metric_surface,
33 )
34 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
35  positive_threshold_validation as positive_threshold,
36 )
37 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
38  sensitivity_matrix_validation as sensitivity_matrix,
39 )
40 from benchmarks.density_matrix.performance_evidence import ( # noqa: E402
41  summary_consistency_validation as summary_consistency,
42 )
43 from benchmarks.density_matrix.performance_evidence.common import ( # noqa: E402
44  DEFAULT_OUTPUT_ROOT,
45  write_artifact_bundle,
46 )
47 
48 
49 def _write_slice_bundle(module: Any, bundle: dict) -> Path:
50  return write_artifact_bundle(bundle, module.DEFAULT_OUTPUT_DIR, module.ARTIFACT_FILENAME)
51 
52 
53 # (module, build_cases_attr, build_bundle_attr)
54 _CASE_SLICE_REGISTRY: tuple[tuple[Any, str, str], ...] = (
55  (benchmark_matrix, "build_benchmark_matrix_cases", "build_benchmark_matrix_bundle"),
56  (counted_supported, "build_counted_supported_cases", "build_counted_supported_bundle"),
57  (positive_threshold, "build_positive_threshold_cases", "build_positive_threshold_bundle"),
58  (sensitivity_matrix, "build_sensitivity_matrix_cases", "build_sensitivity_matrix_bundle"),
59  (metric_surface, "build_metric_surface_cases", "build_metric_surface_bundle"),
60  (diagnosis, "build_diagnosis_cases", "build_diagnosis_bundle"),
61 )
62 
63 # (module, build_bundle_attr)
64 _SPECIAL_BUNDLE_REGISTRY: tuple[tuple[Any, str], ...] = (
65  (benchmark_package, "build_performance_evidence_benchmark_package"),
66  (summary_consistency, "build_summary_consistency_bundle"),
67 )
68 
69 
70 def run_pipeline() -> list[tuple[str, str, Path]]:
71  results: list[tuple[str, str, Path]] = []
72 
73  for mod, cases_attr, bundle_attr in _CASE_SLICE_REGISTRY:
74  cases = getattr(mod, cases_attr)()
75  bundle = getattr(mod, bundle_attr)(cases)
76  results.append(
77  (mod.SUITE_NAME, bundle["status"], _write_slice_bundle(mod, bundle))
78  )
79 
80  for mod, bundle_attr in _SPECIAL_BUNDLE_REGISTRY:
81  bundle = getattr(mod, bundle_attr)()
82  results.append(
83  (mod.SUITE_NAME, bundle["status"], _write_slice_bundle(mod, bundle))
84  )
85 
86  return results
87 
88 
89 def main(argv: list[str] | None = None) -> int:
90  parser = argparse.ArgumentParser(description=__doc__)
91  parser.add_argument(
92  "--quiet",
93  action="store_true",
94  help="Suppress per-bundle console output.",
95  )
96  args = parser.parse_args(argv)
97 
98  DEFAULT_OUTPUT_ROOT.mkdir(parents=True, exist_ok=True)
99  results = run_pipeline()
100  for suite_name, status, output_path in results:
101  if not args.quiet:
102  print(f"{suite_name}: status={status} path={output_path}")
103  return 0 if all(status == "pass" for _, status, _ in results) else 1
104 
105 
106 if __name__ == "__main__":
107  raise SystemExit(main())