Hello! Welcome back.
In our last lesson, we broke down the theory behind the quantum teleportation protocol. We explored the roles of Alice and Bob, the sequence of gates, and the crucial part played by shared entanglement and classical communication.
Today, we'll move from theory to practice. Our goal is to implement and verify the complete quantum teleportation circuit using Qiskit. This will involve translating each step of the protocol—creating the entangled pair, performing Alice's operations, and applying Bob's conditional corrections—into a working Python program. By the end of this lesson, you'll have built a circuit that successfully teleports a quantum state in a simulation.
The Quantum Teleportation Circuit: A Quick Review
Let's start with a visual reminder of the circuit we're about to build. This diagram shows the three qubits and the sequence of operations we discussed in the previous lesson.

Our task is to construct this circuit in Qiskit.
Building the Circuit, Step-by-Step
We'll build the teleportation protocol in stages, just as we described it theoretically. A great resource for this is the Qiskit documentation itself, which provides clean, commented code. We'll use it as our guide.
This guide from the IBM Quantum Learning platform provides the complete Qiskit code for the teleportation protocol.
Read through the text and the first large code block, which defines the protocol circuit. Don't worry about running the code just yet. Focus on how each section of the code maps to a part of the protocol: Initialization: Notice the use of QuantumRegister for the qubits and ClassicalRegister for the measurement bits. Entanglement: See how the Hadamard and CNOT gates create the Bell pair. Alice's Operations: Identify the CNOT and Hadamard gates she applies to her qubits. Measurement: Find the measure commands. Bob's Conditional Gates: Pay close attention to the with protocol.if_test(...) blocks. This is how Qiskit implements classically controlled operations.
The resource you just read introduced two useful Qiskit features:
barrier(): This is a visual element in the circuit diagram that also acts as a directive to the compiler, preventing it from merging gates across the barrier. It helps keep our logical steps separate and readable.if_test(): This is the modern Qiskit syntax for making a quantum gate conditional on the value of a classical bit. In our case, Bob applies an X gate only if Alice's first classical bit is 1, and a Z gate only if her second classical bit is 1. This directly implements the correction table from our last lesson.
Now, let's watch a video that walks through this exact coding process. Seeing it built in real-time can help solidify your understanding.
Quantum Teleportation Demystified with a Quantum Computer | Paradoxes Ep. 08
In this video from the Qiskit YouTube channel, the presenter codes the teleportation circuit live.
Watch the segment on building the circuit. Notice how the code structure mirrors the theoretical steps: initializing qubits, creating entanglement, performing Alice's joint measurement, and applying Bob's conditional gates.
Verifying the Teleportation
We've built the circuit, but how do we confirm it works? We can't simply measure Bob's final qubit, because that would just give us a 0 or 1, destroying the teleported state.
The standard verification method is a clever "round trip" test:
- Prepare an initial state: Instead of starting with an unknown state , we'll create a specific, known state by applying a gate to a qubit that starts as . To make the test general, we'll use a random unitary gate, . The state to be teleported is now .
- Run the protocol: Execute the teleportation circuit to send to Bob's qubit.
- Apply the inverse gate: If the protocol worked, Bob's qubit is now in the state . To check this, he can apply the inverse gate, . Since quantum gates are unitary, their inverse is simply their conjugate transpose, denoted . Applying it should return his qubit to the initial state: .
- Measure: Finally, Bob measures his qubit. If the teleportation was successful, he should measure
0with 100% certainty.
This process provides a powerful way to confirm that the state was transmitted with high fidelity. The fact that every gate has a corresponding inverse is a direct consequence of the unitarity of quantum evolution, a concept you've noted as important.
Let's see how this verification is implemented in Qiskit.
Testing the Teleportation Protocol
This second part of the IBM Quantum Learning guide explains and implements the verification strategy.
Read the text and code blocks in this section. Focus on these key steps: UGate: A random unitary gate is created to prepare the initial state. test.compose(protocol): The compose method is a neat way to insert our entire protocol circuit into a larger test circuit. random_gate.inverse(): The inverse of the initial gate is applied to Bob's qubit at the end. Simulation & Results: The circuit is run on a simulator, and a histogram of the results is plotted. Notice that the result for Bob's qubit (the leftmost bit in the histogram 000) is always 0.
To see this verification in action, let's return to the Qiskit video.
Quantum Teleportation Demystified with a Quantum Computer | Paradoxes Ep. 08
This short clip shows the verification process and the final measurement results.
Watch the section on verifying the result. The presenter explains the inverse gate strategy and shows the histogram, confirming that Bob's qubit is always measured as 0, indicating a successful teleportation.
By combining these steps, you now have a complete Qiskit program to both implement and verify the quantum teleportation protocol.
Conclusion
In this lesson, we bridged the gap between theory and practice. You've seen how to translate the abstract steps of the quantum teleportation protocol into concrete Qiskit code.
Key Takeaways:
- Quantum and classical registers (
QuantumRegister,ClassicalRegister) are used to define the resources for the circuit. - The teleportation circuit is built by adding gates (
h,cx,measure) in the same sequence as the theoretical protocol. - The
barrier()function improves readability and controls circuit compilation. - Classically controlled operations are implemented using
if_test(), allowing Bob's actions to depend on Alice's measurement outcomes. - A robust verification method involves preparing a random state with a unitary gate , running the protocol, applying the inverse gate , and measuring to confirm the qubit has returned to .
Preview of the Next Lesson:
We've now seen that teleportation works and how to build it. In the next lesson, we will revisit a crucial question we touched upon briefly: "Why doesn't quantum teleportation enable faster-than-light communication?". We will formalize the argument and ensure the distinction between the instantaneous collapse of the wavefunction and the speed of information transfer is perfectly clear.