In this post I will help to untangle the mystery of quantum teleportation and provide some sample code that you can run on IBM’s Quantum Experience to see it in action. I will be using QISKit in this article so download and install the SDK.
This is a follow up post to an earlier article on Superdense Coding, so I encourage to you read that first as you will need to have a good understanding of quantum superposition and entanglement before tackling the subject of quantum teleportation.
As we shall see quantum teleportation is really the flip side of superdense coding. In superdense coding we are able to send two classical bits of information using only a single qubit. In quantum teleportation we will use two classical bits of information to send a single qubit that is in an unknown quantum state.
I will walk you through the math, quantum circuits, and code. Along the way, I will explain what is happening in each step. Before I get started I assume that you have some knowledge of qubits, Dirac notation, classical bits, and linear algebra. If you are looking for a tutorial on Quantum Computing I encourage you to check out the IBM Q Experience documentation.
Before we dive into the foundational concepts let’s look at some Python code that we will use in our examples. In the following code fragment, we create two types of registers: quantum and classical. The classical registers will be used to store the results of measuring our quantum registers. The quantum registers are our ‘qubits’ and we will manipulate them in our program to achieve certain desired effects. The quantum circuit will be used to wire our qubits and operations together. You can find a copy of the code that we will use throughout the article here.
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegisterfrom qiskit import available_backends, execute# Create three quantum and classical registersq = QuantumRegister(3)
c = ClassicalRegister(3)
qc = QuantumCircuit(q, c)
Before we embark on our journey into quantum teleportation we need to first discuss what it means to copy or clone a qubit. As we will soon see, qubits in unknown states cannot generally be copied or cloned. So, naturally you should be asking yourself how will we be able to transmit a qubit if we cannot copy or clone it? In this article I will show you how we can work around this restriction to faithfully send a quibit without loss of information.
As a refresher recall the Dirac and vector notation for |0⟩ and|1⟩ basis states and the general description of a qubit as a linear combination of basis states, as shown in the diagrams below.
No Cloning Theorem
Let’s start our journey into quantum teleportation by first exploring the notion of cloning qubits. The “No Cloning Theorem” states that you cannot universally clone a qubit in an unknown quantum state. Let’s dig into this a little deeper to see why this is true.
Before we jump in, let’s just spend a moment to take a look at the rules for adding and multiplying vectors, as we will need this information to understand the “No Cloning Theorem”.
|𝜓⟩,|𝜙⟩, and |𝜔⟩ are vectorsThe sum |𝜓⟩ + |𝜙⟩ is a vectorThe scalar product 𝛼|𝜓⟩ is a vector and 𝛼 is a complex number 𝛼 ∈ ℂAddition is commutative: |𝜓⟩ + |𝜙⟩ = |𝜙⟩ + |𝜓⟩Addition is associative: (|𝜓⟩ + |𝜙⟩) + |𝜔⟩ = |𝜙⟩ + (|𝜓⟩ + |𝜔⟩)Scalar multiplication is distributive for scalars and vectors:(𝛼 + 𝛽)|𝜓⟩ = 𝛼|𝜓⟩ + 𝛽|𝜓⟩ where 𝛼,𝛽 ∈ ℂ𝛼(|𝜓⟩ + |𝜙⟩) = 𝛼|𝜓⟩ + 𝛼|𝜙⟩ where 𝛼 ∈ ℂScalar multiplication is associative:𝛼(𝛽|𝜓⟩) = (𝛼𝛽)|𝜓⟩ where 𝛼,𝛽 ∈ ℂ
Now, imagine that we could build a special unitary operator called U that could clone a qubit. This operator would take as input two qubits, one in an unknown state |𝜓⟩ and the other in a state such as |0⟩ that will serve as our target for copying. The cloning operator would then produce a copy of our qubit along with the original source qubit and both qubits will be in the same state |𝜓⟩.
So, let’s test our cloning operator and see what happens when we use it. We know that if we apply our cloning operator we should end up with a copy and our original qubit, as shown below.
Recall that a qubit is simply a superposition of states|𝜓⟩ = α|0⟩+β|1⟩. So, let’s go ahead and replace |𝜓⟩ with α|0⟩+β|1⟩ and then take the product, as shown below.
Now, what would our cloning machine do if we cloned the expansion of |𝜓⟩? So let’s try that out and see what we get, as shown below.
Which is the same as:
Let’s compare the results of our two cloning operations:
- α²|00⟩ + αβ|10⟩ + αβ|01⟩ + β²|11⟩
- α|00⟩ + β|11⟩
As you can see the results are not the same. How can we make this work? The simple answer is that we cannot, as shown below.
We are left with a contradiction, either Quantum Mechanics is wrong in spite of decades of experimental evidence proving the contrary or we cannot reliably clone qubits that are in unknown quantum states. The sad fact is that no matter how hard we try we simply cannot clone qubits in unknown quantum states.
There is one subtlety to point out though. The “No Cloning Theorem” does not say that two qubits cannot be in the same quantum state. It just states that if you don’t know the state then you cannot build a machine to reliably clone it. The universe is free to allow qubits that are in the same state.
Now, what if we knew the state in advance could we clone it? The answer to this is yes. For example, if we knew we had to clone a qubit that was going to be in one of two possible superposition states |+⟩ or |−⟩, then we could perform some number of unitary transforms that would enable us to copy the state of the qubit.
Recall that the Hadamard transform is used to place a qubit into either the |+⟩ or |−⟩ superposition states depending upon whether operator is applied to a qubit either in the |0⟩ or |1 ⟩ basis state. The resultant vector has equal probabilities of returning either 0 or 1 when the qubit is measured. The diagrams below show the definition of |+⟩ and |−⟩ as well as the quantum circuit for generating them.
How are we able to copy the state of the qubit? We know that the two superposition states |+⟩ or |−⟩ must have been generated from either the |0⟩ or |1⟩ basis states. So, this means that if we were to take our qubit that was in the |+⟩ or |−⟩ state out of superposition, then our qubit would be in either the |0⟩ or |1⟩ basis state.
We can easily take our qubit out of superposition by applying the Hadamard transformation. Recall that quantum transformations are reversible, so applying the same unitary Hadamard transformation effectively undoes the prior Hadamard transformation, see the diagram below.
Once the qubit is out of superposition we can perform a controlled not (CNOT) between our source qubit that we want to copy and the target qubit, where the source qubit acts as the control for the target qubit. Recall that the CNOT operator is a 2 qubit unitary transformation where one qubit acts as a control and the other serves as a target. If the control qubit is set to 1, then the target qubit is flipped.
Now that we have both qubits in the same basis state |0⟩ or |1⟩ we can perform a Hadamard transform to place both qubits into the same superposition state |+⟩ or |−⟩. The circuit diagram below shows the series of unitary transforms that we performed to copy a qubit in the|+⟩ state.
Here is the QISKit code to do perform our copying operation.
# Create an initial superposition + state
qc.h(q)# Take the qubit out of superposition
qc.h(q)# Perform a CNOT between the qubits
qc.cx(q, q)# Put the qubits into superposition and now the states are the same
So given the restrictions and limitations on cloning qubits is there some way that we could communicate the state of an unknown qubit using some of the basic properties of quantum computing? Let’s say that Alice has a qubit in an unknown quantum state |𝜓⟩ = α|0⟩ + β|1⟩ that she wishes to communicate to her colleague Bob, how might she do this? Well let’s pretend that we could somehow create a magical link between Alice’s qubit and a qubit that Bob has prepared in the |0⟩ basis state.
What type of special link might Alice create? Let’s imagine that she could setup a CNOT gate between her qubit and Bob’s qubit that could span any distance, as shown below. We know that such a gate is impossible to create, but let’s pretend that we could establish a CNOT gate between these qubits to see what happens.
We can see that after the CNOT gate is applied the joint state is now
|𝜓⟩ = α|00⟩ + β|11⟩. So what if Alice were to measure her qubit ① in the |0⟩ and |1⟩ basis state? Well she would get either 0 or a 1 and the new joint state would be either |00⟩ or |11⟩ leaving Bob’s qubit ② in the state |0⟩ or |1⟩ which is not the same state as α|0⟩ + β|1⟩. So doing this type of measurement is clearly not going to help Alice communicate with Bob.
So does Alice have any other options? What if Alice were to measure her qubit ① in the |+⟩ and |−⟩ basis state? To do this we can write |0⟩ and |1⟩ in terms of |+⟩ and |−⟩, as shown below.
Now let’s go ahead and rewrite Alice’s qubit ① in terms of |+⟩ and |−⟩, as shown below.
Let’s simplify this by collecting terms, as shown below.
We can see that if Alice were to measure her qubit ① she would get either + or −, leaving Bob’s qubit ② either in the state α|0⟩ + β|1⟩ or α|0⟩ − β|1⟩.
In the case when Alice measures her qubit ① and gets a +, then Bob does not need to do anything to his qubit ② as it is exactly in the correct state
α|0⟩ + β|1⟩. If Alice, however, measures −, then Bob’s qubit is out of phase
α|0⟩ − β|1⟩.
Bob can change the phase of his qubit to get the correct state of
α|0⟩ + β|1⟩. Bob does this by applying the Pauli Z gate. Applying the Z gate flips the phase of Bob’s qubit. If you want to learn more about the Pauli gates check out this link and also my article on Superdense Coding. So all Alice needs to do is tell Bob which measurement she made, either + or −. If needed Bob then applies the phase shift Z gate to correct the phase , as shown below.
How can Alice make her measurement in the |0⟩ and |1⟩ basis and be able tell whether she is measuring + or −? The answer is that Alice will apply the Hadamard H gate to her qubit ① prior to making her measurement, as shown below.
The Hadamard gate projects + onto the measurement of 0 and − onto the measurement of 1. Remember that once Alice makes her measurement she will destroy her qubit, but her qubit’s state will have shifted to Bob’s qubit. The code below shows how we can measure in the + and − basis and apply a phase flip if needed.
# Prepare an initial state for qubit ① using a single unitary
qc.u1(0.5, q)# Perform a CNOT between qubit ① and qubit ②
qc.cx(q, q)# Measure qubit ① in the + - basis
qc.measure(q, c)# If needed Perform a phase correction to qubit ②
if c == 1:
So what does this tell us about transmitting qubits? It tells us that if we had some way to create a remote CNOT between Alice’s qubit and Bob’s qubit we could communicate. The good news is that we do have a way to do this and that is through entanglement. So now let’s see how we can use entanglement to establish a remote CNOT operation and teleport a qubit.
How will this work? What we are going to do is to create a special state of entanglement between three qubits where one of our qubits holds the unknown information we want to send and the other two will be an entangled pair of qubits that will be shared between the sender and the receiver of the information.
We will be performing a series of measurements on two of the qubits which will end up taking them out of entanglement. These measurements and our knowledge of entangled states will enable us to “teleport” our source qubit to the destination without loss of information. We will, however, be destroying the source qubit that contains the information that we want to send as part of our teleportation protocol.
Setting up the Initial States
In our scenario let’s pretend once again that Alice would like to send Bob a qubit that is in some unknown state. We know that Alice cannot directly clone the qubit, because of the “No Cloning Theorem”. Alice, however is a very clever quantum coder and knows that she can use the nature of quantum entanglement to help her achieve her goal.
The first thing that Alice does is to call up her friend Eve to help her and Bob out. She asks Eve to prepare a pair of entangled qubits for her and Bob and instructs Eve to give her one of the qubits and send Bob the other one, as shown in the circuit diagram below.
In the circuit diagram the qubit labeled ① is the qubit that contains the unknown information that Alice wants to teleport to Bob. The qubits labeled ② and ③ are the entangled qubits that Eve has prepared for Alice and Bob. The joint state of our 3 qubit system is simply the product of the qubits, as shown below.
Here is the QISkit code for setting up the entangled pair of qubits and the initial state of the qubit that we will be teleporting.
# Prepare an initial state for qubit ① using a single unitary
qc.u1(0.5, q)# Prepare an entangled pair using qubit ② and qubit ③
qc.cx(q, q)# Barrier to prevent gate reordering for optimization
Creating the Remote Controlled Not and Applying Correction
Now that we have prepared our qubits, the next thing that Alice does is to perform a CNOT operation between qubit ① that she wishes to teleport to Bob and her half of the entangled pair of qubits ② that she shares with Bob, as shown in the circuit diagram below.
Let’s see what effect the CNOT operation now has on the joint state of the 3 qubit system, as shown below. As we can see when qubit ① is set to 1 as indicated by the green rectangle, the target qubit ② is flipped, as indicated by the red rectangles.
So how does this help Alice in communicating with Bob? Well at this point what would happen if Alice were to measure qubit ②, as shown in the circuit diagram below?
Alice would get either a 0 or a 1. What does this measurement tell Alice? It tells Alice that the joint remaining state of qubits ① and ③ are in either one of the two possible states, as shown below.
Remember Alice is trying to send Bob the state |𝜓⟩ = α|0⟩ + β|1⟩. However, when Alice measure qubit ② and gets a 1 she knows that qubit ③ has somehow become flipped from a 0 to a 1. At this point Alice writes this measurement down and tells Bob what she measured. Alice and Bob know that they can easily flip a qubit by applying the Pauli X gate, as shown below. If you want to learn more about the Pauli operators follow this link.
Here is the QISKit code for establishing the CNOT, measuring the qubit, and performing a bit flip if necessary.
# Perform a CNOT between qubit ① and qubit ②
qc.cx(q, q)# Measure qubit ② in the computational basis
qc.measure(q, c)# If needed Perform a bit flip correction to qubit ③
if c == 1:
Applying Phase Correction
The next thing that Alice does is to perform a Hadamard transformation on qubit ① just like she did before so that she can tell Bob if he needs to perform a phase flip on his qubit ③, as shown in the circuit diagram below.
let’s dig into this a little deeper to see what happens to the state of our 3 qubit system after applying the Hadamard gate. Recall from earlier that applying the Hadamard operator to the qubit basis states |0⟩ and |1⟩ transforms our qubit into one of the following two superposition states.
Let’s now substitute the two superposition states for H|0⟩ and H|1⟩ into our previous 3 qubit state description, as shown below and indicated by the red rectangle.
Now let’s take the product and see what the state of our 3 qubit system is, as shown below.
To make it easier to see what is happening let’s refactor such that we group qubits ① and ② together and isolate qubit ③, as shown below and indicated by the red rectangle.
We see that qubit ③ contains in all but three case the original state of qubit ①. What we have effectively done is teleported the state from qubit ① to qubit ③. We are still left with one remaining issue though.
Recall that we are trying to teleport the state of qubit ① which was
|𝜓⟩ = α|0⟩ + β|1⟩ and we already took care of the cases where we needed to flip our qubit, so all that remains is to take care of the cases where Bob needs to flip the phase of his qubit using the Pauli Z gate.
Earlier we saw that Alice was able to do determine whether a phase flip was needed by measuring the qubit in the |+⟩ and |−⟩ basis. So Alice now performs a measurement after applying the Hadamard gate which enables her to measure a 0 when the qubit is + and 1 when the qubit is − and then gives this value to Bob for him to determine whether he needs to perform a phase flip, as shown below.
Here is the QISKit code for measuring the qubit in the + − basis and performing a phase correction if necessary.
# Measure qubit ① in the + - basis
qc.measure(q, c)# If needed Perform a phase correction to qubit ③
if c == 1:
So there we have it! Alice is able to successfully teleport a qubit to Bob. There are a few important takeaways from the teleportation protocol that we should briefly mention:
- Alice and Bob did not communicate faster than the speed of light. Alice had to tell Bob what her two measurements were, and this had to be done over some classical communication channel, which by definition is slower than the speed of light.
- Alice ends up destroying her qubit as she teleports the information to Bob and therefore we did not violate the no cloning theorem.