Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
phase31_external_correctness_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Stage-A Phase 3.1 external slice (five Aer rows: four microcases + q4 continuity).
3 
4 Run with:
5  python benchmarks/density_matrix/correctness_evidence/phase31_external_correctness_validation.py
6 """
7 
8 from __future__ import annotations
9 
10 from benchmarks.density_matrix.correctness_evidence.case_selection import (
11  CORRECTNESS_EVIDENCE_CASE_KIND_CONTINUITY,
12  CORRECTNESS_EVIDENCE_CASE_KIND_MICROCASE,
13 )
14 from benchmarks.density_matrix.correctness_evidence.common import (
15  CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
16  phase31_correctness_evidence_output_dir,
17 )
18 from benchmarks.density_matrix.correctness_evidence.records import (
19  build_phase31_correctness_evidence_positive_records,
20 )
21 from benchmarks.density_matrix.correctness_evidence.validation_support import (
22  assemble_positive_case_bundle,
23 )
24 from benchmarks.density_matrix.validation_scaffold import (
25  require_bundle_fields,
26  run_case_slice_cli,
27 )
28 
29 SUITE_NAME = "correctness_evidence_phase31_external_correctness"
30 ARTIFACT_FILENAME = "phase31_external_correctness_bundle.json"
31 DEFAULT_OUTPUT_DIR = phase31_correctness_evidence_output_dir("external_correctness")
32 ARTIFACT_CORE_FIELDS = (
33  "suite_name",
34  "status",
35  "record_schema_version",
36  "software",
37  "selected_candidate",
38  "summary",
39  "cases",
40 )
41 
42 
43 def build_cases() -> list[dict]:
44  return [
45  case
47  if case["external_reference_required"]
48  ]
49 
50 
51 def build_artifact_bundle(cases: list[dict]) -> dict:
52  external_passes = sum(case["external_reference_pass"] for case in cases)
53  microcases = sum(case["case_kind"] == CORRECTNESS_EVIDENCE_CASE_KIND_MICROCASE for case in cases)
54  continuity_cases = sum(
55  case["case_kind"] == CORRECTNESS_EVIDENCE_CASE_KIND_CONTINUITY for case in cases
56  )
57  status = (
58  "pass"
59  if len(cases) == 5
60  and external_passes == len(cases)
61  and microcases == 4
62  and continuity_cases == 1
63  else "fail"
64  )
65  summary = {
66  "package_kind": "phase31_stage_a_bounded",
67  "total_cases": len(cases),
68  "external_reference_passes": external_passes,
69  "microcases": microcases,
70  "continuity_cases": continuity_cases,
71  }
73  SUITE_NAME,
74  status,
75  summary,
76  cases,
77  record_schema_version=CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
78  )
79  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Phase 3.1 external correctness bundle")
80  return bundle
81 
82 
83 def main(argv: list[str] | None = None) -> int:
84  return run_case_slice_cli(
85  argv,
86  build_cases=build_cases,
87  build_artifact_bundle=build_artifact_bundle,
88  artifact_filename=ARTIFACT_FILENAME,
89  default_output_dir=DEFAULT_OUTPUT_DIR,
90  description=__doc__ or "",
91  output_dir_help="Directory to write the Phase 3.1 external correctness bundle into.",
92  quiet_report=lambda b: print(
93  "external_reference_passes={external_reference_passes}, total_cases={total_cases}".format(
94  **b["summary"]
95  )
96  ),
97  )
98 
99 
100 if __name__ == "__main__":
101  raise SystemExit(main())
def build_phase31_correctness_evidence_positive_records()
def phase31_correctness_evidence_output_dir