# Quantum Teleportation Algorithm — Programming on Quantum Computers Ep 5

We’re not transporting
qubit zero to qubit two, but teleporting the information contained in qubit zero onto qubit two. (upbeat electronic music) Hey, welcome back to coding with Qiskit. This is Abe. In today’s video, we’ll be talking about
quantum teleportation. Now the word teleportation might be familiar to you
from pop culture references, and in particular, one that’s very popular is Star Trek’s beam me up technology, and more recently, quantum
teleportation has been in the news as a result of developments in the field of quantum
computing in general. Today we’re going to explain how to build this quantum teleportation
circuit on Qiskit. Now you might think that a circuit like quantum teleportation might require several complicated gates, but in fact you’ve done most of the work in your hello world application, so we’ll build from that
hello world application, and add a few more gates in order to do something very useful. So before we begin, let’s understand what
quantum teleportation means. So quantum teleportation is the transfer of quantum states from
one qubit to one other. Now let’s not get too excited. This does not mean physically transporting a qubit from one place to another, but in fact this is a transfer of quantum information
from one qubit to another. Now you might wonder why we’re even doing any of this. Now in a classical computer, copying something and transferring it from one place to another isn’t a problem. In fact, we do it every day. However, in quantum computers, the act of trying to transfer by copying is not allowed because the moment you copy you’re actually implicitly doing a measurement, which destroys the quantum state that you’re trying to transfer
from point A to point B. In order to get around this problem, we’re going to take
advantage of entanglement as a resource and build a circuit which is the quantum
teleportation circuit. So as always we begin by importing Qiskit into our workspace, and I do that by typing from
qiskit import everything. I am first going to
build a quantum circuit made up of three classical
bits and three quantum bits, so it’s written down in this compact from, quantum circuit three, three. I want to point out that this is slightly different from what you have seen in the hello world application. It’s a more compact notation, and what this language is saying is I want to build a quantum circuit made of three quantum bits
and three classical bits. All right, so as I’ve mentioned before, we’re going to be drawing
our circuit at every step, and looking at how it looks, and so I’m going to
type matplotlib inline, and then circuit dot draw, I’ll put equals matplotlib. So as you see our circuit doesn’t look too exciting at the moment. These are the three quantum bits, and these are the three classical bits, so now what we’re going to do is begin the teleportation circuit, so I’m going to take Q zero, which is this quantum bit. I’m going to take the
state in that quantum bit and transfer it over to Q two, which is this lower quantum bit. Q one will be a resource that we use in order to do this process. So let’s start a bit simple. What I’m going to do is
teleport the state one from Q zero to Q two. You might remember from the gates video that the way to take
us from the state zero in Q zero to the state one is by applying an X gate, so let me do that first. (electronic music) As you see here, we have now our X gate, which means at this point, right after the barrier, we have the state one on Q zero, and we’re going to teleport
that state to Q two. All right, now here comes
the teleportation protocol. So the first thing I’m going to do is create entanglement
between Q one and Q two, and this is very simple. We’re going to follow
exactly the same procedure that we did in our
hello world application, so what I’m doing first is applying a Hadamard gate on Q one, and then I’m applying a controlled X gate between Q one and Q two. (electronic music) So I’m going to draw the circuit again, to show you what it looks like. And as you see here, this is the familiar entanglement circuit that we used in our
hello world application. Okay, so now Q one and
Q two are entangled. The rest of the teleportation protocol dictates that we apply
the following two gates: a controlled X gate going
from Q zero to Q one, and we’re going to apply a Hadamard gate on Q zero, okay? Let’s draw our circuit again. So now this is how our circuit looks. And there’s one more missing aspect to the teleportation circuit, and that is to do two measurements. The measurements are going to be on Q zero and Q one, so I can do that by writing out circuit dot measure, take the measurements in Q zero and Q one, and put them in the classical registers Q zero and Q one. Before I do this, just so that
we see things more clearly, I’m going to add a barrier, and I’m going to draw the circuit. All right, so as you see here, these are the two measurements that I’ve started off with, and now for the teleportation
protocol to complete, I need to add two more gates. These gates are shown here. So I’m going to add a barrier first, and then I’m going to apply controlled X going from qubit one to qubit two, and a controlled Z going
from qubit zero to qubit two. Here’s how our circuit looks. And that’s it. So this is the quantum
teleportation protocol. So what I’m claiming to
you at this point is that the state one here that we have at the end of this barrier has now been teleported
to this qubit, Q two. We can verify this by
applying a measurement to Q two and seeing the outcomes. So what do we expect? You might notice that Q two starts off in the state zero, and I’m claiming that I’ve teleported the state one to that qubit, so if I measure this qubit, what I expect to see is always one. So let’s do that simulation, so we can now take the circuit and simulate it in one
of the chasm simulators in the air backend. (electronic music) I’m going to execute the quantum circuit on the backend, being the simulator, and I’m going to say I want 1,024 shots of this experiment. Really this number could be anything. So I’m going to add dot result to execute, and then I’m going to say the counts are result dot get counts, and the I’m going to take the visualization tools in Qiskit, so from Qiskit dot tools dot visualization import plot histogram, and then I’m going to
plot histogram counts. So notice that so far I haven’t added the measurement on Q two yet, so let me quickly add
that before we move on. What I’m saying is take the results of measuring qubit two and put it in classical register two. Okay, so let’s see what happens. So these are the results. First of all, to understand these results, let me point out something to you. So these numbers here are read as C two, C one, C zero, so just like they’re pointed upward, you can read them off as the result in this one and this one and this one, so the result one, zero, zero means the results here
are one, zero, and zero on these lines. So as I mentioned before, we’ve taken the results of measuring Q two and put them in C two, and that’s this last number, and as you see, we only get results where C two is equal to one. And that I hope convinces you that the measurement results always have the state we want in that particular qubit, qubit two. If you actually want to
see what the counts are, you can always print the counts, and as you see, all the results have this first digit as one. And just as a reminder, we’re seeing the counts here being 223 for the result one,
zero, one, for example, and when you look for one, zero, one here, you see something that says 0.218. And that’s because 223 is 21.8% of the total number of
shots that we asked for in the measurement. And so at this point,
I think it’s important to remind you again what we’ve done. So we’ve built this fairly
complicated circuit, but at the end of the day, what we’ve done is taken
the state in Q zero and teleported it to the state in Q two, so at the end of this complicated circuit, what you’ve done is taken the state here and brought it down here. And you can see this has
tremendous application, so we haven’t mentioned so far the key element of the circuit, which is that there’s entanglement here, which allows us to take these two qubits far apart from each other, and so what this allows us to do is transfer quantum information
over long distances, and this is one of the
key application areas where applying the quantum
teleportation circuit can become very useful. I hope this has made sense to you, and in fact, one thing
you can try out here to make sure that you’ve understood how the circuit works is the following challenge. So you’ve noticed here
that I’ve teleported the state one on this qubit down to this qubit, so instead, remember that you can teleport any quantum state that you’d like, so in particular, here’s a challenge. Why do you try teleporting the state zero plus one over the square root of two? So remember again, this
is the quantum state that you get when you
apply a Hadamard gate onto the zero quantum state, so why do you try to apply the quantum teleportation protocol to this particular state and see what the outcomes are. And tell us in the comments
down below what you find. So I hope it’s been clear to you that simple modifications on top of the already simple quantum algorithm that we built in the
hello world application can lead to a very useful quantum circuit, and in fact that this quantum circuit is the basis for more
complicated quantum algorithms. In the next video, we’ll consider the Bernstein
Vazirani algorithm. Be sure to subscribe so
that you don’t miss out. Thanks for watching, and we’ll see you in the next video. (upbeat electronic music)

