Quantum Teleportation in Qiskit, Step by Step (and What It Does Not Do)
"Teleportation" is the most misleading word in quantum computing. Nothing travels faster than light, no matter is moved, and you cannot use it to send a message for free. What the protocol actually does is narrower and, once you see the circuit, more interesting: it moves an unknown quantum state from one qubit to another, using one shared entangled pair and two classical bits.
This post builds the protocol gate by gate in Qiskit, checks it exactly with a statevector, and then runs it on a noisy model of IBM's ibm_fez to see how well it survives real-world errors.
The setup in one paragraph
Alice holds a qubit in some state |ψ⟩ = α|0⟩ + β|1⟩ that she does not know (and cannot learn by measuring — measurement would destroy it). Alice and Bob also share a Bell pair, prepared in advance. Alice performs a joint measurement on her two qubits, sends the two classical result bits to Bob, and Bob applies one of four corrections. Afterwards Bob's qubit is in exactly |ψ⟩, and Alice's copy is gone. That last part is not optional: the no-cloning theorem forbids ending up with two copies.
Step 1 — Prepare a state to send
To make the test meaningful, the state should not be |0⟩ or |1⟩. I use Ry(1.1) followed by Rz(0.7), which gives a state with unequal amplitudes and a non-trivial phase. Because I know how I prepared it, I can later undo that preparation on Bob's side: if teleportation worked, Bob's qubit returns to |0⟩.
Step 2 — Share a Bell pair
Qubits 1 (Alice) and 2 (Bob) are entangled with a Hadamard and a CNOT — the same two gates as in the entanglement post, with the Hadamard on the control only.
Step 3 — Alice's Bell measurement
A CNOT from qubit 0 to qubit 1, then a Hadamard on qubit 0, rotates Alice's two qubits into the Bell basis. Measuring them now gives two bits, each 0 or 1 with equal probability — they carry no information about α or β on their own.
Step 4 — Bob's correction
Depending on the two bits, Bob applies nothing, X, Z, or both. On hardware that supports dynamic circuits this is done with mid-circuit measurement and classical feed-forward. On backends that do not, the standard trick is the deferred measurement principle: replace "measure, then apply X if 1" with a controlled-X, and the result is mathematically identical.
The code (deferred-measurement version)
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector, partial_trace, state_fidelity
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit_ibm_runtime.fake_provider import FakeFez
theta, phi = 1.1, 0.7 # the state to send: Ry(theta) then Rz(phi) on |0>
def teleport(check=True):
qc = QuantumCircuit(3, 1)
qc.ry(theta, 0); qc.rz(phi, 0) # Alice's unknown state on q0
qc.h(1); qc.cx(1, 2) # Bell pair: q1 (Alice), q2 (Bob)
qc.cx(0, 1); qc.h(0) # rotate Alice's qubits into the Bell basis
qc.cx(1, 2); qc.cz(0, 2) # Bob's corrections, as controlled gates
if check:
qc.rz(-phi, 2); qc.ry(-theta, 2) # undo the preparation on Bob's qubit
qc.measure(2, 0) # ideal result: always 0
return qc
# Exact check: Bob's qubit vs the original state
sv = Statevector(teleport(check=False))
bob = partial_trace(sv, [0, 1])
ref = QuantumCircuit(1); ref.ry(theta, 0); ref.rz(phi, 0)
print("fidelity:", state_fidelity(bob, Statevector(ref)))
# Noisy run on a model of ibm_fez
backend = FakeFez()
pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
counts = Sampler(mode=backend).run([pm.run(teleport())], shots=20000).result()[0].data.c.get_counts()
print("P(0):", counts.get("0", 0) / 20000)
Results
| Check | Result |
|---|---|
| Statevector fidelity, Bob vs original | 1.000000 |
| Noisy ibm_fez model, P(Bob returns to |0⟩) | 98.4% (19,684 of 20,000 shots) |
| Dynamic-circuit version on Aer (no noise) | 100%, with all four Alice outcomes appearing |
The statevector confirms the algebra exactly. On the noisy model, 1.6% of runs end with Bob in the wrong state — the combined cost of a handful of two-qubit gates and one readout on current hardware. That number is a good sanity check for any device: if your own run lands far below it, the problem is usually qubit layout or a bad calibration day, not the protocol.
The dynamic-circuit version
If your backend supports mid-circuit measurement, this is the version that matches the textbook — Alice really measures, and Bob's gates really depend on classical bits:
qc = QuantumCircuit(3, 3)
qc.ry(theta, 0); qc.rz(phi, 0)
qc.h(1); qc.cx(1, 2)
qc.cx(0, 1); qc.h(0)
qc.measure(0, 0); qc.measure(1, 1)
with qc.if_test((qc.clbits[1], 1)):
qc.x(2)
with qc.if_test((qc.clbits[0], 1)):
qc.z(2)
qc.rz(-phi, 2); qc.ry(-theta, 2)
qc.measure(2, 2)
Run on Aer, Alice's two bits come out as 00, 01, 10 and 11 in roughly equal proportions, yet Bob's check qubit reads 0 every time. That is the whole point: the classical bits look like pure noise, and only together with Bob's half of the Bell pair do they reconstruct the state.
What teleportation does not do
- It does not beat the speed of light. Bob cannot recover |ψ⟩ until the two classical bits arrive, and those travel at ordinary speeds.
- It does not copy. Alice's qubit ends in a measured, classical state. Exactly one copy of |ψ⟩ exists at any time.
- It does not move matter. Only the state moves; the physical qubits stay where they are.
- It consumes entanglement. Each teleported qubit uses up one Bell pair, which is why entanglement distribution is the bottleneck of quantum networks.
Why it matters beyond the demo
Teleportation is not a party trick. It is how quantum networks plan to move states between nodes, how some error-correction schemes apply gates ("gate teleportation"), and how modular quantum processors are expected to connect chips. Understanding these few lines of Qiskit is the entry point to all of it.
References
- C. H. Bennett et al., "Teleporting an unknown quantum state via dual classical and Einstein–Podolsky–Rosen channels," Phys. Rev. Lett. 70, 1895 (1993).
- D. Bouwmeester et al., "Experimental quantum teleportation," Nature 390, 575 (1997).
- Qiskit documentation: classical feed-forward and control flow (dynamic circuits).
Comments
Post a Comment