Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_phase31_correctness_evidence.py
Go to the documentation of this file.
1 """Regression tests for Stage-A bounded Phase 3.1 correctness-evidence sibling (P31-S10-E02)."""
2 
3 from __future__ import annotations
4 
5 from pathlib import Path
6 import sys
7 
8 import pytest
9 
10 REPO_ROOT = Path(__file__).resolve().parents[3]
11 if str(REPO_ROOT) not in sys.path:
12  sys.path.insert(0, str(REPO_ROOT))
13 
14 from benchmarks.density_matrix.correctness_evidence.case_selection import (
15  CORRECTNESS_EVIDENCE_CASE_KIND_CONTINUITY,
16  CORRECTNESS_EVIDENCE_CASE_KIND_MICROCASE,
17  build_phase31_correctness_evidence_case_contexts,
18 )
19 from benchmarks.density_matrix.correctness_evidence.common import (
20  CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
21  CORRECTNESS_EVIDENCE_PHASE31_PACKAGE_SCHEMA_VERSION,
22  CORRECTNESS_EVIDENCE_PHASE31_SUMMARY_SCHEMA_VERSION,
23 )
24 from benchmarks.density_matrix.correctness_evidence.phase31_correctness_bundle_validation import (
25  build_artifact_bundle as build_phase31_correctness_package_bundle,
26 )
27 from benchmarks.density_matrix.correctness_evidence.phase31_correctness_matrix_validation import (
28  build_artifact_bundle as build_phase31_matrix_bundle,
29  build_cases as build_phase31_matrix_cases,
30 )
31 from benchmarks.density_matrix.correctness_evidence.phase31_external_correctness_validation import (
32  build_artifact_bundle as build_phase31_external_bundle,
33  build_cases as build_phase31_external_cases,
34 )
35 from benchmarks.density_matrix.correctness_evidence.phase31_output_integrity_validation import (
36  build_artifact_bundle as build_phase31_output_integrity_bundle,
37  build_cases as build_phase31_output_integrity_cases,
38 )
39 from benchmarks.density_matrix.correctness_evidence.phase31_runtime_classification_validation import (
40  build_artifact_bundle as build_phase31_runtime_classification_bundle,
41  build_cases as build_phase31_runtime_classification_cases,
42 )
43 from benchmarks.density_matrix.correctness_evidence.phase31_sequential_correctness_validation import (
44  build_artifact_bundle as build_phase31_sequential_bundle,
45  build_cases as build_phase31_sequential_cases,
46 )
47 from benchmarks.density_matrix.correctness_evidence.phase31_summary_consistency_validation import (
48  build_artifact_bundle as build_phase31_summary_consistency_bundle,
49 )
50 from benchmarks.density_matrix.correctness_evidence.records import (
51  build_phase31_correctness_evidence_positive_records,
52  counted_supported_case,
53 )
54 
55 
58  assert len(ctxs) == 6
59  kinds = [c.metadata["case_kind"] for c in ctxs]
60  assert kinds.count(CORRECTNESS_EVIDENCE_CASE_KIND_MICROCASE) == 4
61  assert kinds.count(CORRECTNESS_EVIDENCE_CASE_KIND_CONTINUITY) == 2
62  assert sum(c.metadata["external_reference_required"] for c in ctxs) == 5
63 
64 
67  assert len(recs) == 6
68  assert all(r["record_schema_version"] == CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION for r in recs)
69  assert all(counted_supported_case(r) for r in recs)
70  for r in recs:
71  assert r["claim_surface_id"] == "phase31_bounded_mixed_motif_v1"
72  assert r["representation_primary"] == "kraus_bundle"
73  assert r["contains_noise"] is True
74  assert r["counted_phase31_case"] is True
75  assert "runtime_class" in r
76  if r["case_kind"] == CORRECTNESS_EVIDENCE_CASE_KIND_MICROCASE:
77  assert r["channel_invariants"] is not None
78  assert r["channel_invariants"]["invariant_slice_pass"] is True
79  assert r["partition_route_summary"] is None
80  assert r["fused_block_support_qbits"] is not None
81  else:
82  assert r["channel_invariants"] is None
83  assert r["partition_route_summary"] is not None
84  assert r["partition_route_summary"]["partition_count"] >= 1
85  assert r["fused_block_support_qbits"] is None
86 
87 
88 @pytest.mark.parametrize(
89  "build_cases_fn,build_bundle_fn",
90  (
91  (build_phase31_matrix_cases, build_phase31_matrix_bundle),
92  (build_phase31_sequential_cases, build_phase31_sequential_bundle),
93  (build_phase31_external_cases, build_phase31_external_bundle),
94  (build_phase31_output_integrity_cases, build_phase31_output_integrity_bundle),
95  (build_phase31_runtime_classification_cases, build_phase31_runtime_classification_bundle),
96  ),
97  ids=(
98  "phase31_matrix",
99  "phase31_sequential",
100  "phase31_external",
101  "phase31_output_integrity",
102  "phase31_runtime_classification",
103  ),
104 )
105 def test_phase31_positive_slice_bundles_pass(build_cases_fn, build_bundle_fn):
106  cases = build_cases_fn()
107  bundle = build_bundle_fn(cases)
108  assert bundle["status"] == "pass"
109  assert bundle["record_schema_version"] == CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION
110 
111 
113  bundle = build_phase31_matrix_bundle(build_phase31_matrix_cases())
114  s = bundle["summary"]
115  assert s["total_cases"] == 6
116  assert s["microcases"] == 4
117  assert s["continuity_cases"] == 2
118  assert s["structured_cases"] == 0
119  assert s["external_slice_cases"] == 5
120 
121 
123  bundle = build_phase31_external_bundle(build_phase31_external_cases())
124  assert bundle["status"] == "pass"
125  assert bundle["summary"]["total_cases"] == 5
126  assert bundle["summary"]["microcases"] == 4
127  assert bundle["summary"]["continuity_cases"] == 1
128 
129 
131  pkg = build_phase31_correctness_package_bundle()
132  assert pkg["schema_version"] == CORRECTNESS_EVIDENCE_PHASE31_PACKAGE_SCHEMA_VERSION
133  assert pkg["status"] == "pass"
134  assert len(pkg["cases"]) == 6
135  summ = build_phase31_summary_consistency_bundle()
136  assert summ["status"] == "pass"
137  assert summ["schema_version"] == CORRECTNESS_EVIDENCE_PHASE31_SUMMARY_SCHEMA_VERSION
138  assert summ["summary"]["counted_supported_cases"] == 6
def build_phase31_correctness_evidence_positive_records()
def counted_supported_case