We translate the teleportation protocol into executable Python code. Alice wants to send a qubit state to Bob. Direct copying of the state is not possible due to the no-cloning theorem; instead, an entangled pair of qubits is consumed to transfer the information.
To simulate this, we need a system with three qubits and two classical bits.
We begin by setting up the quantum register and the classical register. In a Python environment using a standard SDK like Qiskit, we define these registers to hold our data. We also need to prepare in a distinct state. If we leave in the default ground state , verifying teleportation is difficult because the target is already initialized to .
To make the test valid, we apply a rotation to . For this example, we apply a Rotation-X gate to change the state to something specific, such as a localized probability amplitude.
import numpy as np
from qiskit import QuantumCircuit, Aer, execute
# Define the circuit with 3 qubits and 2 classical bits
circuit = QuantumCircuit(3, 2)
# Step 0: Prepare the payload state |psi> on q0
# We apply a rotation so the state is not just |0> or |1>
# This makes it easier to verify the transfer later
circuit.rx(np.pi/3, 0)
circuit.barrier()
Teleportation requires a shared resource. Alice and Bob must share a Bell pair before the protocol begins. We generate this pair between (Alice) and (Bob). As learned in the previous chapter, we achieve this using a Hadamard gate followed by a CNOT gate.
# Step 1: Create a Bell Pair between q1 and q2
circuit.h(1)
circuit.cx(1, 2)
circuit.barrier()
At this stage, and are maximally entangled. Alice holds (the message) and (her resource). Bob holds .
Alice needs to entangle her message qubit () with her resource qubit (). She performs a CNOT gate using the message as the control and the resource as the target. Immediately after, she applies a Hadamard gate to the message qubit.
These operations change the basis of the qubits, preparing them for measurement. This effectively "spreads" the information of across the three-qubit system.
# Step 2: Alice applies CNOT and Hadamard
circuit.cx(0, 1)
circuit.h(0)
circuit.barrier()
Alice now measures her two qubits. The results are stored in classical bits. This action destroys the quantum state on Alice's side. However, due to the entanglement established earlier, the state of Bob's qubit () instantly collapses into one of four possible variations of the original message .
# Step 3: Alice measures her qubits
circuit.measure([0, 1], [0, 1])
circuit.barrier()
The diagram below illustrates the flow of information through these gates. Note how the quantum information interacts locally at Alice's end before becoming classical data.
The standard data flow in a teleportation circuit. The dashed line represents the initial quantum correlation, while the solid arrow represents the transmission of classical bits.
Bob's qubit () now holds the message, but it might be flipped or phase-shifted depending on Alice's random measurement outcomes. Bob must apply "correction" gates based on the classical bits he receives.
In programming terms, we use conditional logic. The simulator checks the classical register value and applies the gate dynamically.
# Step 4: Bob applies correction gates based on classical bits
# If classical bit 0 is 1, apply Z
circuit.z(2).c_if(circuit.clbits[0], 1)
# If classical bit 1 is 1, apply X
circuit.x(2).c_if(circuit.clbits[1], 1)
The order of operations is mathematically specific. If both bits are 1, we apply then (or then , though standard convention usually implies ). The logic ensures that whatever random transformation occurred during measurement is perfectly undone.
To prove teleportation was successful, we compare the state of Bob's qubit () at the end of the circuit with the initial state of Alice's qubit (). Since we cannot "see" a quantum state without destroying it, simulation offers a unique advantage. We can use a statevector simulator to inspect the mathematical probability amplitudes directly.
The following chart displays the probability distribution of the original payload versus the final teleported state. In a perfect simulation, they overlap completely.
Comparison of probability amplitudes. The blue bars represent the initialization of Alice's qubit, and the green bars represent Bob's qubit after the protocol.
If you run this experiment on a real quantum computer, you will not get the perfect distribution shown above in a single shot. You would need to run the circuit thousands of times (shots) and build a histogram of the results. This is due to quantum noise and gate errors.
However, in our ideal Python simulation, you will observe that the mathematical vector describing is identical to the vector we initialized on .
This confirms that the state has been transferred. Note that and collapsed into or during measurement. The information did not duplicate; it moved. This satisfies the no-cloning theorem while achieving information transport.
When implementing this in production environments, keep these limitations in mind:
By mastering this circuit, you understand the primary mechanism for moving data in a quantum network. In the next section, we will look at "Superdense Coding," which uses the same resource to achieve the opposite effect: sending two classical bits using one qubit.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with