CharlesCNorton commited on
Commit ·
6f5e4e2
1
Parent(s): 9ea6dfa
Add Zeno diagnostic: identity vs X Zeno at high N
Browse filesIdentity Zeno holds at 91.2% at 14x T1. Gate errors cause
60% of X Zeno decline; measurement mechanism causes 40%.
- README.md +16 -0
- results/zeno_diagnostic/zeno_diagnostic.json +0 -0
- zeno_diagnostic.py +438 -0
README.md
CHANGED
|
@@ -640,6 +640,22 @@ At 3.47× T1 the delay-matched control reads 18.3%, approaching the thermal floo
|
|
| 640 |
|
| 641 |
The delay-matched control reaches the thermal floor (~17%) by 3× T1 and remains there through 14× T1. Zeno excess-flip weighted fidelity declines at approximately 2.5 percentage points per doubling of N, consistent with logarithmic degradation. At 13.86× T1, the Zeno-protected qubit maintains 77% fidelity while the delay-matched control reads 16.8%.
|
| 642 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
---
|
| 644 |
|
| 645 |
## Data Format
|
|
|
|
| 640 |
|
| 641 |
The delay-matched control reaches the thermal floor (~17%) by 3× T1 and remains there through 14× T1. Zeno excess-flip weighted fidelity declines at approximately 2.5 percentage points per doubling of N, consistent with logarithmic degradation. At 13.86× T1, the Zeno-protected qubit maintains 77% fidelity while the delay-matched control reads 16.8%.
|
| 642 |
|
| 643 |
+
### Zeno Fidelity Decline Diagnostic
|
| 644 |
+
|
| 645 |
+
**zeno_diagnostic/** — Identifies the source of fidelity decline observed at high N. The X gate Zeno protocol requires Ry rotation gates between each measurement; at N=1024 this amounts to 2048 rotations decomposed into ~5000 native gates. To determine whether the decline from 92% (N=32) to 77% (N=1024) originates from accumulated gate errors or from the measurement mechanism itself, we compare identity Zeno (repeated measurement with no rotations) against X Zeno (measurement with Ry rotations) at matched N values. Fifteen circuits were run at 4096 shots each on ibm_torino (job d6jjtl860irc7394k8rg, 55s QPU time, March 3 2026).
|
| 646 |
+
|
| 647 |
+
**Results (excess-flip weighting, 4096 shots per circuit):**
|
| 648 |
+
|
| 649 |
+
| N | ×T1 | Identity Zeno | X Zeno | Delay-matched | I − X |
|
| 650 |
+
|---|-----|---------------|--------|---------------|-------|
|
| 651 |
+
| 32 | 0.43 | 95.4% | 92.5% | 89.0% | +2.9pp |
|
| 652 |
+
| 128 | 1.73 | 94.4% | 91.1% | 86.6% | +3.2pp |
|
| 653 |
+
| 256 | 3.47 | 93.7% | 88.6% | 87.6% | +5.2pp |
|
| 654 |
+
| 512 | 6.93 | 92.6% | 82.8% | 88.8% | +9.7pp |
|
| 655 |
+
| 1024 | 13.86 | 91.2% | 82.3% | 87.3% | +8.9pp |
|
| 656 |
+
|
| 657 |
+
Identity Zeno declines by 4.2 percentage points from N=32 to N=1024. X Zeno declines by 10.2 percentage points over the same range. The measurement mechanism accounts for roughly 40% of the total decline; accumulated Ry gate errors account for the remaining 60%. The Zeno projection mechanism itself remains effective at 91.2% fidelity after 1024 consecutive measurements spanning 14× T1.
|
| 658 |
+
|
| 659 |
---
|
| 660 |
|
| 661 |
## Data Format
|
results/zeno_diagnostic/zeno_diagnostic.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
zeno_diagnostic.py
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Zeno Diagnostic — Is the decline from gate errors or measurement mechanism?
|
| 3 |
+
|
| 4 |
+
Identity Zeno (theta=0): just measure the qubit repeatedly, no rotations.
|
| 5 |
+
If identity stays at 95% while X declined to 77% at N=1024,
|
| 6 |
+
the decline is from accumulated Ry gate errors.
|
| 7 |
+
If identity also declines, it's the measurement mechanism itself.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
import sys
|
| 12 |
+
from datetime import datetime, timezone
|
| 13 |
+
from dataclasses import dataclass
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
import numpy as np
|
| 16 |
+
from scipy.special import comb
|
| 17 |
+
|
| 18 |
+
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
|
| 19 |
+
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
|
| 20 |
+
from qiskit_ibm_runtime import (
|
| 21 |
+
QiskitRuntimeService,
|
| 22 |
+
SamplerV2,
|
| 23 |
+
Batch,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
DATA_DIR = Path("D:/qiskit-zenodragging")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@dataclass
|
| 31 |
+
class ExperimentConfig:
|
| 32 |
+
name: str
|
| 33 |
+
circuit: QuantumCircuit
|
| 34 |
+
category: str
|
| 35 |
+
params: dict
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def log(msg, level=0):
|
| 39 |
+
indent = " " * level
|
| 40 |
+
ts = datetime.now().strftime("%H:%M:%S")
|
| 41 |
+
print(f"[{ts}] {indent}{msg}")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def check_usage(service):
|
| 45 |
+
jobs = list(service.jobs(limit=200))
|
| 46 |
+
now = datetime.now(timezone.utc)
|
| 47 |
+
month_start = datetime(now.year, now.month, 1, tzinfo=timezone.utc)
|
| 48 |
+
total = 0
|
| 49 |
+
for j in jobs:
|
| 50 |
+
u = j.usage() or 0
|
| 51 |
+
try:
|
| 52 |
+
m = j.metrics()
|
| 53 |
+
ts = m.get('timestamps', {}).get('created', '')
|
| 54 |
+
if ts:
|
| 55 |
+
dt = datetime.fromisoformat(ts.replace('Z', '+00:00'))
|
| 56 |
+
if dt >= month_start:
|
| 57 |
+
total += u
|
| 58 |
+
except Exception:
|
| 59 |
+
pass
|
| 60 |
+
return {"total": total, "remaining": 600 - total, "percentage": 100 * total / 600}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def build_identity_zeno(n_meas):
|
| 64 |
+
"""Zeno freeze: just measure |0> repeatedly. No rotations. Ideal = |0>."""
|
| 65 |
+
qr = QuantumRegister(1, 'q')
|
| 66 |
+
cr = ClassicalRegister(n_meas + 1, 'c')
|
| 67 |
+
qc = QuantumCircuit(qr, cr)
|
| 68 |
+
|
| 69 |
+
for k in range(n_meas):
|
| 70 |
+
qc.measure(0, k)
|
| 71 |
+
|
| 72 |
+
qc.measure(0, n_meas)
|
| 73 |
+
return qc
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def build_x_zeno(n_meas):
|
| 77 |
+
"""Zeno drag 0->pi via N measurements, then undo. Ideal = |0>. (For comparison.)"""
|
| 78 |
+
theta = np.pi
|
| 79 |
+
qr = QuantumRegister(1, 'q')
|
| 80 |
+
cr = ClassicalRegister(n_meas + 1, 'c')
|
| 81 |
+
qc = QuantumCircuit(qr, cr)
|
| 82 |
+
|
| 83 |
+
for k in range(1, n_meas + 1):
|
| 84 |
+
theta_k = k * theta / n_meas
|
| 85 |
+
qc.ry(-theta_k, 0)
|
| 86 |
+
qc.measure(0, k - 1)
|
| 87 |
+
qc.ry(theta_k, 0)
|
| 88 |
+
|
| 89 |
+
qc.ry(-theta, 0)
|
| 90 |
+
qc.measure(0, n_meas)
|
| 91 |
+
return qc
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def build_delay_matched(n_meas, meas_duration_dt):
|
| 95 |
+
"""Identity + delay = same wall-clock. Ideal = |0>."""
|
| 96 |
+
qc = QuantumCircuit(1, 1)
|
| 97 |
+
qc.delay(n_meas * meas_duration_dt, 0, unit='dt')
|
| 98 |
+
qc.measure(0, 0)
|
| 99 |
+
return qc
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def analyze_zeno(bitstrings, n_meas, p_meas):
|
| 103 |
+
total = len(bitstrings)
|
| 104 |
+
successful = 0
|
| 105 |
+
correct_given_success = 0
|
| 106 |
+
flip_bins = {}
|
| 107 |
+
|
| 108 |
+
for bs in bitstrings:
|
| 109 |
+
if len(bs) < n_meas + 1:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
final = bs[0]
|
| 113 |
+
intermediate = bs[1:n_meas + 1]
|
| 114 |
+
n_flips = sum(1 for b in intermediate if b == '1')
|
| 115 |
+
|
| 116 |
+
if n_flips not in flip_bins:
|
| 117 |
+
flip_bins[n_flips] = {'total': 0, 'correct': 0}
|
| 118 |
+
flip_bins[n_flips]['total'] += 1
|
| 119 |
+
if final == '0':
|
| 120 |
+
flip_bins[n_flips]['correct'] += 1
|
| 121 |
+
|
| 122 |
+
if n_flips == 0:
|
| 123 |
+
successful += 1
|
| 124 |
+
if final == '0':
|
| 125 |
+
correct_given_success += 1
|
| 126 |
+
|
| 127 |
+
success_rate = successful / total if total > 0 else 0
|
| 128 |
+
fidelity_hard = correct_given_success / successful if successful > 0 else 0
|
| 129 |
+
|
| 130 |
+
expected_meas_flips = n_meas * p_meas
|
| 131 |
+
|
| 132 |
+
# exp(-k)
|
| 133 |
+
w1_c, w1_t = 0, 0
|
| 134 |
+
for nf, data in flip_bins.items():
|
| 135 |
+
w = np.exp(-nf)
|
| 136 |
+
w1_c += w * data['correct']
|
| 137 |
+
w1_t += w * data['total']
|
| 138 |
+
fid_exp_k = w1_c / w1_t if w1_t > 0 else 0
|
| 139 |
+
|
| 140 |
+
# Excess-flip
|
| 141 |
+
w3_c, w3_t = 0, 0
|
| 142 |
+
for nf, data in flip_bins.items():
|
| 143 |
+
excess = max(0, nf - expected_meas_flips)
|
| 144 |
+
w = np.exp(-excess)
|
| 145 |
+
w3_c += w * data['correct']
|
| 146 |
+
w3_t += w * data['total']
|
| 147 |
+
fid_excess = w3_c / w3_t if w3_t > 0 else 0
|
| 148 |
+
|
| 149 |
+
# Likelihood ratio
|
| 150 |
+
w4_c, w4_t = 0, 0
|
| 151 |
+
for nf, data in flip_bins.items():
|
| 152 |
+
if nf <= n_meas:
|
| 153 |
+
p_target = comb(n_meas, nf, exact=True) * (p_meas ** nf) * ((1 - p_meas) ** (n_meas - nf))
|
| 154 |
+
p_random = comb(n_meas, nf, exact=True) * (0.5 ** n_meas)
|
| 155 |
+
w = min(p_target / p_random, 1e10) if p_random > 0 else 0
|
| 156 |
+
else:
|
| 157 |
+
w = 0
|
| 158 |
+
w4_c += w * data['correct']
|
| 159 |
+
w4_t += w * data['total']
|
| 160 |
+
fid_likelihood = w4_c / w4_t if w4_t > 0 else 0
|
| 161 |
+
|
| 162 |
+
all_flips = []
|
| 163 |
+
for nf, data in flip_bins.items():
|
| 164 |
+
all_flips.extend([nf] * data['total'])
|
| 165 |
+
mean_flips = np.mean(all_flips) if all_flips else 0
|
| 166 |
+
std_flips = np.std(all_flips) if all_flips else 0
|
| 167 |
+
|
| 168 |
+
return {
|
| 169 |
+
'total': total,
|
| 170 |
+
'successful': successful,
|
| 171 |
+
'success_rate': success_rate,
|
| 172 |
+
'fidelity_hard_ps': fidelity_hard,
|
| 173 |
+
'fidelity_exp_k': fid_exp_k,
|
| 174 |
+
'fidelity_excess': fid_excess,
|
| 175 |
+
'fidelity_likelihood': fid_likelihood,
|
| 176 |
+
'expected_meas_flips': expected_meas_flips,
|
| 177 |
+
'mean_flips': mean_flips,
|
| 178 |
+
'std_flips': std_flips,
|
| 179 |
+
'flip_distribution': {str(k): v for k, v in sorted(flip_bins.items())},
|
| 180 |
+
'type': 'zeno',
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def analyze_standard(bitstrings):
|
| 185 |
+
total = len(bitstrings)
|
| 186 |
+
zeros = sum(1 for b in bitstrings if b[-1] == '0')
|
| 187 |
+
return {'total': total, 'fidelity': zeros / total, 'type': 'standard'}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def main():
|
| 191 |
+
print("=" * 70)
|
| 192 |
+
print("ZENO DIAGNOSTIC — GATE ERRORS OR MEASUREMENT MECHANISM?")
|
| 193 |
+
print("=" * 70)
|
| 194 |
+
|
| 195 |
+
service = QiskitRuntimeService(channel="ibm_cloud", instance="claude")
|
| 196 |
+
|
| 197 |
+
usage_before = check_usage(service)
|
| 198 |
+
log(f"Usage: {usage_before['total']}s / 600s ({usage_before['percentage']:.1f}%)")
|
| 199 |
+
log(f"Remaining: {usage_before['remaining']}s")
|
| 200 |
+
|
| 201 |
+
if usage_before['remaining'] < 30:
|
| 202 |
+
log("Less than 30s remaining. Aborting.")
|
| 203 |
+
return
|
| 204 |
+
|
| 205 |
+
backend = service.backend("ibm_torino")
|
| 206 |
+
log(f"Backend: {backend.name} ({backend.num_qubits}q)")
|
| 207 |
+
|
| 208 |
+
dt = backend.dt
|
| 209 |
+
target_obj = backend.target
|
| 210 |
+
meas_props = target_obj['measure'][(0,)]
|
| 211 |
+
meas_duration_s = meas_props.duration
|
| 212 |
+
meas_duration_dt = int(meas_duration_s / dt)
|
| 213 |
+
meas_error = meas_props.error
|
| 214 |
+
|
| 215 |
+
props = backend.qubit_properties(0)
|
| 216 |
+
T1 = props.t1
|
| 217 |
+
T2 = props.t2
|
| 218 |
+
|
| 219 |
+
log(f"Measurement: {meas_duration_s*1e6:.3f} us, error={meas_error:.4f}")
|
| 220 |
+
log(f"Qubit 0: T1={T1*1e6:.1f} us, T2={T2*1e6:.1f} us")
|
| 221 |
+
|
| 222 |
+
n_values = [32, 128, 256, 512, 1024]
|
| 223 |
+
shots = 4096
|
| 224 |
+
|
| 225 |
+
all_experiments = []
|
| 226 |
+
|
| 227 |
+
for n in n_values:
|
| 228 |
+
total_time_us = n * meas_duration_s * 1e6
|
| 229 |
+
t1_mult = n * meas_duration_s / T1
|
| 230 |
+
|
| 231 |
+
# Identity Zeno — no rotations
|
| 232 |
+
all_experiments.append(ExperimentConfig(
|
| 233 |
+
name=f"identity_zeno_N{n}",
|
| 234 |
+
circuit=build_identity_zeno(n),
|
| 235 |
+
category="identity_zeno",
|
| 236 |
+
params={'gate': 'I', 'theta': 0, 'n_meas': n,
|
| 237 |
+
'total_time_us': total_time_us,
|
| 238 |
+
'T1_multiple': t1_mult},
|
| 239 |
+
))
|
| 240 |
+
|
| 241 |
+
# X Zeno — with rotations (for direct comparison)
|
| 242 |
+
all_experiments.append(ExperimentConfig(
|
| 243 |
+
name=f"x_zeno_N{n}",
|
| 244 |
+
circuit=build_x_zeno(n),
|
| 245 |
+
category="x_zeno",
|
| 246 |
+
params={'gate': 'X', 'theta': np.pi, 'n_meas': n,
|
| 247 |
+
'total_time_us': total_time_us,
|
| 248 |
+
'T1_multiple': t1_mult},
|
| 249 |
+
))
|
| 250 |
+
|
| 251 |
+
# Delay-matched
|
| 252 |
+
all_experiments.append(ExperimentConfig(
|
| 253 |
+
name=f"delay_N{n}",
|
| 254 |
+
circuit=build_delay_matched(n, meas_duration_dt),
|
| 255 |
+
category="delay",
|
| 256 |
+
params={'gate': 'I', 'theta': 0, 'n_meas': n,
|
| 257 |
+
'total_time_us': total_time_us,
|
| 258 |
+
'T1_multiple': t1_mult},
|
| 259 |
+
))
|
| 260 |
+
|
| 261 |
+
log(f"Total experiments: {len(all_experiments)}")
|
| 262 |
+
|
| 263 |
+
log("Transpiling...")
|
| 264 |
+
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
|
| 265 |
+
|
| 266 |
+
transpiled = []
|
| 267 |
+
for exp in all_experiments:
|
| 268 |
+
try:
|
| 269 |
+
tc = pm.run(exp.circuit)
|
| 270 |
+
transpiled.append(tc)
|
| 271 |
+
except Exception as e:
|
| 272 |
+
log(f"ERROR transpiling {exp.name}: {e}")
|
| 273 |
+
transpiled.append(None)
|
| 274 |
+
|
| 275 |
+
valid_indices = [i for i, tc in enumerate(transpiled) if tc is not None]
|
| 276 |
+
valid_transpiled = [transpiled[i] for i in valid_indices]
|
| 277 |
+
valid_experiments = [all_experiments[i] for i in valid_indices]
|
| 278 |
+
|
| 279 |
+
log(f"Transpiled: {len(valid_transpiled)}/{len(all_experiments)}")
|
| 280 |
+
|
| 281 |
+
depths = [tc.depth() for tc in valid_transpiled]
|
| 282 |
+
log(f"Depths: min={min(depths)}, max={max(depths)}")
|
| 283 |
+
|
| 284 |
+
for i, exp in enumerate(valid_experiments):
|
| 285 |
+
exp.params['transpiled_depth'] = depths[i]
|
| 286 |
+
|
| 287 |
+
log("Submitting batch...")
|
| 288 |
+
start_time = datetime.now(timezone.utc)
|
| 289 |
+
|
| 290 |
+
with Batch(backend=backend) as batch:
|
| 291 |
+
sampler = SamplerV2(mode=batch)
|
| 292 |
+
job = sampler.run(valid_transpiled, shots=shots)
|
| 293 |
+
log(f"Job ID: {job.job_id()}")
|
| 294 |
+
log("Waiting...")
|
| 295 |
+
job.wait_for_final_state()
|
| 296 |
+
|
| 297 |
+
end_time = datetime.now(timezone.utc)
|
| 298 |
+
wall_time = (end_time - start_time).total_seconds()
|
| 299 |
+
log(f"Done. Wall time: {wall_time:.1f}s, QPU: {job.usage() or 0}s")
|
| 300 |
+
|
| 301 |
+
result = job.result()
|
| 302 |
+
metrics = job.metrics()
|
| 303 |
+
results_data = {}
|
| 304 |
+
|
| 305 |
+
for i, exp in enumerate(valid_experiments):
|
| 306 |
+
pub_result = result[i]
|
| 307 |
+
data_bin = pub_result.data
|
| 308 |
+
|
| 309 |
+
if hasattr(data_bin, 'c'):
|
| 310 |
+
bitstrings = list(data_bin.c.get_bitstrings())
|
| 311 |
+
elif hasattr(data_bin, 'meas'):
|
| 312 |
+
bitstrings = list(data_bin.meas.get_bitstrings())
|
| 313 |
+
else:
|
| 314 |
+
cr_name = list(data_bin.keys())[0]
|
| 315 |
+
bitstrings = list(getattr(data_bin, cr_name).get_bitstrings())
|
| 316 |
+
|
| 317 |
+
if 'zeno' in exp.category:
|
| 318 |
+
analysis = analyze_zeno(bitstrings, exp.params['n_meas'], meas_error)
|
| 319 |
+
else:
|
| 320 |
+
analysis = analyze_standard(bitstrings)
|
| 321 |
+
|
| 322 |
+
results_data[exp.name] = {
|
| 323 |
+
'category': exp.category,
|
| 324 |
+
'params': {k: (float(v) if isinstance(v, (np.floating, float)) else v)
|
| 325 |
+
for k, v in exp.params.items()},
|
| 326 |
+
'analysis': analysis,
|
| 327 |
+
'raw_bitstrings': bitstrings[:500],
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
# Save
|
| 331 |
+
output = {
|
| 332 |
+
'experiment': 'zeno_diagnostic',
|
| 333 |
+
'description': 'Diagnose Zeno fidelity decline: gate errors vs measurement mechanism',
|
| 334 |
+
'timestamp': start_time.isoformat(),
|
| 335 |
+
'backend': backend.name,
|
| 336 |
+
'shots': shots,
|
| 337 |
+
'job_id': job.job_id(),
|
| 338 |
+
'usage_seconds': job.usage() or 0,
|
| 339 |
+
'wall_time_seconds': wall_time,
|
| 340 |
+
'metrics': metrics,
|
| 341 |
+
'hardware_timing': {
|
| 342 |
+
'dt_ns': dt * 1e9,
|
| 343 |
+
'measurement_duration_us': meas_duration_s * 1e6,
|
| 344 |
+
'measurement_duration_dt': meas_duration_dt,
|
| 345 |
+
'measurement_error': meas_error,
|
| 346 |
+
'qubit_0_T1_us': T1 * 1e6,
|
| 347 |
+
'qubit_0_T2_us': T2 * 1e6,
|
| 348 |
+
},
|
| 349 |
+
'results': results_data,
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
outfile = DATA_DIR / 'results' / 'zeno_diagnostic' / 'zeno_diagnostic.json'
|
| 353 |
+
outfile.parent.mkdir(exist_ok=True)
|
| 354 |
+
with open(outfile, 'w') as f:
|
| 355 |
+
json.dump(output, f, indent=2, default=str)
|
| 356 |
+
log(f"Saved: {outfile}")
|
| 357 |
+
|
| 358 |
+
# =========================================================================
|
| 359 |
+
# THE ANSWER
|
| 360 |
+
# =========================================================================
|
| 361 |
+
print("\n" + "=" * 70)
|
| 362 |
+
print("DIAGNOSTIC: IDENTITY ZENO vs X ZENO vs DELAY")
|
| 363 |
+
print("=" * 70)
|
| 364 |
+
|
| 365 |
+
print(f"\n{'N':>5} | {'×T1':>5} | {'I Zeno(exc)':>11} | {'X Zeno(exc)':>11} | {'Delay':>7} | {'I-X gap':>7} | {'I flips':>10} | {'X flips':>10}")
|
| 366 |
+
print("-" * 90)
|
| 367 |
+
|
| 368 |
+
for n in n_values:
|
| 369 |
+
ik = f"identity_zeno_N{n}"
|
| 370 |
+
xk = f"x_zeno_N{n}"
|
| 371 |
+
dk = f"delay_N{n}"
|
| 372 |
+
|
| 373 |
+
if not all(k in results_data for k in [ik, xk, dk]):
|
| 374 |
+
continue
|
| 375 |
+
|
| 376 |
+
ia = results_data[ik]['analysis']
|
| 377 |
+
xa = results_data[xk]['analysis']
|
| 378 |
+
da = results_data[dk]['analysis']
|
| 379 |
+
t1m = results_data[ik]['params']['T1_multiple']
|
| 380 |
+
|
| 381 |
+
gap = ia['fidelity_excess'] - xa['fidelity_excess']
|
| 382 |
+
|
| 383 |
+
print(f"{n:5d} | {t1m:4.1f}x | {ia['fidelity_excess']:11.4f} | {xa['fidelity_excess']:11.4f} | "
|
| 384 |
+
f"{da['fidelity']:7.4f} | {gap:+7.4f} | {ia['mean_flips']:4.1f}±{ia['std_flips']:<4.1f} | "
|
| 385 |
+
f"{xa['mean_flips']:4.1f}±{xa['std_flips']:<4.1f}")
|
| 386 |
+
|
| 387 |
+
print(f"\n{'=' * 70}")
|
| 388 |
+
print("VERDICT")
|
| 389 |
+
print(f"{'=' * 70}")
|
| 390 |
+
|
| 391 |
+
# Compare decline rates
|
| 392 |
+
i_fids = []
|
| 393 |
+
x_fids = []
|
| 394 |
+
for n in n_values:
|
| 395 |
+
ik = f"identity_zeno_N{n}"
|
| 396 |
+
xk = f"x_zeno_N{n}"
|
| 397 |
+
if ik in results_data and xk in results_data:
|
| 398 |
+
i_fids.append(results_data[ik]['analysis']['fidelity_excess'])
|
| 399 |
+
x_fids.append(results_data[xk]['analysis']['fidelity_excess'])
|
| 400 |
+
|
| 401 |
+
i_decline = i_fids[0] - i_fids[-1]
|
| 402 |
+
x_decline = x_fids[0] - x_fids[-1]
|
| 403 |
+
|
| 404 |
+
print(f"\n Identity Zeno decline (N={n_values[0]} to N={n_values[-1]}): {i_decline:+.4f}")
|
| 405 |
+
print(f" X gate Zeno decline (N={n_values[0]} to N={n_values[-1]}): {x_decline:+.4f}")
|
| 406 |
+
print(f" Difference: {x_decline - i_decline:.4f}")
|
| 407 |
+
|
| 408 |
+
if i_decline < 0.05 and x_decline > 0.10:
|
| 409 |
+
print(f"\n GATE ERRORS are the bottleneck.")
|
| 410 |
+
print(f" Identity Zeno holds steady — the measurement mechanism works.")
|
| 411 |
+
print(f" X Zeno declines — accumulated Ry rotation errors cause the drop.")
|
| 412 |
+
print(f" Better gates would eliminate the decline.")
|
| 413 |
+
elif abs(i_decline - x_decline) < 0.05:
|
| 414 |
+
print(f"\n MEASUREMENT MECHANISM is the bottleneck.")
|
| 415 |
+
print(f" Both identity and X decline similarly.")
|
| 416 |
+
print(f" The rotations aren't the problem — repeated measurement itself degrades fidelity.")
|
| 417 |
+
else:
|
| 418 |
+
print(f"\n MIXED: both contribute.")
|
| 419 |
+
print(f" Identity decline: {i_decline:.4f}")
|
| 420 |
+
print(f" X decline: {x_decline:.4f}")
|
| 421 |
+
print(f" Gate errors account for ~{(x_decline - i_decline)/x_decline*100:.0f}% of the decline.")
|
| 422 |
+
|
| 423 |
+
usage_after = check_usage(service)
|
| 424 |
+
log(f"\nUsage: {usage_after['total']}s / 600s ({usage_after['percentage']:.1f}%)")
|
| 425 |
+
log(f"This job: {job.usage() or 0}s")
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
if __name__ == '__main__':
|
| 429 |
+
try:
|
| 430 |
+
main()
|
| 431 |
+
except KeyboardInterrupt:
|
| 432 |
+
log("Interrupted.")
|
| 433 |
+
sys.exit(1)
|
| 434 |
+
except Exception as e:
|
| 435 |
+
log(f"FATAL: {e}")
|
| 436 |
+
import traceback
|
| 437 |
+
traceback.print_exc()
|
| 438 |
+
sys.exit(1)
|