Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_phase31_hybrid_pilot_validation.py
Go to the documentation of this file.
1 """Regression tests for the Phase 3.1 hybrid performance pilot (P31-S09-E01)."""
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.performance_evidence.case_selection import (
15  BENCHMARK_SLICE_PHASE31_HYBRID_PILOT,
16  PHASE31_HYBRID_PILOT_WORKLOAD_ID,
17  build_phase31_hybrid_pilot_case_context,
18  build_phase31_performance_inventory_cases,
19  iter_phase31_performance_cases,
20 )
21 from benchmarks.density_matrix.performance_evidence.common import (
22  PERFORMANCE_EVIDENCE_CASE_SCHEMA_VERSION,
23  PERFORMANCE_EVIDENCE_REPETITIONS,
24 )
25 from benchmarks.density_matrix.performance_evidence.phase31_hybrid_pilot_validation import (
26  build_phase31_hybrid_pilot_bundle,
27  build_phase31_hybrid_pilot_cases,
28 )
29 from benchmarks.density_matrix.performance_evidence.records import (
30  _PHASE31_HYBRID_DECISION_CLASSES,
31  _PHASE31_HYBRID_DIAGNOSIS_TAGS,
32  build_phase31_hybrid_pilot_record,
33 )
34 
35 _FROZEN_DECISION_CLASSES = frozenset(_PHASE31_HYBRID_DECISION_CLASSES)
36 _FROZEN_DIAGNOSIS_TAGS = frozenset(_PHASE31_HYBRID_DIAGNOSIS_TAGS)
37 
38 
41  assert ctx.descriptor_set.workload_id == PHASE31_HYBRID_PILOT_WORKLOAD_ID
42  assert ctx.metadata["benchmark_slice"] == BENCHMARK_SLICE_PHASE31_HYBRID_PILOT
43 
44 
47  assert record["workload_id"] == PHASE31_HYBRID_PILOT_WORKLOAD_ID
48  assert record["timing_mode"] == "median_3"
49  n = PERFORMANCE_EVIDENCE_REPETITIONS
50  assert len(record["sequential_runtime_ms_samples"]) == n
51  assert len(record["phase3_fused_runtime_ms_samples"]) == n
52  assert len(record["phase31_hybrid_runtime_ms_samples"]) == n
53  assert len(record["sequential_peak_rss_kb_samples"]) == n
54  assert len(record["phase3_fused_peak_rss_kb_samples"]) == n
55  assert len(record["phase31_hybrid_peak_rss_kb_samples"]) == n
56  for key in (
57  "sequential_median_runtime_ms",
58  "phase3_fused_median_runtime_ms",
59  "phase31_hybrid_median_runtime_ms",
60  ):
61  assert record[key] > 0.0
62  for key in (
63  "sequential_median_peak_rss_kb",
64  "phase3_fused_median_peak_rss_kb",
65  "phase31_hybrid_median_peak_rss_kb",
66  ):
67  assert record[key] >= 0
68  for key in (
69  "channel_native_partition_count",
70  "phase3_routed_partition_count",
71  "channel_native_member_count",
72  "phase3_routed_member_count",
73  ):
74  assert key in record
75  assert record[key] >= 0
76  assert record["channel_native_partition_count"] > 0
77  assert record["channel_native_member_count"] > 0
78  assert record["decision_class"] in _FROZEN_DECISION_CLASSES
79  assert record["diagnosis_tag"] in _FROZEN_DIAGNOSIS_TAGS
80  assert isinstance(record["hybrid_partition_route_records"], list)
81  assert len(record["hybrid_partition_route_records"]) == record[
82  "phase31_hybrid_partition_count"
83  ]
84  assert record["phase3_fused_internal_reference_pass"] is True
85  assert record["phase31_hybrid_internal_reference_pass"] is True
86 
87 
90  cn = record["channel_native_partition_count"]
91  fused_ms = record["phase3_fused_median_runtime_ms"]
92  hybrid_ms = record["phase31_hybrid_median_runtime_ms"]
93  speedup = fused_ms / hybrid_ms if hybrid_ms > 0.0 else 0.0
94  positive = speedup >= 1.2
95  tag = record["diagnosis_tag"]
96  decision = record["decision_class"]
97  if positive:
98  assert tag == "phase31_positive_gain"
99  assert decision == "phase31_justified"
100  elif cn == 0:
101  assert tag == "limited_channel_native_coverage"
102  assert decision == "phase3_sufficient"
103  else:
104  assert tag == "hybrid_overhead_dominant"
105  assert decision == "phase31_not_justified_yet"
106 
107 
110  bundle = build_phase31_hybrid_pilot_bundle(cases)
111  assert bundle["status"] == "pass"
112  assert bundle["record_schema_version"] == PERFORMANCE_EVIDENCE_CASE_SCHEMA_VERSION
113  s = bundle["summary"]
114  assert s["total_cases"] == 1
115  assert s["pilot_workload_id"] == PHASE31_HYBRID_PILOT_WORKLOAD_ID
116  assert s["pilot_case_name"] == cases[0]["case_name"]
117  assert s["timing_mode"] == "median_3"
118  assert s["decision_class"] == cases[0]["decision_class"]
119  assert s["diagnosis_tag"] == cases[0]["diagnosis_tag"]
120  assert s["channel_native_partition_count"] == cases[0]["channel_native_partition_count"]
121  assert s["phase3_routed_partition_count"] == cases[0]["phase3_routed_partition_count"]
122 
123 
125  """Guards Phase 3.1 planning helpers (control branch uses DEFAULT_STRUCTURED_SEED)."""
127  assert len(inventory) == 26
128  assert any(
129  c.get("benchmark_slice") == "phase31_control_performance" for c in inventory
130  )
131  contexts = list(iter_phase31_performance_cases())
132  assert len(contexts) == 26
133  assert any(
134  ctx.metadata.get("benchmark_slice") == "phase31_control_performance"
135  for ctx in contexts
136  )
def build_phase31_hybrid_pilot_record(case_context)