How to Prove Two Qubits Are Entangled: A CHSH Bell Test in Qiskit
A few weeks ago I found out that the circuit behind my own art collection was not doing what I thought it was doing. Every piece in Quantum Genesis was seeded by a circuit with Hadamards and CNOTs, and I had described it as "entangling". It wasn't — with a Hadamard on every qubit, the CNOTs had nothing to entangle. (I wrote up the correction in the entanglement post.)
That raised a better question than "is my circuit entangled?": how do you prove that any circuit is? Looking at counts like {'00': 2010, '11': 2038} is not enough — two coins glued together give the same pattern. The tool physicists use is the CHSH Bell test, and it fits in a few lines of Qiskit. This post walks through it, and runs it on two circuits: a real Bell pair, and the "collection style" circuit that fooled me.
Why counts in one basis prove nothing
Measure a Bell pair in the computational (Z) basis and you get 00 or 11, never 01 or 10. Impressive — until you notice that a classical machine can do exactly the same: flip one coin, write the result twice. Perfect correlation in a single basis is cheap.
What a classical system cannot do is stay that correlated when the two sides measure along different, independently chosen directions. That is the content of Bell's theorem, and CHSH (Clauser, Horne, Shimony and Holt, 1969) turns it into a single number you can compute.
The CHSH number in one paragraph
Alice measures one of two observables, A0 or A1; Bob measures B0 or B1. Each outcome is ±1. From the correlations you build:
S = <A0 B0> + <A0 B1> + <A1 B0> - <A1 B1>
Any theory where outcomes are decided in advance by shared (classical) information obeys |S| ≤ 2. Quantum mechanics allows up to 2√2 ≈ 2.83 (Tsirelson's bound). So the rule of thumb is simple: S above 2 means correlations no classical source can produce.
Choosing the measurements
The standard choice that reaches 2√2 for the Bell state (|00⟩ + |11⟩)/√2 is:
- Alice: A0 = Z, A1 = X
- Bob: B0 = (Z + X)/√2, B1 = (Z − X)/√2 — the same axes rotated by 45°
Plug those into S and most terms cancel. What is left is neat enough to hand straight to the Estimator primitive:
S = √2 · ( <Z⊗Z> + <X⊗X> )
For an ideal Bell pair both expectation values are 1, so S = 2√2.
The code
I ran everything locally with Qiskit Runtime's local mode, using FakeFez — a simulator that carries a snapshot of the real ibm_fez noise (gate errors, readout errors, decoherence). Same code works on the real device by swapping the backend.
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime.fake_provider import FakeFez
backend = FakeFez() # real-device noise model, runs on your laptop
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
def pair(h_on_both):
qc = QuantumCircuit(2)
qc.h(0)
if h_on_both:
qc.h(1) # the "collection style" mistake
qc.cx(0, 1)
return qc
chsh = SparsePauliOp(["ZZ", "XX"], coeffs=[np.sqrt(2), np.sqrt(2)])
estimator = Estimator(mode=backend)
estimator.options.default_shots = 20000
for name, h2 in [("Bell pair", False), ("H on both", True)]:
isa = pm.run(pair(h2))
obs = chsh.apply_layout(isa.layout)
res = estimator.run([(isa, obs)]).result()[0]
print(f"{name}: S = {float(res.data.evs):.3f} ± {float(res.data.stds):.3f}")
The results
| Circuit | S (noisy ibm_fez model) | Ideal value | Verdict |
|---|---|---|---|
| Bell pair (H on control only) | 2.661 ± 0.007 | 2.828 | Violates the classical bound → entangled |
| H on both qubits + CNOT | 1.362 ± 0.013 | 1.414 | Below 2 → no entanglement detected |
(Run it yourself and the last digit will move a little — shot noise. A second run gave 2.655 and 1.371.)
The Bell pair lands at 2.66: about 94% of the quantum maximum, with the gap coming from gate and readout noise in the model. That is still far above 2 — dozens of standard deviations — so the conclusion is solid even on noisy hardware.
The second circuit is the interesting one. With a Hadamard on both qubits, the state before the CNOT is |+⟩|+⟩, and a CNOT leaves |+⟩|+⟩ unchanged. The result is a product state: ⟨X⊗X⟩ = 1 but ⟨Z⊗Z⟩ = 0, so S = √2 ≈ 1.41. Below 2, exactly where the test says "nothing a classical source couldn't do".
What this test is (and isn't)
- It is a practical way to check that a circuit really produces entanglement, using only expectation values you can get from any Estimator.
- It is not a loophole-free Bell experiment. On a single chip the two qubits sit microns apart and the measurement settings aren't chosen at spacelike separation. The real experiments that closed those loopholes (2015 onward, recognised by the 2022 Nobel Prize in Physics) needed separated labs and fast random switches.
- It also says nothing about randomness quality. My "H on both" circuit fails the Bell test, yet it is still a perfectly good quantum random number source: each bit is a genuine 50/50 measurement outcome. Entanglement and randomness are different properties — a lesson I learned the hard way.
Try it yourself
- Swap
FakeFez()for a real backend fromQiskitRuntimeServiceand compare the S values. Expect slightly lower numbers on busy days. - Set
estimator.options.resilience_level = 1on real hardware to turn on readout-error mitigation, and see how much of the gap to 2.83 it closes. - Try a GHZ state on three qubits and look up the Mermin inequality — the three-qubit cousin of CHSH.
References
- J. F. Clauser, M. A. Horne, A. Shimony, R. A. Holt, "Proposed Experiment to Test Local Hidden-Variable Theories," Phys. Rev. Lett. 23, 880 (1969).
- B. S. Cirel'son (Tsirelson), "Quantum generalizations of Bell's inequality," Lett. Math. Phys. 4, 93 (1980).
- The Nobel Prize in Physics 2022 — Aspect, Clauser and Zeilinger, "for experiments with entangled photons, establishing the violation of Bell inequalities".
- Qiskit documentation: EstimatorV2, local testing mode and fake backends.
Comments
Post a Comment