YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Classical Shadows on a 6-qubit GHZ state (Qiskit demo)
Reproducible Qiskit 2.x implementation of the random-Pauli classical-shadow protocol of Huang, Kueng & Preskill, Nat. Phys. 2020 (arXiv:2002.08953): "Predicting many properties of a quantum system from very few measurements."
We prepare a 6-qubit GHZ state and predict 15 different observables (single-qubit Z/X, ZZ correlators, X-stabilizer, Y0Y1, multi-qubit X/Z/Y strings, mixed strings) from a single shadow run of N random Pauli measurements. We then compare to the exact statevector values and verify the theoretical convergence ~ 3^k / √N for k-local Paulis.
Result
At N = 80 000 shots, every shadow estimate matches the ideal value within ~1–2 standard errors, with the empirical standard error tracking theory (locality-3 prediction error ~ 27/√N).
obs ideal shadow err stderr
Z0 +0.0000 -0.0059 -0.0059 0.0061
X0 +0.0000 -0.0108 -0.0108 0.0061
Z0Z1 +1.0000 +1.0028 +0.0028 0.0100
Z1Z2 +1.0000 +1.0158 +0.0158 0.0101
Z0Z5 +1.0000 +0.9990 -0.0010 0.0100
X^all (XXXXXX) +1.0000 +0.9295 -0.0705 0.0920
Y0Y1 +0.0000 +0.0127 +0.0127 0.0106
X0Y1Z2 +0.0000 +0.0014 +0.0014 0.0182
ZZZZZZ (global) +1.0000 +1.2758 +0.2758 0.1077
The 6-local Z⊗Z⊗Z⊗Z⊗Z⊗Z and X⊗X⊗X⊗X⊗X⊗X estimators are noisier (~0.1 stderr) because only 1/729 of shots match all 6 measurement bases, but the result is still consistent with the ideal value within ~3σ — which is a striking demonstration of the protocol's central claim.
What I learned (sanity-checking)
The first run gave a clear bias on single-qubit Paulis (~0.14 instead of 0,
~22σ off). Cause: I had set AerSimulator(seed_simulator=SEED) at
construction, so every .run() invocation reused the same seed and the
~110 shots per measurement pattern were deterministic from that seed —
introducing a systematic bias when aggregated. Fix: pass a fresh
seed_simulator=... per .run() call. After that the protocol behaves
exactly as the theorem predicts.
Files
classical_shadows_ghz.py— main scriptartifacts/results.json,results.csv,run.logartifacts/convergence.png— |error| vs N (log–log) for various observablesartifacts/bar.png— ideal vs shadow estimate for all 15 observables
Run
pip install "qiskit~=2.4" qiskit-aer matplotlib
python classical_shadows_ghz.py
Tested with qiskit==2.4.1, qiskit-aer==0.17.2.