CharlesCNorton commited on
Commit ·
a851e2d
1
Parent(s): f6ae2a3
Add full state tomography at high N without post-selection
Browse files30 circuits (5 N values x 3 Pauli bases x 2 categories), 8192 shots
each. Density matrices reconstructed from raw X/Y/Z measurements.
Per-flip-count bin tomography calibrates weighting schemes against
ground truth. 217s QPU on ibm_torino.
- .gitattributes +1 -0
- README.md +53 -3
- results/zeno_tomography/zeno_tomography.json +3 -0
- zeno_tomography.py +714 -0
.gitattributes
CHANGED
|
@@ -57,3 +57,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
results/zeno_tomography/zeno_tomography.json filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -772,6 +772,56 @@ Identity Zeno tells a different story. With no rotations to corrupt, the pure me
|
|
| 772 |
|
| 773 |
**Two-qubit (2 circuits).** Standard CNOT round-trip on Q37-Q52: 99.6%. Zeno CNOT with soft k≤2: 91.5%. Two-qubit Zeno overhead still exceeds the post-selection benefit.
|
| 774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
---
|
| 776 |
|
| 777 |
## Data Format
|
|
@@ -834,10 +884,10 @@ Full calibration data for all 133 qubits is embedded in `results/zeno_megabatch/
|
|
| 834 |
|
| 835 |
### Execution Details
|
| 836 |
|
| 837 |
-
- **Shots per circuit**: 2048–
|
| 838 |
- **Execution mode**: IBM Quantum Runtime Batch (parallel compilation)
|
| 839 |
-
- **Total QPU time**: ~200 seconds across January 2026 experiments; 155 seconds for March 2026 measurement duration experiments; 56 seconds for weakness tests
|
| 840 |
-
- **Temporal window**: January experiments completed within 24 hours (single calibration epoch); measurement duration
|
| 841 |
|
| 842 |
---
|
| 843 |
|
|
|
|
| 772 |
|
| 773 |
**Two-qubit (2 circuits).** Standard CNOT round-trip on Q37-Q52: 99.6%. Zeno CNOT with soft k≤2: 91.5%. Two-qubit Zeno overhead still exceeds the post-selection benefit.
|
| 774 |
|
| 775 |
+
### State Tomography
|
| 776 |
+
|
| 777 |
+
**results/zeno_tomography/zeno_tomography.json** — Full single-qubit quantum state tomography of Zeno-dragged states at N = 32, 128, 256, 512, and 1024 intermediate measurements. For each N, the qubit is dragged from |0⟩ to |1⟩ via the standard Zeno protocol (no undo rotation), then measured in the X, Y, and Z Pauli bases using separate circuits. The three basis measurements yield expectation values ⟨X⟩, ⟨Y⟩, ⟨Z⟩, from which the single-qubit density matrix is reconstructed as ρ = (I + ⟨X⟩σ_X + ⟨Y⟩σ_Y + ⟨Z⟩σ_Z)/2. No post-selection or trajectory weighting is applied to the raw tomographic reconstruction. Delay-matched controls (Ry(π)|0⟩ + equivalent idle time) are measured identically at every N. Thirty circuits total (5 N values × 3 bases × 2 categories), 8192 shots each, submitted as a single Batch on ibm_torino qubit 0 (job d6jm6ko60irc7394n5u0, 217s QPU, March 3 2026). Script: `zeno_tomography.py`.
|
| 778 |
+
|
| 779 |
+
**Raw tomographic fidelity with |1⟩ (no selection, no weighting):**
|
| 780 |
+
|
| 781 |
+
| N | ×T1 | Zeno F(|1⟩) | Zeno Purity | Delay F(|1⟩) | Delay Purity | Zeno − Delay |
|
| 782 |
+
|---|-----|-------------|-------------|--------------|--------------|--------------|
|
| 783 |
+
| 32 | 0.4 | 71.7% | 59.4% | 58.0% | 51.7% | +13.7pp |
|
| 784 |
+
| 128 | 1.7 | 70.5% | 58.4% | 26.3% | 61.4% | +44.2pp |
|
| 785 |
+
| 256 | 3.5 | 70.2% | 58.2% | 16.4% | 72.9% | +53.8pp |
|
| 786 |
+
| 512 | 6.9 | 70.1% | 58.2% | 12.8% | 78.1% | +57.3pp |
|
| 787 |
+
| 1024 | 13.9 | 69.7% | 57.8% | 13.2% | 77.4% | +56.6pp |
|
| 788 |
+
|
| 789 |
+
The Zeno-dragged state maintains 69.7% fidelity with |1⟩ at N = 1024 (13.9× T1) without any trajectory selection. The delay-matched control thermalizes to ~13% fidelity (near the maximally mixed value of 50%, shifted by readout asymmetry on qubit 0) by 3.5× T1 and remains there. The fidelity gap between Zeno and delay increases with N as the control decays while the Zeno-protected state remains approximately constant, declining by only 2 percentage points from N = 32 to N = 1024.
|
| 790 |
+
|
| 791 |
+
The Bloch vector components provide additional information. Across all N, the Zeno state has ⟨X⟩ ≈ 0 and ⟨Y⟩ ≈ 0 with ⟨Z⟩ between −0.39 and −0.43, indicating the state lies near the −Z axis (consistent with |1⟩) but with significant depolarization. The Bloch vector length |r| ≈ 0.40 at all N values indicates a substantially mixed state. By comparison, the delay-matched control's Bloch vector rotates toward +Z (the thermal equilibrium state |0⟩) with increasing N, reaching ⟨Z⟩ = +0.74 at N = 512.
|
| 792 |
+
|
| 793 |
+
**Per-bin tomography.** The same shots are binned by intermediate flip count, and density matrices are reconstructed independently for each bin. This provides the true state fidelity at each flip count without relying on the final Z-basis measurement alone. Representative results at N = 32:
|
| 794 |
+
|
| 795 |
+
| Flips | Shots | ⟨X⟩ | ⟨Y⟩ | ⟨Z⟩ | F(|1⟩) | Purity |
|
| 796 |
+
|-------|-------|------|------|------|--------|--------|
|
| 797 |
+
| 0 | 1269 | +0.017 | +0.132 | −0.830 | 91.5% | 85.3% |
|
| 798 |
+
| 1 | 1872 | +0.051 | +0.109 | −0.829 | 91.5% | 85.1% |
|
| 799 |
+
| 2 | 1365 | +0.081 | +0.003 | −0.804 | 90.2% | 82.6% |
|
| 800 |
+
| 3 | 658 | +0.068 | +0.115 | −0.647 | 82.4% | 71.9% |
|
| 801 |
+
| 4 | 312 | −0.020 | +0.041 | −0.455 | 72.8% | 60.5% |
|
| 802 |
+
| 5 | 173 | −0.138 | −0.065 | −0.133 | 56.7% | 52.0% |
|
| 803 |
+
| ≥6 | — | — | — | ~0 to +0.3 | ~40% | ~52% |
|
| 804 |
+
|
| 805 |
+
Fidelity decreases monotonically with flip count through k = 5, consistent with the interpretation that intermediate flips indicate trajectory corruption. The k = 0 and k = 1 bins have nearly identical tomographic fidelity (91.5%), suggesting that a single flip at N = 32 is more likely a measurement readout error than a genuine state disturbance. By k = 5, the state has depolarized to near the maximally mixed state (purity ≈ 0.52, fidelity ≈ 0.57).
|
| 806 |
+
|
| 807 |
+
**Weighting scheme ground-truth calibration.** The per-bin tomographic fidelities provide a model-free reference for evaluating trajectory weighting schemes. For each scheme, the weighted average of per-bin fidelities is computed using the scheme's weight function and the empirical bin populations. Selected results:
|
| 808 |
+
|
| 809 |
+
| N | Scheme | Tomographic F | Utilization | Effective Yield |
|
| 810 |
+
|---|--------|---------------|-------------|-----------------|
|
| 811 |
+
| 32 | Unweighted | 71.4% | 100% | 71.4% |
|
| 812 |
+
| 32 | Hard PS (k=0) | 91.5% | 15.5% | 14.1% |
|
| 813 |
+
| 32 | Soft k≤2 | 91.1% | 54.7% | 49.8% |
|
| 814 |
+
| 32 | Excess-flip | 88.8% | 66.3% | 58.9% |
|
| 815 |
+
| 128 | Unweighted | 70.7% | 100% | 70.7% |
|
| 816 |
+
| 128 | Hard PS (k=0) | 93.3% | 0.2% | 0.2% |
|
| 817 |
+
| 128 | Soft k≤2 | 92.6% | 3.0% | 2.8% |
|
| 818 |
+
| 128 | Excess-flip | 86.9% | 45.2% | 39.2% |
|
| 819 |
+
| 1024 | Unweighted | 70.0% | 100% | 70.0% |
|
| 820 |
+
|
| 821 |
+
At N = 32, the unweighted tomographic fidelity (71.4%) represents the assumption-free baseline. Hard post-selection achieves the highest per-shot fidelity (91.5%) but retains only 15.5% of shots. The excess-flip scheme provides the best tradeoff at moderate N (58.9% yield at N = 32). At N ≥ 128, hard post-selection and soft k≤2 retain too few shots for reliable estimation; the excess-flip and calibrated exponential schemes maintain higher utilization but with reduced fidelity.
|
| 822 |
+
|
| 823 |
+
At N = 1024, only the unweighted estimator retains meaningful utilization (100%, by definition). The per-bin fidelities at N = 1024 show no systematic dependence on flip count within the range where bins are populated (k ≈ 120–530), as the flip count distribution has shifted far from zero due to the 11.6% measurement error rate on qubit 0. The raw unweighted fidelity of 70.0% at 13.9× T1, compared to the delay-matched control at 13.2%, confirms that the Zeno mechanism preserves state information well beyond the qubit's natural coherence time. This result does not depend on any trajectory weighting or post-selection.
|
| 824 |
+
|
| 825 |
---
|
| 826 |
|
| 827 |
## Data Format
|
|
|
|
| 884 |
|
| 885 |
### Execution Details
|
| 886 |
|
| 887 |
+
- **Shots per circuit**: 2048–8192 depending on experiment
|
| 888 |
- **Execution mode**: IBM Quantum Runtime Batch (parallel compilation)
|
| 889 |
+
- **Total QPU time**: ~200 seconds across January 2026 experiments; 155 seconds for March 2026 measurement duration experiments; 56 seconds for weakness tests; 217 seconds for state tomography
|
| 890 |
+
- **Temporal window**: January experiments completed within 24 hours (single calibration epoch); measurement duration, weakness test, and state tomography experiments conducted March 3, 2026
|
| 891 |
|
| 892 |
---
|
| 893 |
|
results/zeno_tomography/zeno_tomography.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3062d8f2aba251da7a11444c7914a2b707899e4e36d31f909b80f41b63232616
|
| 3 |
+
size 51237437
|
zeno_tomography.py
ADDED
|
@@ -0,0 +1,714 @@
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Zeno Dragging State Tomography
|
| 3 |
+
|
| 4 |
+
Full quantum state tomography of Zeno-dragged states at high measurement
|
| 5 |
+
counts. Measures in X, Y, and Z Pauli bases without post-selection or
|
| 6 |
+
trajectory weighting. Reconstructs single-qubit density matrices from raw
|
| 7 |
+
statistics. Per-flip-count bin tomography provides assumption-free ground
|
| 8 |
+
truth for calibrating all weighting schemes.
|
| 9 |
+
|
| 10 |
+
Protocol:
|
| 11 |
+
Zeno: drag |0> to |1> via N intermediate projective measurements,
|
| 12 |
+
then measure in X, Y, or Z basis (no undo rotation).
|
| 13 |
+
Control: Ry(pi)|0> + equivalent idle delay + basis measurement.
|
| 14 |
+
|
| 15 |
+
For each N, six circuits are submitted (3 bases x 2 categories).
|
| 16 |
+
Shots are binned by intermediate flip count after collection, and
|
| 17 |
+
density matrices are reconstructed per bin independently.
|
| 18 |
+
|
| 19 |
+
N values: 32, 128, 256, 512, 1024
|
| 20 |
+
Shots: 8192 per circuit
|
| 21 |
+
Target state: |1>
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
import json
|
| 25 |
+
import sys
|
| 26 |
+
from datetime import datetime, timezone
|
| 27 |
+
from dataclasses import dataclass
|
| 28 |
+
from pathlib import Path
|
| 29 |
+
import numpy as np
|
| 30 |
+
from scipy.special import comb
|
| 31 |
+
|
| 32 |
+
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
|
| 33 |
+
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
|
| 34 |
+
from qiskit_ibm_runtime import (
|
| 35 |
+
QiskitRuntimeService,
|
| 36 |
+
SamplerV2,
|
| 37 |
+
Batch,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
DATA_DIR = Path("D:/qiskit-zenodragging")
|
| 42 |
+
RESULTS_DIR = DATA_DIR / "results" / "zeno_tomography"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@dataclass
|
| 46 |
+
class ExperimentConfig:
|
| 47 |
+
name: str
|
| 48 |
+
circuit: QuantumCircuit
|
| 49 |
+
category: str
|
| 50 |
+
params: dict
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def log(msg, level=0):
|
| 54 |
+
indent = " " * level
|
| 55 |
+
ts = datetime.now().strftime("%H:%M:%S")
|
| 56 |
+
print(f"[{ts}] {indent}{msg}")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def check_usage(service):
|
| 60 |
+
jobs = list(service.jobs(limit=200))
|
| 61 |
+
now = datetime.now(timezone.utc)
|
| 62 |
+
month_start = datetime(now.year, now.month, 1, tzinfo=timezone.utc)
|
| 63 |
+
total = 0
|
| 64 |
+
for j in jobs:
|
| 65 |
+
u = j.usage() or 0
|
| 66 |
+
try:
|
| 67 |
+
m = j.metrics()
|
| 68 |
+
ts = m.get('timestamps', {}).get('created', '')
|
| 69 |
+
if ts:
|
| 70 |
+
dt = datetime.fromisoformat(ts.replace('Z', '+00:00'))
|
| 71 |
+
if dt >= month_start:
|
| 72 |
+
total += u
|
| 73 |
+
except Exception:
|
| 74 |
+
pass
|
| 75 |
+
return {"total": total, "remaining": 600 - total, "percentage": 100 * total / 600}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# =============================================================================
|
| 79 |
+
# CIRCUIT BUILDERS
|
| 80 |
+
# =============================================================================
|
| 81 |
+
|
| 82 |
+
def build_zeno_tomo(theta, n_meas, basis):
|
| 83 |
+
"""Zeno drag |0> to |1> with final measurement in the specified basis.
|
| 84 |
+
|
| 85 |
+
Intermediate measurements are recorded for trajectory binning.
|
| 86 |
+
No undo rotation is applied — the qubit remains in the dragged state.
|
| 87 |
+
|
| 88 |
+
Args:
|
| 89 |
+
theta: total drag angle (pi for |0> -> |1>)
|
| 90 |
+
n_meas: number of intermediate projective measurements
|
| 91 |
+
basis: 'Z', 'X', or 'Y'
|
| 92 |
+
"""
|
| 93 |
+
qr = QuantumRegister(1, 'q')
|
| 94 |
+
cr = ClassicalRegister(n_meas + 1, 'c')
|
| 95 |
+
qc = QuantumCircuit(qr, cr)
|
| 96 |
+
|
| 97 |
+
for k in range(1, n_meas + 1):
|
| 98 |
+
theta_k = k * theta / n_meas
|
| 99 |
+
qc.ry(-theta_k, 0)
|
| 100 |
+
qc.measure(0, k - 1)
|
| 101 |
+
qc.ry(theta_k, 0)
|
| 102 |
+
|
| 103 |
+
if basis == 'X':
|
| 104 |
+
qc.h(0)
|
| 105 |
+
elif basis == 'Y':
|
| 106 |
+
qc.sdg(0)
|
| 107 |
+
qc.h(0)
|
| 108 |
+
|
| 109 |
+
qc.measure(0, n_meas)
|
| 110 |
+
return qc
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def build_delay_tomo(theta, n_meas, meas_duration_dt, basis):
|
| 114 |
+
"""Delay-matched control with final measurement in the specified basis.
|
| 115 |
+
|
| 116 |
+
Applies Ry(theta) then idles for the same wall-clock duration as the
|
| 117 |
+
corresponding Zeno circuit, then measures in the specified basis.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
theta: rotation angle
|
| 121 |
+
n_meas: number of Zeno steps to match in duration
|
| 122 |
+
meas_duration_dt: hardware measurement duration in dt units
|
| 123 |
+
basis: 'Z', 'X', or 'Y'
|
| 124 |
+
"""
|
| 125 |
+
qc = QuantumCircuit(1, 1)
|
| 126 |
+
qc.ry(theta, 0)
|
| 127 |
+
qc.delay(n_meas * meas_duration_dt, 0, unit='dt')
|
| 128 |
+
|
| 129 |
+
if basis == 'X':
|
| 130 |
+
qc.h(0)
|
| 131 |
+
elif basis == 'Y':
|
| 132 |
+
qc.sdg(0)
|
| 133 |
+
qc.h(0)
|
| 134 |
+
|
| 135 |
+
qc.measure(0, 0)
|
| 136 |
+
return qc
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# =============================================================================
|
| 140 |
+
# DENSITY MATRIX RECONSTRUCTION
|
| 141 |
+
# =============================================================================
|
| 142 |
+
|
| 143 |
+
def reconstruct_density_matrix(exp_x, exp_y, exp_z):
|
| 144 |
+
"""Reconstruct single-qubit density matrix from Pauli expectation values.
|
| 145 |
+
|
| 146 |
+
rho = (I + exp_x * sigma_X + exp_y * sigma_Y + exp_z * sigma_Z) / 2
|
| 147 |
+
"""
|
| 148 |
+
rho = np.array([
|
| 149 |
+
[1 + exp_z, exp_x - 1j * exp_y],
|
| 150 |
+
[exp_x + 1j * exp_y, 1 - exp_z],
|
| 151 |
+
], dtype=complex) / 2
|
| 152 |
+
return rho
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def state_fidelity_ket1(rho):
|
| 156 |
+
"""Fidelity of rho with |1>: F = <1|rho|1> = rho[1,1]."""
|
| 157 |
+
return float(np.real(rho[1, 1]))
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def purity(rho):
|
| 161 |
+
"""Tr(rho^2)."""
|
| 162 |
+
return float(np.real(np.trace(rho @ rho)))
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# =============================================================================
|
| 166 |
+
# ANALYSIS
|
| 167 |
+
# =============================================================================
|
| 168 |
+
|
| 169 |
+
def bin_zeno_shots(bitstrings, n_meas):
|
| 170 |
+
"""Parse Zeno bitstrings into flip-count bins.
|
| 171 |
+
|
| 172 |
+
Returns dict: {n_flips: {'zeros': int, 'total': int}}
|
| 173 |
+
where 'zeros' counts final-bit == '0' outcomes.
|
| 174 |
+
"""
|
| 175 |
+
bins = {}
|
| 176 |
+
total_zeros = 0
|
| 177 |
+
total_count = 0
|
| 178 |
+
|
| 179 |
+
for bs in bitstrings:
|
| 180 |
+
if len(bs) < n_meas + 1:
|
| 181 |
+
continue
|
| 182 |
+
|
| 183 |
+
final = bs[0]
|
| 184 |
+
intermediate = bs[1:n_meas + 1]
|
| 185 |
+
n_flips = sum(1 for b in intermediate if b == '1')
|
| 186 |
+
|
| 187 |
+
if n_flips not in bins:
|
| 188 |
+
bins[n_flips] = {'zeros': 0, 'total': 0}
|
| 189 |
+
bins[n_flips]['total'] += 1
|
| 190 |
+
if final == '0':
|
| 191 |
+
bins[n_flips]['zeros'] += 1
|
| 192 |
+
|
| 193 |
+
total_count += 1
|
| 194 |
+
if final == '0':
|
| 195 |
+
total_zeros += 1
|
| 196 |
+
|
| 197 |
+
return bins, total_zeros, total_count
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def analyze_zeno_tomo(bs_z, bs_x, bs_y, n_meas, p_meas):
|
| 201 |
+
"""Full tomographic analysis of Zeno-dragged state.
|
| 202 |
+
|
| 203 |
+
Performs:
|
| 204 |
+
1. Raw tomography over all shots (no selection).
|
| 205 |
+
2. Per-flip-count-bin tomography.
|
| 206 |
+
3. Weighting scheme comparison using per-bin ground truth.
|
| 207 |
+
"""
|
| 208 |
+
z_bins, z_zeros, z_total = bin_zeno_shots(bs_z, n_meas)
|
| 209 |
+
x_bins, x_zeros, x_total = bin_zeno_shots(bs_x, n_meas)
|
| 210 |
+
y_bins, y_zeros, y_total = bin_zeno_shots(bs_y, n_meas)
|
| 211 |
+
|
| 212 |
+
# --- Raw tomography (all shots, no selection) ---
|
| 213 |
+
def exp_val(zeros, total):
|
| 214 |
+
return 2 * zeros / total - 1 if total > 0 else 0.0
|
| 215 |
+
|
| 216 |
+
rho_raw = reconstruct_density_matrix(
|
| 217 |
+
exp_val(x_zeros, x_total),
|
| 218 |
+
exp_val(y_zeros, y_total),
|
| 219 |
+
exp_val(z_zeros, z_total),
|
| 220 |
+
)
|
| 221 |
+
raw_result = {
|
| 222 |
+
'exp_x': exp_val(x_zeros, x_total),
|
| 223 |
+
'exp_y': exp_val(y_zeros, y_total),
|
| 224 |
+
'exp_z': exp_val(z_zeros, z_total),
|
| 225 |
+
'fidelity': state_fidelity_ket1(rho_raw),
|
| 226 |
+
'purity': purity(rho_raw),
|
| 227 |
+
'shots_per_basis': z_total,
|
| 228 |
+
'rho_00': float(np.real(rho_raw[0, 0])),
|
| 229 |
+
'rho_01_re': float(np.real(rho_raw[0, 1])),
|
| 230 |
+
'rho_01_im': float(np.imag(rho_raw[0, 1])),
|
| 231 |
+
'rho_11': float(np.real(rho_raw[1, 1])),
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
# --- Per-bin tomography ---
|
| 235 |
+
all_flips = sorted(set(
|
| 236 |
+
list(z_bins.keys()) + list(x_bins.keys()) + list(y_bins.keys())
|
| 237 |
+
))
|
| 238 |
+
|
| 239 |
+
per_bin = {}
|
| 240 |
+
for nf in all_flips:
|
| 241 |
+
zd = z_bins.get(nf, {'zeros': 0, 'total': 0})
|
| 242 |
+
xd = x_bins.get(nf, {'zeros': 0, 'total': 0})
|
| 243 |
+
yd = y_bins.get(nf, {'zeros': 0, 'total': 0})
|
| 244 |
+
|
| 245 |
+
min_count = min(zd['total'], xd['total'], yd['total'])
|
| 246 |
+
if min_count < 10:
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
bexp_x = exp_val(xd['zeros'], xd['total'])
|
| 250 |
+
bexp_y = exp_val(yd['zeros'], yd['total'])
|
| 251 |
+
bexp_z = exp_val(zd['zeros'], zd['total'])
|
| 252 |
+
|
| 253 |
+
brho = reconstruct_density_matrix(bexp_x, bexp_y, bexp_z)
|
| 254 |
+
|
| 255 |
+
per_bin[str(nf)] = {
|
| 256 |
+
'n_flips': nf,
|
| 257 |
+
'shots_z': zd['total'],
|
| 258 |
+
'shots_x': xd['total'],
|
| 259 |
+
'shots_y': yd['total'],
|
| 260 |
+
'exp_x': float(bexp_x),
|
| 261 |
+
'exp_y': float(bexp_y),
|
| 262 |
+
'exp_z': float(bexp_z),
|
| 263 |
+
'fidelity': state_fidelity_ket1(brho),
|
| 264 |
+
'purity': purity(brho),
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
# --- Weighting scheme ground-truth comparison ---
|
| 268 |
+
weighting = _weighting_ground_truth(per_bin, n_meas, p_meas)
|
| 269 |
+
|
| 270 |
+
return {
|
| 271 |
+
'raw': raw_result,
|
| 272 |
+
'per_bin': per_bin,
|
| 273 |
+
'weighting_predictions': weighting,
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def analyze_delay_tomo(bs_z, bs_x, bs_y):
|
| 278 |
+
"""Tomography for delay-matched control (no intermediate measurements)."""
|
| 279 |
+
def exp_val(bitstrings):
|
| 280 |
+
total = len(bitstrings)
|
| 281 |
+
zeros = sum(1 for b in bitstrings if b[-1] == '0')
|
| 282 |
+
return 2 * zeros / total - 1 if total > 0 else 0.0, total
|
| 283 |
+
|
| 284 |
+
ex, nx = exp_val(bs_x)
|
| 285 |
+
ey, ny = exp_val(bs_y)
|
| 286 |
+
ez, nz = exp_val(bs_z)
|
| 287 |
+
|
| 288 |
+
rho = reconstruct_density_matrix(ex, ey, ez)
|
| 289 |
+
|
| 290 |
+
return {
|
| 291 |
+
'exp_x': float(ex),
|
| 292 |
+
'exp_y': float(ey),
|
| 293 |
+
'exp_z': float(ez),
|
| 294 |
+
'fidelity': state_fidelity_ket1(rho),
|
| 295 |
+
'purity': purity(rho),
|
| 296 |
+
'shots_per_basis': nz,
|
| 297 |
+
'rho_00': float(np.real(rho[0, 0])),
|
| 298 |
+
'rho_01_re': float(np.real(rho[0, 1])),
|
| 299 |
+
'rho_01_im': float(np.imag(rho[0, 1])),
|
| 300 |
+
'rho_11': float(np.real(rho[1, 1])),
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def _weighting_ground_truth(per_bin, n_meas, p_meas):
|
| 305 |
+
"""Evaluate weighting schemes against per-bin tomographic fidelity.
|
| 306 |
+
|
| 307 |
+
Uses the per-bin density-matrix fidelity as ground truth to compute
|
| 308 |
+
the weighted-average fidelity each scheme would produce.
|
| 309 |
+
"""
|
| 310 |
+
if not per_bin:
|
| 311 |
+
return {}
|
| 312 |
+
|
| 313 |
+
bins = []
|
| 314 |
+
for bd in per_bin.values():
|
| 315 |
+
pop = (bd['shots_z'] + bd['shots_x'] + bd['shots_y']) / 3.0
|
| 316 |
+
bins.append({
|
| 317 |
+
'k': bd['n_flips'],
|
| 318 |
+
'pop': pop,
|
| 319 |
+
'fid': bd['fidelity'],
|
| 320 |
+
})
|
| 321 |
+
|
| 322 |
+
total_pop = sum(b['pop'] for b in bins)
|
| 323 |
+
if total_pop == 0:
|
| 324 |
+
return {}
|
| 325 |
+
|
| 326 |
+
expected_flips = n_meas * p_meas
|
| 327 |
+
|
| 328 |
+
def weighted_fidelity(weight_fn):
|
| 329 |
+
num = sum(weight_fn(b['k']) * b['pop'] * b['fid'] for b in bins)
|
| 330 |
+
den = sum(weight_fn(b['k']) * b['pop'] for b in bins)
|
| 331 |
+
if den == 0:
|
| 332 |
+
return None
|
| 333 |
+
fid = num / den
|
| 334 |
+
util = den / total_pop
|
| 335 |
+
return {
|
| 336 |
+
'tomographic_fidelity': float(fid),
|
| 337 |
+
'utilization': float(util),
|
| 338 |
+
'effective_yield': float(fid * util),
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
schemes = {}
|
| 342 |
+
|
| 343 |
+
# 1. No weighting
|
| 344 |
+
r = weighted_fidelity(lambda k: 1.0)
|
| 345 |
+
if r:
|
| 346 |
+
schemes['unweighted'] = r
|
| 347 |
+
|
| 348 |
+
# 2. Hard post-selection (k=0)
|
| 349 |
+
r = weighted_fidelity(lambda k: 1.0 if k == 0 else 0.0)
|
| 350 |
+
if r:
|
| 351 |
+
schemes['hard_ps_k0'] = r
|
| 352 |
+
|
| 353 |
+
# 3. Soft k<=2
|
| 354 |
+
r = weighted_fidelity(lambda k: 1.0 if k <= 2 else 0.0)
|
| 355 |
+
if r:
|
| 356 |
+
schemes['soft_k2'] = r
|
| 357 |
+
|
| 358 |
+
# 4. exp(-k)
|
| 359 |
+
r = weighted_fidelity(lambda k: np.exp(-k))
|
| 360 |
+
if r:
|
| 361 |
+
schemes['exp_minus_k'] = r
|
| 362 |
+
|
| 363 |
+
# 5. Calibrated exp(-alpha*k)
|
| 364 |
+
alpha = np.log(2) / max(expected_flips, 1)
|
| 365 |
+
r = weighted_fidelity(lambda k: np.exp(-alpha * k))
|
| 366 |
+
if r:
|
| 367 |
+
schemes['calibrated_exp'] = r
|
| 368 |
+
schemes['calibrated_exp']['alpha'] = float(alpha)
|
| 369 |
+
|
| 370 |
+
# 6. Excess-flip: exp(-max(0, k - expected))
|
| 371 |
+
r = weighted_fidelity(lambda k: np.exp(-max(0, k - expected_flips)))
|
| 372 |
+
if r:
|
| 373 |
+
schemes['excess_flip'] = r
|
| 374 |
+
schemes['excess_flip']['expected_flips'] = float(expected_flips)
|
| 375 |
+
|
| 376 |
+
# 7. Likelihood ratio: Binom(k; N, p_meas) / Binom(k; N, 0.5)
|
| 377 |
+
def lr_weight(k):
|
| 378 |
+
if k > n_meas:
|
| 379 |
+
return 0.0
|
| 380 |
+
p_t = comb(n_meas, k, exact=True) * (p_meas ** k) * ((1 - p_meas) ** (n_meas - k))
|
| 381 |
+
p_r = comb(n_meas, k, exact=True) * (0.5 ** n_meas)
|
| 382 |
+
return min(p_t / p_r, 1e10) if p_r > 0 else 0.0
|
| 383 |
+
|
| 384 |
+
r = weighted_fidelity(lr_weight)
|
| 385 |
+
if r:
|
| 386 |
+
schemes['likelihood_ratio'] = r
|
| 387 |
+
|
| 388 |
+
return schemes
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
# =============================================================================
|
| 392 |
+
# MAIN
|
| 393 |
+
# =============================================================================
|
| 394 |
+
|
| 395 |
+
def main():
|
| 396 |
+
print("=" * 70)
|
| 397 |
+
print("ZENO STATE TOMOGRAPHY")
|
| 398 |
+
print("=" * 70)
|
| 399 |
+
|
| 400 |
+
service = QiskitRuntimeService(channel="ibm_cloud", instance="claude")
|
| 401 |
+
|
| 402 |
+
usage_before = check_usage(service)
|
| 403 |
+
log(f"Usage: {usage_before['total']}s / 600s ({usage_before['percentage']:.1f}%)")
|
| 404 |
+
log(f"Remaining: {usage_before['remaining']}s")
|
| 405 |
+
|
| 406 |
+
if usage_before['remaining'] < 30:
|
| 407 |
+
log("Insufficient quota (<30s). Aborting.")
|
| 408 |
+
return
|
| 409 |
+
|
| 410 |
+
backend = service.backend("ibm_torino")
|
| 411 |
+
log(f"Backend: {backend.name} ({backend.num_qubits}q)")
|
| 412 |
+
|
| 413 |
+
dt = backend.dt
|
| 414 |
+
hw_target = backend.target
|
| 415 |
+
meas_props = hw_target['measure'][(0,)]
|
| 416 |
+
meas_duration_s = meas_props.duration
|
| 417 |
+
meas_duration_dt = int(meas_duration_s / dt)
|
| 418 |
+
meas_error = meas_props.error
|
| 419 |
+
|
| 420 |
+
props = backend.qubit_properties(0)
|
| 421 |
+
T1 = props.t1
|
| 422 |
+
T2 = props.t2
|
| 423 |
+
|
| 424 |
+
log(f"Measurement: {meas_duration_s*1e6:.3f} us ({meas_duration_dt} dt), "
|
| 425 |
+
f"error={meas_error:.4f}")
|
| 426 |
+
log(f"Qubit 0: T1={T1*1e6:.1f} us, T2={T2*1e6:.1f} us")
|
| 427 |
+
|
| 428 |
+
theta = np.pi
|
| 429 |
+
n_values = [32, 128, 256, 512, 1024]
|
| 430 |
+
bases = ['Z', 'X', 'Y']
|
| 431 |
+
shots = 8192
|
| 432 |
+
|
| 433 |
+
# QPU budget estimate
|
| 434 |
+
estimated_qpu = 0
|
| 435 |
+
for n in n_values:
|
| 436 |
+
step_time = n * (meas_duration_s + 100e-9) # meas + ~2 Ry gates
|
| 437 |
+
estimated_qpu += 3 * shots * step_time # 3 Zeno basis circuits
|
| 438 |
+
estimated_qpu += 3 * shots * n * meas_duration_s # 3 delay circuits (rough)
|
| 439 |
+
log(f"Estimated QPU: {estimated_qpu:.0f}s")
|
| 440 |
+
|
| 441 |
+
if estimated_qpu > usage_before['remaining']:
|
| 442 |
+
log(f"WARNING: estimated QPU ({estimated_qpu:.0f}s) exceeds "
|
| 443 |
+
f"remaining quota ({usage_before['remaining']:.0f}s)")
|
| 444 |
+
log("Proceeding — estimate is conservative. Abort manually if needed.")
|
| 445 |
+
|
| 446 |
+
print(f"\n{'N':>5} | {'Time(us)':>8} | {'x T1':>6} | {'Est depth':>9}")
|
| 447 |
+
print("-" * 38)
|
| 448 |
+
for n in n_values:
|
| 449 |
+
t_us = n * meas_duration_s * 1e6
|
| 450 |
+
t1m = n * meas_duration_s / T1
|
| 451 |
+
print(f"{n:5d} | {t_us:8.1f} | {t1m:5.1f}x | {n * 5:9d}")
|
| 452 |
+
|
| 453 |
+
# Build circuits
|
| 454 |
+
all_experiments = []
|
| 455 |
+
|
| 456 |
+
for n in n_values:
|
| 457 |
+
total_time_us = n * meas_duration_s * 1e6
|
| 458 |
+
t1_mult = n * meas_duration_s / T1
|
| 459 |
+
|
| 460 |
+
for basis in bases:
|
| 461 |
+
all_experiments.append(ExperimentConfig(
|
| 462 |
+
name=f"zeno_N{n}_{basis}",
|
| 463 |
+
circuit=build_zeno_tomo(theta, n, basis),
|
| 464 |
+
category="zeno",
|
| 465 |
+
params={'n_meas': n, 'theta': float(theta), 'basis': basis,
|
| 466 |
+
'total_time_us': total_time_us, 'T1_multiple': t1_mult},
|
| 467 |
+
))
|
| 468 |
+
|
| 469 |
+
all_experiments.append(ExperimentConfig(
|
| 470 |
+
name=f"delay_N{n}_{basis}",
|
| 471 |
+
circuit=build_delay_tomo(theta, n, meas_duration_dt, basis),
|
| 472 |
+
category="delay",
|
| 473 |
+
params={'n_meas': n, 'theta': float(theta), 'basis': basis,
|
| 474 |
+
'total_time_us': total_time_us, 'T1_multiple': t1_mult},
|
| 475 |
+
))
|
| 476 |
+
|
| 477 |
+
log(f"Circuits: {len(all_experiments)} ({len(all_experiments)//2} Zeno "
|
| 478 |
+
f"+ {len(all_experiments)//2} delay)")
|
| 479 |
+
|
| 480 |
+
# Transpile
|
| 481 |
+
log("Transpiling...")
|
| 482 |
+
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
|
| 483 |
+
|
| 484 |
+
transpiled = []
|
| 485 |
+
valid_experiments = []
|
| 486 |
+
for exp in all_experiments:
|
| 487 |
+
try:
|
| 488 |
+
tc = pm.run(exp.circuit)
|
| 489 |
+
transpiled.append(tc)
|
| 490 |
+
valid_experiments.append(exp)
|
| 491 |
+
except Exception as e:
|
| 492 |
+
log(f"Transpile error ({exp.name}): {e}")
|
| 493 |
+
|
| 494 |
+
log(f"Transpiled: {len(transpiled)}/{len(all_experiments)}")
|
| 495 |
+
|
| 496 |
+
if not transpiled:
|
| 497 |
+
log("No circuits transpiled. Aborting.")
|
| 498 |
+
return
|
| 499 |
+
|
| 500 |
+
depths = [tc.depth() for tc in transpiled]
|
| 501 |
+
log(f"Depths: min={min(depths)}, max={max(depths)}")
|
| 502 |
+
|
| 503 |
+
for i, exp in enumerate(valid_experiments):
|
| 504 |
+
exp.params['transpiled_depth'] = depths[i]
|
| 505 |
+
|
| 506 |
+
# Submit
|
| 507 |
+
log("Submitting batch...")
|
| 508 |
+
start_time = datetime.now(timezone.utc)
|
| 509 |
+
|
| 510 |
+
with Batch(backend=backend) as batch:
|
| 511 |
+
sampler = SamplerV2(mode=batch)
|
| 512 |
+
job = sampler.run(transpiled, shots=shots)
|
| 513 |
+
log(f"Job ID: {job.job_id()}")
|
| 514 |
+
log("Waiting...")
|
| 515 |
+
job.wait_for_final_state()
|
| 516 |
+
|
| 517 |
+
end_time = datetime.now(timezone.utc)
|
| 518 |
+
wall_time = (end_time - start_time).total_seconds()
|
| 519 |
+
log(f"Complete. Wall: {wall_time:.1f}s, QPU: {job.usage() or 0}s")
|
| 520 |
+
|
| 521 |
+
# Parse bitstrings
|
| 522 |
+
result = job.result()
|
| 523 |
+
metrics = job.metrics()
|
| 524 |
+
|
| 525 |
+
bitstring_map = {}
|
| 526 |
+
for i, exp in enumerate(valid_experiments):
|
| 527 |
+
pub_result = result[i]
|
| 528 |
+
data_bin = pub_result.data
|
| 529 |
+
|
| 530 |
+
if hasattr(data_bin, 'c'):
|
| 531 |
+
bitstrings = list(data_bin.c.get_bitstrings())
|
| 532 |
+
elif hasattr(data_bin, 'meas'):
|
| 533 |
+
bitstrings = list(data_bin.meas.get_bitstrings())
|
| 534 |
+
else:
|
| 535 |
+
cr_name = list(data_bin.keys())[0]
|
| 536 |
+
bitstrings = list(getattr(data_bin, cr_name).get_bitstrings())
|
| 537 |
+
|
| 538 |
+
bitstring_map[exp.name] = bitstrings
|
| 539 |
+
|
| 540 |
+
# Tomographic reconstruction
|
| 541 |
+
results_data = {}
|
| 542 |
+
|
| 543 |
+
for n in n_values:
|
| 544 |
+
zeno_z = bitstring_map.get(f"zeno_N{n}_Z", [])
|
| 545 |
+
zeno_x = bitstring_map.get(f"zeno_N{n}_X", [])
|
| 546 |
+
zeno_y = bitstring_map.get(f"zeno_N{n}_Y", [])
|
| 547 |
+
|
| 548 |
+
if zeno_z and zeno_x and zeno_y:
|
| 549 |
+
results_data[f"zeno_N{n}"] = analyze_zeno_tomo(
|
| 550 |
+
zeno_z, zeno_x, zeno_y, n, meas_error)
|
| 551 |
+
|
| 552 |
+
delay_z = bitstring_map.get(f"delay_N{n}_Z", [])
|
| 553 |
+
delay_x = bitstring_map.get(f"delay_N{n}_X", [])
|
| 554 |
+
delay_y = bitstring_map.get(f"delay_N{n}_Y", [])
|
| 555 |
+
|
| 556 |
+
if delay_z and delay_x and delay_y:
|
| 557 |
+
results_data[f"delay_N{n}"] = {
|
| 558 |
+
'raw': analyze_delay_tomo(delay_z, delay_x, delay_y)
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
# Save
|
| 562 |
+
output = {
|
| 563 |
+
'experiment': 'zeno_state_tomography',
|
| 564 |
+
'description': (
|
| 565 |
+
'Full single-qubit state tomography of Zeno-dragged states at '
|
| 566 |
+
'N = 32 through 1024 intermediate measurements. Density matrices '
|
| 567 |
+
'reconstructed from X, Y, Z basis measurements without post-selection '
|
| 568 |
+
'or trajectory weighting. Per-flip-count bin tomography provides '
|
| 569 |
+
'ground-truth fidelity for calibrating weighting schemes. '
|
| 570 |
+
'Delay-matched controls at every N value.'
|
| 571 |
+
),
|
| 572 |
+
'protocol': {
|
| 573 |
+
'zeno': 'Drag |0> to |1> via N projective measurements, '
|
| 574 |
+
'then measure in Pauli basis. No undo rotation.',
|
| 575 |
+
'delay': 'Ry(pi)|0> + idle delay matching Zeno wall-clock, '
|
| 576 |
+
'then measure in Pauli basis.',
|
| 577 |
+
'target_state': '|1>',
|
| 578 |
+
'bases': ['X', 'Y', 'Z'],
|
| 579 |
+
'shots_per_circuit': shots,
|
| 580 |
+
},
|
| 581 |
+
'timestamp': start_time.isoformat(),
|
| 582 |
+
'backend': backend.name,
|
| 583 |
+
'n_values': n_values,
|
| 584 |
+
'total_circuits': len(valid_experiments),
|
| 585 |
+
'job_id': job.job_id(),
|
| 586 |
+
'usage_seconds': job.usage() or 0,
|
| 587 |
+
'wall_time_seconds': wall_time,
|
| 588 |
+
'metrics': metrics,
|
| 589 |
+
'hardware': {
|
| 590 |
+
'qubit': 0,
|
| 591 |
+
'dt_ns': dt * 1e9,
|
| 592 |
+
'measurement_duration_us': meas_duration_s * 1e6,
|
| 593 |
+
'measurement_duration_dt': meas_duration_dt,
|
| 594 |
+
'measurement_error': meas_error,
|
| 595 |
+
'T1_us': T1 * 1e6,
|
| 596 |
+
'T2_us': T2 * 1e6,
|
| 597 |
+
},
|
| 598 |
+
'results': results_data,
|
| 599 |
+
'raw_bitstrings': {name: bs for name, bs in bitstring_map.items()},
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
RESULTS_DIR.mkdir(parents=True, exist_ok=True)
|
| 603 |
+
outfile = RESULTS_DIR / 'zeno_tomography.json'
|
| 604 |
+
with open(outfile, 'w') as f:
|
| 605 |
+
json.dump(output, f, indent=2, default=str)
|
| 606 |
+
log(f"Saved: {outfile}")
|
| 607 |
+
|
| 608 |
+
# =========================================================================
|
| 609 |
+
# RESULTS
|
| 610 |
+
# =========================================================================
|
| 611 |
+
print("\n" + "=" * 70)
|
| 612 |
+
print("RAW TOMOGRAPHIC FIDELITY WITH |1> (NO SELECTION)")
|
| 613 |
+
print("=" * 70)
|
| 614 |
+
|
| 615 |
+
print(f"\n{'N':>5} | {'x T1':>5} | {'Zeno F':>7} | {'Zeno P':>7} | "
|
| 616 |
+
f"{'Delay F':>7} | {'Delay P':>7} | {'Z - D':>7}")
|
| 617 |
+
print("-" * 56)
|
| 618 |
+
|
| 619 |
+
for n in n_values:
|
| 620 |
+
zk = f"zeno_N{n}"
|
| 621 |
+
dk = f"delay_N{n}"
|
| 622 |
+
if zk not in results_data or dk not in results_data:
|
| 623 |
+
continue
|
| 624 |
+
|
| 625 |
+
zr = results_data[zk]['raw']
|
| 626 |
+
dr = results_data[dk]['raw']
|
| 627 |
+
t1m = n * meas_duration_s / T1
|
| 628 |
+
gap = zr['fidelity'] - dr['fidelity']
|
| 629 |
+
|
| 630 |
+
print(f"{n:5d} | {t1m:4.1f}x | {zr['fidelity']:7.4f} | "
|
| 631 |
+
f"{zr['purity']:7.4f} | {dr['fidelity']:7.4f} | "
|
| 632 |
+
f"{dr['purity']:7.4f} | {gap:+7.4f}")
|
| 633 |
+
|
| 634 |
+
# Bloch vector summary
|
| 635 |
+
print(f"\n{'N':>5} | {'Cat':>5} | {'<X>':>7} | {'<Y>':>7} | {'<Z>':>7} | "
|
| 636 |
+
f"{'|r|':>6}")
|
| 637 |
+
print("-" * 48)
|
| 638 |
+
for n in n_values:
|
| 639 |
+
for cat in ['zeno', 'delay']:
|
| 640 |
+
key = f"{cat}_N{n}"
|
| 641 |
+
if key not in results_data:
|
| 642 |
+
continue
|
| 643 |
+
r = results_data[key]['raw']
|
| 644 |
+
bloch_len = np.sqrt(r['exp_x']**2 + r['exp_y']**2 + r['exp_z']**2)
|
| 645 |
+
print(f"{n:5d} | {cat:>5} | {r['exp_x']:+7.4f} | "
|
| 646 |
+
f"{r['exp_y']:+7.4f} | {r['exp_z']:+7.4f} | {bloch_len:6.4f}")
|
| 647 |
+
|
| 648 |
+
# Per-bin tables for selected N
|
| 649 |
+
for n in [32, 256, 1024]:
|
| 650 |
+
zk = f"zeno_N{n}"
|
| 651 |
+
if zk not in results_data:
|
| 652 |
+
continue
|
| 653 |
+
|
| 654 |
+
zeno = results_data[zk]
|
| 655 |
+
if not zeno['per_bin']:
|
| 656 |
+
continue
|
| 657 |
+
|
| 658 |
+
print(f"\n{'=' * 70}")
|
| 659 |
+
print(f"PER-BIN TOMOGRAPHY: N={n}")
|
| 660 |
+
print(f"{'=' * 70}")
|
| 661 |
+
|
| 662 |
+
print(f"\n{'k':>5} | {'shots':>6} | {'<X>':>7} | {'<Y>':>7} | "
|
| 663 |
+
f"{'<Z>':>7} | {'F(|1>)':>7} | {'Purity':>7}")
|
| 664 |
+
print("-" * 58)
|
| 665 |
+
|
| 666 |
+
for nf_str in sorted(zeno['per_bin'].keys(), key=lambda x: int(x)):
|
| 667 |
+
bd = zeno['per_bin'][nf_str]
|
| 668 |
+
print(f"{bd['n_flips']:5d} | {bd['shots_z']:6d} | "
|
| 669 |
+
f"{bd['exp_x']:+7.4f} | {bd['exp_y']:+7.4f} | "
|
| 670 |
+
f"{bd['exp_z']:+7.4f} | {bd['fidelity']:7.4f} | "
|
| 671 |
+
f"{bd['purity']:7.4f}")
|
| 672 |
+
|
| 673 |
+
# Weighting scheme ground truth
|
| 674 |
+
print(f"\n{'=' * 70}")
|
| 675 |
+
print("WEIGHTING SCHEME GROUND-TRUTH CALIBRATION")
|
| 676 |
+
print("=" * 70)
|
| 677 |
+
|
| 678 |
+
scheme_names = [
|
| 679 |
+
'unweighted', 'hard_ps_k0', 'soft_k2', 'exp_minus_k',
|
| 680 |
+
'calibrated_exp', 'excess_flip', 'likelihood_ratio',
|
| 681 |
+
]
|
| 682 |
+
|
| 683 |
+
print(f"\n{'N':>5} | {'Scheme':>16} | {'Tomo F':>7} | "
|
| 684 |
+
f"{'Util':>7} | {'Yield':>7}")
|
| 685 |
+
print("-" * 52)
|
| 686 |
+
|
| 687 |
+
for n in n_values:
|
| 688 |
+
zk = f"zeno_N{n}"
|
| 689 |
+
if zk not in results_data:
|
| 690 |
+
continue
|
| 691 |
+
wp = results_data[zk].get('weighting_predictions', {})
|
| 692 |
+
for sn in scheme_names:
|
| 693 |
+
if sn in wp:
|
| 694 |
+
s = wp[sn]
|
| 695 |
+
print(f"{n:5d} | {sn:>16} | {s['tomographic_fidelity']:7.4f} | "
|
| 696 |
+
f"{s['utilization']:7.4f} | {s['effective_yield']:7.4f}")
|
| 697 |
+
print()
|
| 698 |
+
|
| 699 |
+
usage_after = check_usage(service)
|
| 700 |
+
log(f"Usage: {usage_after['total']}s / 600s ({usage_after['percentage']:.1f}%)")
|
| 701 |
+
log(f"This job: {job.usage() or 0}s")
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
if __name__ == '__main__':
|
| 705 |
+
try:
|
| 706 |
+
main()
|
| 707 |
+
except KeyboardInterrupt:
|
| 708 |
+
log("Interrupted.")
|
| 709 |
+
sys.exit(1)
|
| 710 |
+
except Exception as e:
|
| 711 |
+
log(f"FATAL: {e}")
|
| 712 |
+
import traceback
|
| 713 |
+
traceback.print_exc()
|
| 714 |
+
sys.exit(1)
|