from qiskit import *

%matplotlib inline
from qiskit.tools.visualization import plot_histogram

qc = QuantumCircuit(3, 3)
qc.draw(output='mpl')

# we will teleport the state q_0 to q_2 with using q_1
qc.x(0)
qc.barrier()
qc.draw(output='mpl')

# barrier decide that after barrier q_0 has state |1> than of |0>
qc.h(1)
qc.cx(1, 2)
qc.draw(output='mpl')

# It created an entangled state means same qubit exits on q_1 and q_2 at the same time  also
qc.cx(0, 1)
qc.h(0)

qc.draw(output='mpl')

qc.barrier()
qc.measure([0,1],[0,1])
qc.draw(output='mpl')

# before measure all the states are entangled but to complete the teleportation process 
qc.barrier()
qc.cx(1,2)
qc.cz(0,2)

qc.draw(output='mpl')

# the qubit at q_0 teleported to the state q_2
# let's measure q_2 states
qc.measure(2,2)
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc, backend=simulator, shots=1024).result()
counts = result.get_counts()
plot_histogram(counts)


print(counts)

# It is used to transfer quantum information over long distances 
"""
Question : Build a Quantum Teleportation circuit to teleport the qubit |+> or |-> 


"""


qc = QuantumCircuit(3, 3)
qc.h(0)
qc.barrier()
qc.draw(output='mpl')

