This notebook uses Qubiter to illustrate a pedagogical Teleportation experiment performed by S. Fedortchencko on IBM Quantum Experience, and described by him in the paper
$$\newcommand{\bra}[1]{\left\langle{#1}\right|}$$$$\newcommand{\ket}[1]{\left|{#1}\right\rangle}$$
First change your working directory to the qubiter directory in your computer, and add its path to the path environment variable.
import os
import sys
print(os.getcwd())
os.chdir('../../')
print(os.getcwd())
sys.path.insert(0,os.getcwd())
/home/rrtucci/PycharmProjects/qubiter/qubiter/jupyter_notebooks /home/rrtucci/PycharmProjects/qubiter
from qubiter.SEO_writer import *
from qubiter.SEO_simulator import *
from qubiter.StateVec import *
import numpy as np
loaded OneQubitGate, WITHOUT autograd.numpy
Number of qubits is 3. Note that we use "bit" for both qbits and cbits
num_qbits = 3
Use a trivial circuit embedder that embeds 3 qubits into same 3 qubits
emb = CktEmbedder(num_qbits, num_qbits)
Open a writer, tell it where to write to. We will use zero bit last (ZL) convention
file_prefix = 'teleportation-fedor'
wr = SEO_writer(file_prefix, emb)
Write partial circuit that creates a state at qbit 0 that will be teleported to qbit 2.
z_axis = 3
def init_ckt():
wr.write_one_qbit_gate(0, OneQubitGate.had2) # H(0)
wr.write_one_qbit_gate(0, OneQubitGate.rot_ax, [-np.pi/8, z_axis]) # T(0)
wr.write_one_qbit_gate(0, OneQubitGate.had2) # H(0)
wr.write_one_qbit_gate(0, OneQubitGate.rot_ax, [-np.pi/4, z_axis]) # S(0)
init_ckt()
wr.close_files()
init_st_vec = StateVec.get_standard_basis_st_vec([0, 0, 0])
sim = SEO_simulator(file_prefix, num_qbits, init_st_vec)
StateVec.describe_st_vec_dict(sim.cur_st_vec_dict, print_st_vec=True)
*********branch= pure state vector: [[[0.65328148-0.65328148j 0. +0.j ] [0. +0.j 0. +0.j ]] [[0.27059805-0.27059805j 0. +0.j ] [0. +0.j 0. +0.j ]]] total probability of state vector (=one if no measurements)= 1.000000 dictionary with key=qubit, value=(Prob(0), Prob(1)) {0: (0.853553, 0.146447), 1: (1.0, 0.0), 2: (1.0, 0.0)}
Now run the whole circuit. If you want to see the state vector after only first n gates, where n is less than total number of gates, just comment out all gates from n+1 to the final one. You can comment multiple lines with control-slash applied to a selected block. control-slash also uncomments a selected, commented block.
wr = SEO_writer(file_prefix, emb)
init_ckt()
wr.write_one_qbit_gate(2, OneQubitGate.had2) # H(2)
control_pos = 2
target_pos = 1
trols = Controls.new_single_trol(num_qbits, control_pos, kind=True)
wr.write_controlled_one_qbit_gate(target_pos, trols, OneQubitGate.sigx)
control_pos = 0
target_pos = 1
trols = Controls.new_single_trol(num_qbits, control_pos, kind=True)
wr.write_controlled_one_qbit_gate(target_pos, trols, OneQubitGate.sigx)
wr.write_one_qbit_gate(0, OneQubitGate.had2) # H(0)
wr.write_MEAS(tar_bit_pos=0, kind=0)
wr.write_MEAS(tar_bit_pos=1, kind=0)
wr.close_files()
init_st_vec = StateVec.get_standard_basis_st_vec([0, 0, 0])
sim = SEO_simulator(file_prefix, num_qbits, init_st_vec)
StateVec.describe_st_vec_dict(sim.cur_st_vec_dict, print_st_vec=True)
*********branch= pure state vector: [[[0.32664074-0.32664074j 0.13529903-0.13529903j] [0. +0.j 0. +0.j ]] [[0. +0.j 0. +0.j ] [0. +0.j 0. +0.j ]]] total probability of state vector (=one if no measurements)= 0.250000 dictionary with key=qubit, value=(Prob(0), Prob(1)) {0: (1.0, 0.0), 1: (1.0, 0.0), 2: (0.853553, 0.146447)}
Look in files
to see the quantum circuit that was generated
If you do the algebra, the final state vector should be
$ \begin{array}{c}\ket{0}\\ \ket{0} \\ (\frac{cc}{2} \ket{0} + \frac{ss}{2}\ket{1}\end{array}+ \begin{array}{c}\ket{0} \\ \ket{1} \\ (\frac{cc}{2} \ket{0} + \frac{ss}{2}\ket{1})\end{array}+ \begin{array}{c}\ket{1} \\ \ket{0} \\ (\frac{cc}{2} \ket{0} - \frac{ss}{2}\ket{1})\end{array}+ \begin{array}{c}\ket{1} \\ \ket{1} \\ (\frac{-ss}{2} \ket{0} + \frac{cc}{2}\ket{1})\end{array} $
where cc = cos(\pi/8) and ss = sin(\pi/8), and where the first, second, third row corresponds to qubit 0, 1, 2