# Let’s teleportation! #Quantumcomputing #qiskit #memo

Recently I am learning quantum computing and qiskit coding.
Learning new things is very fun for me.

Today I tried to code quantum teleportation with qiskit.

’Teleportation’ sounds attractive for me I watched many SF movies when I was child ;) BTW, definition of teleportation is ‘the ability to transport a person or object instantly from one place to another ‘.(from wikipedia)

It is not magic.

What is quantum teleportation?

Quantum teleportation is a process by which quantum information (e.g. the exact state of an atom or photon) can be transmitted (exactly, in principle) from one location to another. The method transport information not object.

It seems useful for information transfer.

OK let’s write code. Following circuit uses 3 qubits. Alice has two qubits and Bob has one qubit. Alice would like to transfer her one qubit information $|\Psi(1)>$ Psi is defined as $\Psi(1)=\alpha|0> + \beta|1>$.

Bob would like to know alpha and beta.

At first import packages and generate $\Psi(1)$ with unitary gate.

from qiskit import QuantumCircuit
from qiskit import QuantumRegister
from qiskit import ClassicalRegister
from qiskit import visualization
from qiskit import BasicAer
from qiskit.aqua import run_algorithm
from qiskit.visualization import plot_histogram
from qiskit import execute
backend = BasicAer.get_backend('qasm_simulator')

q = QuantumRegister(3)
c0 = ClassicalRegister(1,'c0')
c1 = ClassicalRegister(1,'c1')
c2 = ClassicalRegister(1,'c2')

qc = QuantumCircuit(q, c0,c1,c2)
# set first state of q which is psi(1)
# Alice has q and q
# Bob has q
qc.u3(0.3, 0.2, 0.1, q)


Next I made quantum circuit. The circuit is made with hadamard gate, controlled not gate, and pauli x, z gate.


qc.h(q)
qc.cx(q,q)
qc.barrier(q)
qc.cx(q, q)
qc.h(q)
qc.barrier(q)

qc.measure(q, c0)
qc.measure(q, c1)
qc.z(q).c_if(c0, 1)
qc.x(q).c_if(c1, 1)

qc.measure(q, c2)
qc.draw(output='mpl')


What does mean the circuit? OK calculate it.

First step is q passed unitary gate and q passed hadamard gate.

q will be $U3|0> \rightarrow \alpha|0> + \beta|1>$

q will be $H|0> \rightarrow 1/\sqrt{2}(|0> + |1>)$

So after U3 and H gate, circuit state will be… $1/\sqrt{2}(\alpha|0> + \beta|1>) \otimes (|0> + |1>) \otimes |0>$
= $1/\sqrt{2}(\alpha|000> + \alpha|010> + \beta|100> + \beta|110> )$

Then q passed cx gate. Then qubit will be below. $1/\sqrt{2}(\alpha|000> + \alpha|011> + \beta|100> + \beta|111> )$

Then q passed cx gate. qubit will be. $1/\sqrt{2}(\alpha|000> + \alpha|011> + \beta|110> + \beta|101> )$
=> $1/\sqrt{2}(\alpha|000> + \alpha|011> + \beta|110> + \beta|101> )$

Now q can not separate it is entangle state. $1/2(\alpha(|0>+|1>)|00> + \alpha(|0>+|1>)|11> + \beta(|0>-|1>)|10> + \beta(|0>-|1>)|01> )$

=> $1/2(\alpha(|000>+|100>) + \alpha(|011>+|111>) + \beta(|010>-|110>) + \beta(|001>-|101>))$

=> $1/2( |00>(\alpha|0>+\beta|1>) + |01>(\alpha|1>+\beta|0>) + |10>(\alpha|0>-\beta|1>) + |11>(\alpha|1>-\beta|0>))$

Now entangle state is solved.
Bob can get Alices information by applying pauli x, z gate combination depends on q, q measurements.

If q, q = 00, q is $\alpha|0>+\beta|1>$, no operation is required.

If q, q = 01, q is $\alpha|1>+\beta|0>$, it is required Pauli x gate.

If q, q = 10, q is $\alpha|0>-\beta|1>$, it is required Pauli z gate.

Finally, q, q = 11, q is $\alpha|0>-\beta|1>$, it is required Pauli z gate.

Alice need to tell Bob her measurements of q, q, so Bob can not information faster than light.

Let’s run the circuit


res = execute(qc, backend, shots=1024)
plot_histogram(res.result().get_counts(qc))


c is top of the 3 bit numbers. Most of c is 0. And how about alpha and beta?

Alpha = 0.245+0.258+0.219+0.256 = 0.978

Beta = 0.007+0.005+0.005+0.006 = 0.023

Check q first state.

q1 = QuantumRegister(1)
c5 = ClassicalRegister(1)
qc2 = QuantumCircuit(q1,c5)
qc2.u3(0.3, 0.2, 0.1, q1)
qc2.measure(q1, c5)
qc2.draw(output='mpl')

j = execute(qc2, backend, shots=1024)
plot_histogram(j.result().get_counts(qc2))


Probability is almost same. If the code run without U3gate, c will be only0.

I do not fully understand quantum teleportation now. So I’m reading some papers about it.

Today’s code is below.

https://nbviewer.jupyter.org/github/iwatobipen/playground/blob/master/tereportation.ipynb

This site uses Akismet to reduce spam. Learn how your comment data is processed.