Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
correctness_bundle_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Validation: density-matrix correctness-evidence package.
3 
4 Builds the shared correctness-evidence package by joining positive supported
5 records and stage-separated unsupported-boundary evidence through one stable
6 machine-reviewable surface.
7 
8 Run with:
9  python benchmarks/density_matrix/correctness_evidence/correctness_bundle_validation.py
10 """
11 
12 from __future__ import annotations
13 
14 import argparse
15 from pathlib import Path
16 
17 from benchmarks.density_matrix.correctness_evidence.bundle import (
18  build_correctness_package_payload,
19 )
20 from benchmarks.density_matrix.correctness_evidence.common import (
21  CORRECTNESS_PACKAGE_SCHEMA_VERSION,
22  build_package_software_metadata,
23  correctness_evidence_output_dir,
24  write_artifact_bundle,
25 )
26 from benchmarks.density_matrix.correctness_evidence.records import (
27  counted_supported_case,
28 )
29 from benchmarks.density_matrix.validation_scaffold import require_bundle_fields
30 
31 SUITE_NAME = "correctness_evidence_correctness_package"
32 ARTIFACT_FILENAME = "correctness_package_bundle.json"
33 DEFAULT_OUTPUT_DIR = correctness_evidence_output_dir("correctness_package")
34 ARTIFACT_CORE_FIELDS = (
35  "suite_name",
36  "status",
37  "schema_version",
38  "software",
39  "selected_candidate",
40  "summary",
41  "cases",
42  "negative_cases",
43 )
44 
45 
46 def build_cases() -> list[dict]:
47  return build_correctness_package_payload()["cases"]
48 
49 
50 def build_artifact_bundle() -> dict:
52  cases = payload["cases"]
53  negative_cases = payload["negative_cases"]
54  counted_supported_cases = sum(counted_supported_case(case) for case in cases)
55  bundle = {
56  "suite_name": SUITE_NAME,
57  "status": "pass"
58  if counted_supported_cases == len(cases)
59  and len(negative_cases) > 0
60  and all(case["status"] == "unsupported" for case in negative_cases)
61  else "fail",
62  "schema_version": CORRECTNESS_PACKAGE_SCHEMA_VERSION,
63  "software": build_package_software_metadata(),
64  "selected_candidate": payload["selected_candidate"],
65  "summary": payload["summary"],
66  "cases": cases,
67  "negative_cases": negative_cases,
68  }
69  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Correctness package bundle")
70  return bundle
71 
72 
73 def main(argv: list[str] | None = None) -> int:
74  parser = argparse.ArgumentParser(description=__doc__)
75  parser.add_argument(
76  "--output-dir",
77  type=Path,
78  default=DEFAULT_OUTPUT_DIR,
79  help="Directory to write the correctness package bundle into.",
80  )
81  parser.add_argument(
82  "--quiet",
83  action="store_true",
84  help="Suppress per-case console output.",
85  )
86  args = parser.parse_args(argv)
87 
88  bundle = build_artifact_bundle()
89  output_path = write_artifact_bundle(bundle, args.output_dir, ARTIFACT_FILENAME)
90 
91  if not args.quiet:
92  print(
93  "counted_supported_cases={counted_supported_cases}, unsupported_boundary_cases={unsupported_boundary_cases}".format(
94  **bundle["summary"]
95  )
96  )
97  print("Wrote {}".format(output_path))
98 
99  return 0 if bundle["status"] == "pass" else 1
100 
101 
102 if __name__ == "__main__":
103  raise SystemExit(main())
def build_package_software_metadata()
def build_correctness_package_payload()
def counted_supported_case