#have to install the qiskit library first before we do anything
!pip install qiskit
!pip install ipywidgets
#do our usual installation of some standard libraries
import matplotlib
%matplotlib inline
import numpy as np
#you need to get your personal IBM Token from IBM Quantum Experience
#put your token inside '*****'
token='********'
from qiskit import QuantumCircuit, execute, Aer, IBMQ
IBMQ.save_account(token)
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
provider = IBMQ.load_account()
# Creating registers
tq = QuantumRegister(3)
tc0 = ClassicalRegister(1)
tc1 = ClassicalRegister(1)
tc2 = ClassicalRegister(1)
# Make the Quantum circuit, and give it a name "teleport"
teleport = QuantumCircuit(tq, tc0,tc1,tc2)
# Use this code cell to establish the EPR pair of qubits we need. on q(1) and q(2)
# this is just the first step in the process, so don't code the entire algorithm here.
# add your code between the lines
#_____________________________
#_____________________________
# Check your code by drawing the circuit
teleport.draw()
#Alice makes state to teleport
#YOU ARE GOING TO CHANGE THESE VALUES LATER
#________________________________________________
alpha = np.sqrt(.7)
beta = -np.sqrt(.3)
#________________________________________________
teleport.initialize([alpha, beta], tq[0])
teleport.barrier()
# Show teleportation state on a Bloch sphere
plot_bloch_multivector([alpha,beta]);
# show circuit diagram again
teleport.draw()
# Use this code block to add gates so Alice can entangle her message state
# with her part of the EPR pair.
# add your codes between the lines
#_________________________
#________________________
# show circuit diagram again
teleport.barrier()
teleport.draw()
# Alice does her measurements and stores the results in two classical registers tc0, and tc1
# whent he circuit is drawn, you will also be able to see the gates Alice used to
# entangle her message state with the EPR pair
teleport.measure(tq[0], tc0[0])
teleport.measure(tq[1], tc1[0])
teleport.draw()
# use this code block to add in Bob's gates and measurements
# put your if statements here between the lines
#_______________
#______________
#Bob measures his state as the final step
teleport.measure(tq[2], tc2[0])
teleport.draw()
# run the circuit simulation
# note that this circuit can not be run on an IBM Q device
local_backend = Aer.get_backend('qasm_simulator')
teleport_job = execute(teleport, local_backend)
teleport_result = teleport_job.result()
data = teleport_result.get_counts(teleport)
#plot alice's measurements
alice = {}
alice['00'] = data['0 0 0'] + data['1 0 0']
alice['10'] = data['0 1 0'] + data['1 1 0']
alice['01'] = data['0 0 1'] + data['1 0 1']
alice['11'] = data['0 1 1'] + data['1 1 1']
plot_histogram(alice);
#plot bob's measurements
bob = {}
bob['0'] = data['0 0 0'] + data['0 1 0'] + data['0 0 1'] + data['0 1 1']
bob['1'] = data['1 0 0'] + data['1 1 0'] + data['1 0 1'] + data['1 1 1']
plot_histogram(bob);
# this code block draws two Bloch spheres so you can compare Alice and Bob's states
alpha_Bob = np.sqrt(bob['0']/(bob['0']+bob['1']))
beta_Bob = np.sqrt(bob['1']/(bob['0']+bob['1']))
plot_bloch_multivector([alpha,beta], title='Alice Transmitted State');
plot_bloch_multivector([alpha_Bob,beta_Bob], title='Bob Constructed State');