Quantum Teleportation

Quantum teleportation
In [ ]:
#Star Trek Beam as example
#quantum teleportation transfer the state of one qubit to another
#information of one place to another
#we cannot copy, it means we measure it and destroy the state
#we need to build the teleportation circuit
#if encounter any problem, restart the kernel
In [1]:
#import the qiskit package
from qiskit import *
In [2]:
#build circuit with 3 classical bits and 3 qubits
circuit = QuantumCircuit(3,3)
In [3]:
#matplot to draw the circuit
%matplotlib inline
circuit.draw(output='mpl')
Out[3]:
In [4]:
#take q0 to q2
#recall X gate transform q0 to q1 previously
#barrier is to see things more cleearer
#state on q0 teleport the state to q2

circuit.x(0)
circuit.barrier()
circuit.draw(output='mpl')
Out[4]:
In [6]:
#apply H gate on q1 then CX gate on q1 and q2
circuit.h(1)
circuit.cx(1,2)
Out[6]:
<qiskit.circuit.instructionset.InstructionSet at 0x1a209645d0>
In [7]:
circuit.draw(output='mpl')
Out[7]:
In [8]:
#q0 and q2 are entangled
#CX gate from q0 to q1
#H gate on q0
#draw circuit
circuit.cx(0,1)
circuit.h(0)
circuit.draw(output='mpl')
Out[8]:
In [9]:
#now do measurement on q0 and q1 and put them in the classical registers q0 and q1
#add barrier and draw circuit
circuit.barrier()
circuit.measure([0,1],[0,1])
circuit.draw(output='mpl')
Out[9]:
In [10]:
#to complete the teleportation protocol, add 2 more gates and barrier first
#CX from q1 to q2
#CZ from Q0 to q2
#draw circuit
circuit.barrier()
circuit.cx(1,2)
circuit.cz(0,2)
circuit.draw(output='mpl')
Out[10]:
In [13]:
#What do we expect? 
#verify this by measureing q2
#measure q2 and put it in classical register 2
#take the circuit and simulate in the simulator in the air backend
#execute the circuit on the backend being
#simulator 1024 shots
#count the result
#plot it by histogram in counts

circuit.measure(2,2)
simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit, backend = simulator, shots = 1024).result()
counts = result.get_counts()
from qiskit.tools.visualization import plot_histogram
plot_histogram(counts)
Out[13]:
In [14]:
#we only get ressult when c2 is 1
#all the 1st digit are 1
print(counts)
#transfer information over long distance
{'101': 258, '110': 284, '111': 237, '100': 245}