CharlesCNorton commited on
Commit ·
9ea6dfa
1
Parent(s): 4db2247
Add extended N sweep (N=512, 1024) and rename experiment folders
Browse filesZeno excess-flip fidelity: 82.7% at 6.9×T1, 77.0% at 13.9×T1.
Delay-matched control thermalized at ~17% by 3×T1.
Renamed zeno_past_t1 -> zeno_high_n_sweep,
zeno_extreme -> zeno_extended_n_sweep.
README.md
CHANGED
|
@@ -608,9 +608,9 @@ Zeno fidelity remains flat at 95.5% ± 0.7% across all N values (linear regressi
|
|
| 608 |
|
| 609 |
99 circuits, 4096 shots each, job ID d6jh8akgmsgc73bv2uu0, 113s QPU time. March 3, 2026.
|
| 610 |
|
| 611 |
-
### Zeno
|
| 612 |
|
| 613 |
-
**
|
| 614 |
|
| 615 |
At these N values, hard post-selection is not viable: the probability of all intermediate measurements returning 0 is (1−0.116)^256 ≈ 10⁻¹⁴, and zero shots pass at N ≥ 192. Four trajectory weighting schemes are compared: exp(−k), calibrated exp(−αk) tuned to the measurement error rate, an excess-flip scheme that penalizes only flips beyond the expected measurement error count, and a binomial likelihood ratio. The excess-flip scheme is reported below as the most conservative estimate that accounts for the high expected flip count from measurement error at large N.
|
| 616 |
|
|
@@ -626,7 +626,19 @@ At these N values, hard post-selection is not viable: the probability of all int
|
|
| 626 |
|
| 627 |
At 3.47× T1 the delay-matched control reads 18.3%, approaching the thermal floor. Zeno excess-flip weighted fidelity is 85.1%. The gap between Zeno and delay-matched grows monotonically with circuit time. Zeno fidelity declines by approximately 3 percentage points from N=8 to N=256, while the delay-matched control declines by 56 percentage points over the same range.
|
| 628 |
|
| 629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
|
| 631 |
---
|
| 632 |
|
|
|
|
| 608 |
|
| 609 |
99 circuits, 4096 shots each, job ID d6jh8akgmsgc73bv2uu0, 113s QPU time. March 3, 2026.
|
| 610 |
|
| 611 |
+
### Zeno High-N Sweep
|
| 612 |
|
| 613 |
+
**zeno_high_n_sweep/** — Extends the measurement duration experiment to circuit times well beyond the qubit's natural coherence lifetime. Tests N = 8, 16, 32, 48, 64, 96, 128, 192, 256 intermediate measurements for the X gate (θ = π), corresponding to total circuit times of 12.5μs to 399μs. Qubit 0 had T1 = 115.2μs at time of experiment, so N=256 corresponds to 3.47× T1. Nineteen circuits were run at 4096 shots each on ibm_torino (job d6jiid060irc7394imlg, 32s QPU time, March 3 2026).
|
| 614 |
|
| 615 |
At these N values, hard post-selection is not viable: the probability of all intermediate measurements returning 0 is (1−0.116)^256 ≈ 10⁻¹⁴, and zero shots pass at N ≥ 192. Four trajectory weighting schemes are compared: exp(−k), calibrated exp(−αk) tuned to the measurement error rate, an excess-flip scheme that penalizes only flips beyond the expected measurement error count, and a binomial likelihood ratio. The excess-flip scheme is reported below as the most conservative estimate that accounts for the high expected flip count from measurement error at large N.
|
| 616 |
|
|
|
|
| 626 |
|
| 627 |
At 3.47× T1 the delay-matched control reads 18.3%, approaching the thermal floor. Zeno excess-flip weighted fidelity is 85.1%. The gap between Zeno and delay-matched grows monotonically with circuit time. Zeno fidelity declines by approximately 3 percentage points from N=8 to N=256, while the delay-matched control declines by 56 percentage points over the same range.
|
| 628 |
|
| 629 |
+
### Zeno Extended N Sweep
|
| 630 |
+
|
| 631 |
+
**zeno_extended_n_sweep/** — Continues the high-N sweep to N = 512 and N = 1024, reaching circuit times of 799μs (6.93× T1) and 1597μs (13.86× T1). At N=1024 the qubit has thermalized nearly fourteen times over. The same four trajectory weighting schemes from the high-N sweep are applied, with the excess-flip scheme reported as the most conservative defensible estimate. Seven circuits were run at 4096 shots each on ibm_torino (job d6jjbc4mmeis739riovg, 32s QPU time, March 3 2026).
|
| 632 |
+
|
| 633 |
+
**Results (X gate, 4096 shots per circuit):**
|
| 634 |
+
|
| 635 |
+
| N | Time (μs) | ×T1 | Zeno (excess-flip) | Delay-matched | Gap |
|
| 636 |
+
|---|-----------|-----|--------------------|---------------|-----|
|
| 637 |
+
| 256 | 399.4 | 3.47 | 84.5% | 19.6% | +64.9pp |
|
| 638 |
+
| 512 | 798.7 | 6.93 | 82.7% | 17.1% | +65.5pp |
|
| 639 |
+
| 1024 | 1597.4 | 13.86 | 77.0% | 16.8% | +60.2pp |
|
| 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 |
|
results/zeno_extended_n_sweep/zeno_extended_n_sweep.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
results/{zeno_past_t1/zeno_past_t1.json → zeno_high_n_sweep/zeno_high_n_sweep.json}
RENAMED
|
File without changes
|
zeno_extended_n_sweep.py
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Zeno Extreme — N=512 and N=1024
|
| 3 |
+
|
| 4 |
+
N=512: 800μs, 6.9× T1
|
| 5 |
+
N=1024: 1597μs, 13.9× T1
|
| 6 |
+
|
| 7 |
+
Is the 3pp decline from N=8 to N=256 a slow linear death or an asymptote?
|
| 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_standard(theta):
|
| 64 |
+
qc = QuantumCircuit(1, 1)
|
| 65 |
+
qc.ry(theta, 0)
|
| 66 |
+
qc.ry(-theta, 0)
|
| 67 |
+
qc.measure(0, 0)
|
| 68 |
+
return qc
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def build_zeno(theta, n_meas):
|
| 72 |
+
qr = QuantumRegister(1, 'q')
|
| 73 |
+
cr = ClassicalRegister(n_meas + 1, 'c')
|
| 74 |
+
qc = QuantumCircuit(qr, cr)
|
| 75 |
+
|
| 76 |
+
for k in range(1, n_meas + 1):
|
| 77 |
+
theta_k = k * theta / n_meas
|
| 78 |
+
qc.ry(-theta_k, 0)
|
| 79 |
+
qc.measure(0, k - 1)
|
| 80 |
+
qc.ry(theta_k, 0)
|
| 81 |
+
|
| 82 |
+
qc.ry(-theta, 0)
|
| 83 |
+
qc.measure(0, n_meas)
|
| 84 |
+
return qc
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def build_delay_matched(theta, n_meas, meas_duration_dt):
|
| 88 |
+
qc = QuantumCircuit(1, 1)
|
| 89 |
+
qc.ry(theta, 0)
|
| 90 |
+
qc.delay(n_meas * meas_duration_dt, 0, unit='dt')
|
| 91 |
+
qc.ry(-theta, 0)
|
| 92 |
+
qc.measure(0, 0)
|
| 93 |
+
return qc
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def analyze_zeno(bitstrings, n_meas, p_meas):
|
| 97 |
+
total = len(bitstrings)
|
| 98 |
+
successful = 0
|
| 99 |
+
correct_given_success = 0
|
| 100 |
+
flip_bins = {}
|
| 101 |
+
|
| 102 |
+
for bs in bitstrings:
|
| 103 |
+
if len(bs) < n_meas + 1:
|
| 104 |
+
continue
|
| 105 |
+
|
| 106 |
+
final = bs[0]
|
| 107 |
+
intermediate = bs[1:n_meas + 1]
|
| 108 |
+
n_flips = sum(1 for b in intermediate if b == '1')
|
| 109 |
+
|
| 110 |
+
if n_flips not in flip_bins:
|
| 111 |
+
flip_bins[n_flips] = {'total': 0, 'correct': 0}
|
| 112 |
+
flip_bins[n_flips]['total'] += 1
|
| 113 |
+
if final == '0':
|
| 114 |
+
flip_bins[n_flips]['correct'] += 1
|
| 115 |
+
|
| 116 |
+
if n_flips == 0:
|
| 117 |
+
successful += 1
|
| 118 |
+
if final == '0':
|
| 119 |
+
correct_given_success += 1
|
| 120 |
+
|
| 121 |
+
success_rate = successful / total if total > 0 else 0
|
| 122 |
+
fidelity_hard = correct_given_success / successful if successful > 0 else 0
|
| 123 |
+
|
| 124 |
+
expected_meas_flips = n_meas * p_meas
|
| 125 |
+
|
| 126 |
+
# exp(-k)
|
| 127 |
+
w1_c, w1_t = 0, 0
|
| 128 |
+
for nf, data in flip_bins.items():
|
| 129 |
+
w = np.exp(-nf)
|
| 130 |
+
w1_c += w * data['correct']
|
| 131 |
+
w1_t += w * data['total']
|
| 132 |
+
fid_exp_k = w1_c / w1_t if w1_t > 0 else 0
|
| 133 |
+
|
| 134 |
+
# Calibrated exp(-α·k)
|
| 135 |
+
alpha = np.log(2) / max(expected_meas_flips, 1)
|
| 136 |
+
w2_c, w2_t = 0, 0
|
| 137 |
+
for nf, data in flip_bins.items():
|
| 138 |
+
w = np.exp(-alpha * nf)
|
| 139 |
+
w2_c += w * data['correct']
|
| 140 |
+
w2_t += w * data['total']
|
| 141 |
+
fid_calibrated = w2_c / w2_t if w2_t > 0 else 0
|
| 142 |
+
|
| 143 |
+
# Excess-flip
|
| 144 |
+
beta = 1.0
|
| 145 |
+
w3_c, w3_t = 0, 0
|
| 146 |
+
for nf, data in flip_bins.items():
|
| 147 |
+
excess = max(0, nf - expected_meas_flips)
|
| 148 |
+
w = np.exp(-beta * excess)
|
| 149 |
+
w3_c += w * data['correct']
|
| 150 |
+
w3_t += w * data['total']
|
| 151 |
+
fid_excess = w3_c / w3_t if w3_t > 0 else 0
|
| 152 |
+
|
| 153 |
+
# Likelihood ratio
|
| 154 |
+
w4_c, w4_t = 0, 0
|
| 155 |
+
for nf, data in flip_bins.items():
|
| 156 |
+
if nf <= n_meas:
|
| 157 |
+
p_target = comb(n_meas, nf, exact=True) * (p_meas ** nf) * ((1 - p_meas) ** (n_meas - nf))
|
| 158 |
+
p_random = comb(n_meas, nf, exact=True) * (0.5 ** n_meas)
|
| 159 |
+
w = min(p_target / p_random, 1e10) if p_random > 0 else 0
|
| 160 |
+
else:
|
| 161 |
+
w = 0
|
| 162 |
+
w4_c += w * data['correct']
|
| 163 |
+
w4_t += w * data['total']
|
| 164 |
+
fid_likelihood = w4_c / w4_t if w4_t > 0 else 0
|
| 165 |
+
|
| 166 |
+
all_flips = []
|
| 167 |
+
for nf, data in flip_bins.items():
|
| 168 |
+
all_flips.extend([nf] * data['total'])
|
| 169 |
+
mean_flips = np.mean(all_flips) if all_flips else 0
|
| 170 |
+
std_flips = np.std(all_flips) if all_flips else 0
|
| 171 |
+
|
| 172 |
+
return {
|
| 173 |
+
'total': total,
|
| 174 |
+
'successful': successful,
|
| 175 |
+
'success_rate': success_rate,
|
| 176 |
+
'fidelity_hard_ps': fidelity_hard,
|
| 177 |
+
'fidelity_exp_k': fid_exp_k,
|
| 178 |
+
'fidelity_calibrated': fid_calibrated,
|
| 179 |
+
'fidelity_excess': fid_excess,
|
| 180 |
+
'fidelity_likelihood': fid_likelihood,
|
| 181 |
+
'expected_meas_flips': expected_meas_flips,
|
| 182 |
+
'mean_flips': mean_flips,
|
| 183 |
+
'std_flips': std_flips,
|
| 184 |
+
'alpha_used': alpha,
|
| 185 |
+
'flip_distribution': {str(k): v for k, v in sorted(flip_bins.items())},
|
| 186 |
+
'type': 'zeno',
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def analyze_standard(bitstrings):
|
| 191 |
+
total = len(bitstrings)
|
| 192 |
+
zeros = sum(1 for b in bitstrings if b[-1] == '0')
|
| 193 |
+
return {'total': total, 'fidelity': zeros / total, 'type': 'standard'}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def main():
|
| 197 |
+
print("=" * 70)
|
| 198 |
+
print("ZENO EXTREME — N=512 AND N=1024")
|
| 199 |
+
print("=" * 70)
|
| 200 |
+
|
| 201 |
+
service = QiskitRuntimeService(channel="ibm_cloud", instance="claude")
|
| 202 |
+
|
| 203 |
+
usage_before = check_usage(service)
|
| 204 |
+
log(f"Usage: {usage_before['total']}s / 600s ({usage_before['percentage']:.1f}%)")
|
| 205 |
+
log(f"Remaining: {usage_before['remaining']}s")
|
| 206 |
+
|
| 207 |
+
if usage_before['remaining'] < 30:
|
| 208 |
+
log("Less than 30s remaining. Aborting.")
|
| 209 |
+
return
|
| 210 |
+
|
| 211 |
+
backend = service.backend("ibm_torino")
|
| 212 |
+
log(f"Backend: {backend.name} ({backend.num_qubits}q)")
|
| 213 |
+
|
| 214 |
+
dt = backend.dt
|
| 215 |
+
target_obj = backend.target
|
| 216 |
+
meas_props = target_obj['measure'][(0,)]
|
| 217 |
+
meas_duration_s = meas_props.duration
|
| 218 |
+
meas_duration_dt = int(meas_duration_s / dt)
|
| 219 |
+
meas_error = meas_props.error
|
| 220 |
+
sx_duration_s = target_obj['sx'][(0,)].duration
|
| 221 |
+
|
| 222 |
+
props = backend.qubit_properties(0)
|
| 223 |
+
T1 = props.t1
|
| 224 |
+
T2 = props.t2
|
| 225 |
+
|
| 226 |
+
log(f"Measurement: {meas_duration_s*1e6:.3f} us, error={meas_error:.4f}")
|
| 227 |
+
log(f"Qubit 0: T1={T1*1e6:.1f} us, T2={T2*1e6:.1f} us")
|
| 228 |
+
|
| 229 |
+
theta = np.pi
|
| 230 |
+
# Include N=256 for continuity with previous experiment
|
| 231 |
+
n_values = [256, 512, 1024]
|
| 232 |
+
shots = 4096
|
| 233 |
+
|
| 234 |
+
print(f"\nExperiment plan:")
|
| 235 |
+
print(f"{'N':>5} | {'Time(us)':>8} | {'T1 mult':>7} | {'Exp flips':>9} | {'Depth est':>9}")
|
| 236 |
+
print("-" * 50)
|
| 237 |
+
for n in n_values:
|
| 238 |
+
t_us = n * meas_duration_s * 1e6
|
| 239 |
+
t1_mult = n * meas_duration_s / T1
|
| 240 |
+
exp_flips = n * meas_error
|
| 241 |
+
depth_est = n * 5 # rough: each step ~5 native gates
|
| 242 |
+
print(f"{n:5d} | {t_us:8.1f} | {t1_mult:7.1f}x | {exp_flips:9.1f} | {depth_est:9d}")
|
| 243 |
+
|
| 244 |
+
all_experiments = []
|
| 245 |
+
|
| 246 |
+
# Standard baseline
|
| 247 |
+
all_experiments.append(ExperimentConfig(
|
| 248 |
+
name="standard_X",
|
| 249 |
+
circuit=build_standard(theta),
|
| 250 |
+
category="standard",
|
| 251 |
+
params={'gate': 'X', 'theta': theta, 'n_meas': 0},
|
| 252 |
+
))
|
| 253 |
+
|
| 254 |
+
for n in n_values:
|
| 255 |
+
total_time_us = n * meas_duration_s * 1e6
|
| 256 |
+
t1_mult = n * meas_duration_s / T1
|
| 257 |
+
|
| 258 |
+
all_experiments.append(ExperimentConfig(
|
| 259 |
+
name=f"zeno_X_N{n}",
|
| 260 |
+
circuit=build_zeno(theta, n),
|
| 261 |
+
category="zeno",
|
| 262 |
+
params={'gate': 'X', 'theta': theta, 'n_meas': n,
|
| 263 |
+
'total_time_us': total_time_us,
|
| 264 |
+
'T1_multiple': t1_mult},
|
| 265 |
+
))
|
| 266 |
+
|
| 267 |
+
all_experiments.append(ExperimentConfig(
|
| 268 |
+
name=f"delay_X_N{n}",
|
| 269 |
+
circuit=build_delay_matched(theta, n, meas_duration_dt),
|
| 270 |
+
category="delay_matched",
|
| 271 |
+
params={'gate': 'X', 'theta': theta, 'n_meas': n,
|
| 272 |
+
'total_time_us': total_time_us,
|
| 273 |
+
'T1_multiple': t1_mult},
|
| 274 |
+
))
|
| 275 |
+
|
| 276 |
+
log(f"Total experiments: {len(all_experiments)}")
|
| 277 |
+
|
| 278 |
+
log("Transpiling...")
|
| 279 |
+
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
|
| 280 |
+
|
| 281 |
+
transpiled = []
|
| 282 |
+
for exp in all_experiments:
|
| 283 |
+
try:
|
| 284 |
+
tc = pm.run(exp.circuit)
|
| 285 |
+
transpiled.append(tc)
|
| 286 |
+
except Exception as e:
|
| 287 |
+
log(f"ERROR transpiling {exp.name}: {e}")
|
| 288 |
+
transpiled.append(None)
|
| 289 |
+
|
| 290 |
+
valid_indices = [i for i, tc in enumerate(transpiled) if tc is not None]
|
| 291 |
+
valid_transpiled = [transpiled[i] for i in valid_indices]
|
| 292 |
+
valid_experiments = [all_experiments[i] for i in valid_indices]
|
| 293 |
+
|
| 294 |
+
log(f"Transpiled: {len(valid_transpiled)}/{len(all_experiments)}")
|
| 295 |
+
|
| 296 |
+
depths = [tc.depth() for tc in valid_transpiled]
|
| 297 |
+
log(f"Depths: min={min(depths)}, max={max(depths)}")
|
| 298 |
+
|
| 299 |
+
for i, exp in enumerate(valid_experiments):
|
| 300 |
+
exp.params['transpiled_depth'] = depths[i]
|
| 301 |
+
|
| 302 |
+
log("Submitting batch...")
|
| 303 |
+
start_time = datetime.now(timezone.utc)
|
| 304 |
+
|
| 305 |
+
with Batch(backend=backend) as batch:
|
| 306 |
+
sampler = SamplerV2(mode=batch)
|
| 307 |
+
job = sampler.run(valid_transpiled, shots=shots)
|
| 308 |
+
log(f"Job ID: {job.job_id()}")
|
| 309 |
+
log("Waiting...")
|
| 310 |
+
job.wait_for_final_state()
|
| 311 |
+
|
| 312 |
+
end_time = datetime.now(timezone.utc)
|
| 313 |
+
wall_time = (end_time - start_time).total_seconds()
|
| 314 |
+
log(f"Done. Wall time: {wall_time:.1f}s, QPU: {job.usage() or 0}s")
|
| 315 |
+
|
| 316 |
+
result = job.result()
|
| 317 |
+
metrics = job.metrics()
|
| 318 |
+
results_data = {}
|
| 319 |
+
|
| 320 |
+
for i, exp in enumerate(valid_experiments):
|
| 321 |
+
pub_result = result[i]
|
| 322 |
+
data_bin = pub_result.data
|
| 323 |
+
|
| 324 |
+
if hasattr(data_bin, 'c'):
|
| 325 |
+
bitstrings = list(data_bin.c.get_bitstrings())
|
| 326 |
+
elif hasattr(data_bin, 'meas'):
|
| 327 |
+
bitstrings = list(data_bin.meas.get_bitstrings())
|
| 328 |
+
else:
|
| 329 |
+
cr_name = list(data_bin.keys())[0]
|
| 330 |
+
bitstrings = list(getattr(data_bin, cr_name).get_bitstrings())
|
| 331 |
+
|
| 332 |
+
if exp.category == 'zeno':
|
| 333 |
+
analysis = analyze_zeno(bitstrings, exp.params['n_meas'], meas_error)
|
| 334 |
+
else:
|
| 335 |
+
analysis = analyze_standard(bitstrings)
|
| 336 |
+
|
| 337 |
+
results_data[exp.name] = {
|
| 338 |
+
'category': exp.category,
|
| 339 |
+
'params': {k: (float(v) if isinstance(v, (np.floating, float)) else v)
|
| 340 |
+
for k, v in exp.params.items()},
|
| 341 |
+
'analysis': analysis,
|
| 342 |
+
'raw_bitstrings': bitstrings[:500],
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
# Save
|
| 346 |
+
output = {
|
| 347 |
+
'experiment': 'zeno_extreme',
|
| 348 |
+
'description': 'Zeno at N=512 and N=1024 — 6.9x and 13.9x T1',
|
| 349 |
+
'timestamp': start_time.isoformat(),
|
| 350 |
+
'backend': backend.name,
|
| 351 |
+
'shots': shots,
|
| 352 |
+
'job_id': job.job_id(),
|
| 353 |
+
'usage_seconds': job.usage() or 0,
|
| 354 |
+
'wall_time_seconds': wall_time,
|
| 355 |
+
'metrics': metrics,
|
| 356 |
+
'hardware_timing': {
|
| 357 |
+
'dt_ns': dt * 1e9,
|
| 358 |
+
'measurement_duration_us': meas_duration_s * 1e6,
|
| 359 |
+
'measurement_duration_dt': meas_duration_dt,
|
| 360 |
+
'measurement_error': meas_error,
|
| 361 |
+
'sx_duration_ns': sx_duration_s * 1e9,
|
| 362 |
+
'qubit_0_T1_us': T1 * 1e6,
|
| 363 |
+
'qubit_0_T2_us': T2 * 1e6,
|
| 364 |
+
},
|
| 365 |
+
'results': results_data,
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
outfile = DATA_DIR / 'results' / 'zeno_extreme' / 'zeno_extreme.json'
|
| 369 |
+
outfile.parent.mkdir(exist_ok=True)
|
| 370 |
+
with open(outfile, 'w') as f:
|
| 371 |
+
json.dump(output, f, indent=2, default=str)
|
| 372 |
+
log(f"Saved: {outfile}")
|
| 373 |
+
|
| 374 |
+
# =========================================================================
|
| 375 |
+
# RESULTS
|
| 376 |
+
# =========================================================================
|
| 377 |
+
print("\n" + "=" * 70)
|
| 378 |
+
print("ZENO EXTREME")
|
| 379 |
+
print("=" * 70)
|
| 380 |
+
|
| 381 |
+
std_fid = results_data['standard_X']['analysis']['fidelity']
|
| 382 |
+
print(f"\nStandard X gate: {std_fid:.4f}")
|
| 383 |
+
print(f"Qubit 0 T1: {T1*1e6:.1f} us")
|
| 384 |
+
|
| 385 |
+
print(f"\n{'N':>5} | {'Time':>7} | {'×T1':>5} | {'exp(-k)':>7} | {'Excess':>7} | {'LikeR':>7} | {'Delay':>7} | {'Gap':>7} | {'Flips':>12}")
|
| 386 |
+
print("-" * 85)
|
| 387 |
+
|
| 388 |
+
for n in n_values:
|
| 389 |
+
zk = f"zeno_X_N{n}"
|
| 390 |
+
dk = f"delay_X_N{n}"
|
| 391 |
+
if zk not in results_data or dk not in results_data:
|
| 392 |
+
continue
|
| 393 |
+
|
| 394 |
+
za = results_data[zk]['analysis']
|
| 395 |
+
da = results_data[dk]['analysis']
|
| 396 |
+
t_us = results_data[zk]['params']['total_time_us']
|
| 397 |
+
t1m = results_data[zk]['params']['T1_multiple']
|
| 398 |
+
|
| 399 |
+
best = max(za['fidelity_excess'], za['fidelity_likelihood'])
|
| 400 |
+
gap = best - da['fidelity']
|
| 401 |
+
|
| 402 |
+
print(f"{n:5d} | {t_us:5.0f}us | {t1m:4.1f}x | {za['fidelity_exp_k']:.4f} | "
|
| 403 |
+
f"{za['fidelity_excess']:.4f} | {za['fidelity_likelihood']:.4f} | "
|
| 404 |
+
f"{da['fidelity']:.4f} | {gap:+.4f} | {za['mean_flips']:.1f}±{za['std_flips']:.1f}")
|
| 405 |
+
|
| 406 |
+
# Combined table with previous results
|
| 407 |
+
print(f"\n{'=' * 70}")
|
| 408 |
+
print("COMBINED: Full N sweep (from all three experiments)")
|
| 409 |
+
print(f"{'=' * 70}")
|
| 410 |
+
print(f"\n{'N':>5} | {'Time':>7} | {'×T1':>6} | {'Excess':>7} | {'Delay':>7} | {'Gap':>7}")
|
| 411 |
+
print("-" * 55)
|
| 412 |
+
|
| 413 |
+
# Hardcode previous results for the combined view
|
| 414 |
+
prev = {
|
| 415 |
+
8: {'excess': None, 'delay': None}, # will come from this run's N=256 continuity
|
| 416 |
+
32: {'excess': 0.9160, 'delay': 0.5571},
|
| 417 |
+
64: {'excess': 0.9022, 'delay': 0.4060},
|
| 418 |
+
128: {'excess': 0.8647, 'delay': 0.2498},
|
| 419 |
+
256: {'excess': 0.8510, 'delay': 0.1826},
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
for n, p in sorted(prev.items()):
|
| 423 |
+
if p['excess'] is not None:
|
| 424 |
+
t_us = n * meas_duration_s * 1e6
|
| 425 |
+
t1m = n * meas_duration_s / T1
|
| 426 |
+
gap = p['excess'] - p['delay']
|
| 427 |
+
print(f"{n:5d} | {t_us:5.0f}us | {t1m:5.1f}x | {p['excess']:.4f} | {p['delay']:.4f} | {gap:+.4f}")
|
| 428 |
+
|
| 429 |
+
for n in [512, 1024]:
|
| 430 |
+
zk = f"zeno_X_N{n}"
|
| 431 |
+
dk = f"delay_X_N{n}"
|
| 432 |
+
if zk in results_data and dk in results_data:
|
| 433 |
+
za = results_data[zk]['analysis']
|
| 434 |
+
da = results_data[dk]['analysis']
|
| 435 |
+
t_us = results_data[zk]['params']['total_time_us']
|
| 436 |
+
t1m = results_data[zk]['params']['T1_multiple']
|
| 437 |
+
gap = za['fidelity_excess'] - da['fidelity']
|
| 438 |
+
print(f"{n:5d} | {t_us:5.0f}us | {t1m:5.1f}x | {za['fidelity_excess']:.4f} | {da['fidelity']:.4f} | {gap:+.4f}")
|
| 439 |
+
|
| 440 |
+
usage_after = check_usage(service)
|
| 441 |
+
log(f"\nUsage: {usage_after['total']}s / 600s ({usage_after['percentage']:.1f}%)")
|
| 442 |
+
log(f"This job: {job.usage() or 0}s")
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
if __name__ == '__main__':
|
| 446 |
+
try:
|
| 447 |
+
main()
|
| 448 |
+
except KeyboardInterrupt:
|
| 449 |
+
log("Interrupted.")
|
| 450 |
+
sys.exit(1)
|
| 451 |
+
except Exception as e:
|
| 452 |
+
log(f"FATAL: {e}")
|
| 453 |
+
import traceback
|
| 454 |
+
traceback.print_exc()
|
| 455 |
+
sys.exit(1)
|
zeno_past_t1.py → zeno_high_n_sweep.py
RENAMED
|
File without changes
|