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[0] which is psi(1)
# Alice has q[0] and q[1]
# Bob has q[2]
qc.u3(0.3, 0.2, 0.1, q[0])

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

qc.cx(q[0], q[1])

qc.measure(q[0], c0[0])
qc.measure(q[1], c1[0])
qc.z(q[2]).c_if(c0, 1)
qc.x(q[2]).c_if(c1, 1)

qc.measure(q[2], c2[0])
circuit over view

What does mean the circuit? OK calculate it.

First step is q[0] passed unitary gate and q[1] passed hadamard gate.

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

q[1] 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[1] passed cx gate. Then qubit will be below.

1/\sqrt{2}(\alpha|000> + \alpha|011> + \beta|100> + \beta|111> )

Then q[0] 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[2] can not separate it is entangle state.

Then, q[0] passed hadamard gate….

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[0], q[1] measurements.

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

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

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

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

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

Let’s run the circuit

res = execute(qc, backend, shots=1024)

c[2] is top of the 3 bit numbers. Most of c[2] 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[0] 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)
j = execute(qc2, backend, shots=1024)

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

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

Today’s code is below.



Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: