Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
phase31_validation_pipeline.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Run Stage-A Phase 3.1 correctness-evidence validation bundles in one process.
3 
4 Run with:
5  python benchmarks/density_matrix/correctness_evidence/phase31_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.correctness_evidence import (
20  phase31_correctness_bundle_validation as phase31_correctness_package,
21 )
22 from benchmarks.density_matrix.correctness_evidence import (
23  phase31_correctness_matrix_validation as phase31_correctness_matrix,
24 )
25 from benchmarks.density_matrix.correctness_evidence import (
26  phase31_external_correctness_validation as phase31_external_correctness,
27 )
28 from benchmarks.density_matrix.correctness_evidence import (
29  phase31_output_integrity_validation as phase31_output_integrity,
30 )
31 from benchmarks.density_matrix.correctness_evidence import (
32  phase31_runtime_classification_validation as phase31_runtime_classification,
33 )
34 from benchmarks.density_matrix.correctness_evidence import (
35  phase31_sequential_correctness_validation as phase31_sequential_correctness,
36 )
37 from benchmarks.density_matrix.correctness_evidence import (
38  phase31_summary_consistency_validation as phase31_summary_consistency,
39 )
40 from benchmarks.density_matrix.correctness_evidence.common import DEFAULT_OUTPUT_ROOT
41 from benchmarks.density_matrix.correctness_evidence.common import (
42  PHASE31_CORRECTNESS_EVIDENCE_STAGE_A_ROOT,
43  write_artifact_bundle,
44 )
45 
46 
47 def _write_slice_bundle(module: Any, bundle: dict) -> Path:
48  return write_artifact_bundle(bundle, module.DEFAULT_OUTPUT_DIR, module.ARTIFACT_FILENAME)
49 
50 
51 _CASE_SLICE_REGISTRY: tuple[tuple[Any, str, str], ...] = (
52  (phase31_correctness_matrix, "build_cases", "build_artifact_bundle"),
53  (phase31_sequential_correctness, "build_cases", "build_artifact_bundle"),
54  (phase31_external_correctness, "build_cases", "build_artifact_bundle"),
55  (phase31_output_integrity, "build_cases", "build_artifact_bundle"),
56  (phase31_runtime_classification, "build_cases", "build_artifact_bundle"),
57 )
58 
59 _NULLARY_BUNDLE_REGISTRY: tuple[tuple[Any, str], ...] = (
60  (phase31_correctness_package, "build_artifact_bundle"),
61  (phase31_summary_consistency, "build_artifact_bundle"),
62 )
63 
64 
65 def run_phase31_pipeline() -> list[tuple[str, str, Path]]:
66  results: list[tuple[str, str, Path]] = []
67 
68  for mod, cases_attr, bundle_attr in _CASE_SLICE_REGISTRY:
69  cases = getattr(mod, cases_attr)()
70  bundle = getattr(mod, bundle_attr)(cases)
71  results.append(
72  (mod.SUITE_NAME, bundle["status"], _write_slice_bundle(mod, bundle))
73  )
74 
75  for mod, bundle_attr in _NULLARY_BUNDLE_REGISTRY:
76  bundle = getattr(mod, bundle_attr)()
77  results.append(
78  (mod.SUITE_NAME, bundle["status"], _write_slice_bundle(mod, bundle))
79  )
80 
81  return results
82 
83 
84 def main(argv: list[str] | None = None) -> int:
85  parser = argparse.ArgumentParser(description=__doc__)
86  parser.add_argument(
87  "--quiet",
88  action="store_true",
89  help="Suppress per-bundle console output.",
90  )
91  args = parser.parse_args(argv)
92 
93  stage_root = DEFAULT_OUTPUT_ROOT / PHASE31_CORRECTNESS_EVIDENCE_STAGE_A_ROOT
94  stage_root.mkdir(parents=True, exist_ok=True)
95  results = run_phase31_pipeline()
96  for suite_name, status, output_path in results:
97  if not args.quiet:
98  print(f"{suite_name}: status={status} path={output_path}")
99  return 0 if all(status == "pass" for _, status, _ in results) else 1
100 
101 
102 if __name__ == "__main__":
103  raise SystemExit(main())