## 11 thoughts on “Quantum Teleportation Algorithm — Programming on Quantum Computers Ep 5”

1. Rithvik Jain says:

Do we have to buy an api token on ibmq to execute our programs on a real q-computer

2. J Li says:

Might need a different shirt…

3. Umer Yasin says:

I really waiting for when next Ep will came. thanks to Qiskit

4. f 5673 says:

Could you mute the music when you start explaining? It's really annoying

5. linkcell says:

here's what I cannot understand: if I rotate a qubit with H, then X should produce no difference at all (here the cx after entangling q and q). Also, if I have a qubit on state |0> or |1>, as should be the case of q at the end of the line, then a Z rotation shouldn't produce any difference. what am I missing?

6. Matthew Fyson says:

If the histogram doesn't show, try using plot_histogram(counts).show()
worked for me

7. nein nein says:

what is the cz gate for ?

8. Oke Uwechue, Ph.D. says:

Another very interesting video. Thnx!

However, how does the end-result of your circuit differ from a much simpler 2-qubit circuit such as:

q0: | 0 > ——– [H]———*————

|

|

q2: | 0 > —————– [CNOT]——–

at the outputs, the state of q2 will always reflect the state of q0.

Is this not equivalent to teleportation?
Why is the intermediary qubit, q1, necessary?

9. Pete F says:

Thanks Abe

10. Spencer Churchill says:

i did the challenge by simply applying the hadamard gate to q0 instead of the x gate and was happy to see the histogram show all possibilities of 000 to 111…

but i was wondering if the cx and cz gates on q2 are necessary before measuring. i see i get the same probabilities so id like to know why they're there.

11. Dharma Raj says:

super cool 🙂