In [4]:
import numpy as np
import quasm_module as qm
import qutip
from qutip import qip

In [7]:
qip.cnot(3,2,1)[0]


Out[7]:
array([[ 1.+0.j,  0.+0.j,  0.+0.j,  0.+0.j,  0.+0.j,  0.+0.j,  0.+0.j,
         0.+0.j]])

In [3]:
qm.single_qubit_gate('h',0,2)


Out[3]:
array([[ 0.70710678,  0.        ,  0.70710678,  0.        ],
       [ 0.        ,  0.70710678,  0.        ,  0.70710678],
       [ 0.70710678,  0.        , -0.70710678, -0.        ],
       [ 0.        ,  0.70710678, -0.        , -0.70710678]])

In [2]:
bla=qm.load_qasm_file('test4.qasm')

In [3]:
instructions=qm.get_filtered_qasm(bla)

In [12]:
instructions


Out[12]:
['        qubit \tq0\n',
 '        qubit \tq1\n',
 '\n',
 '\tcnot\tq0,q1\n',
 '\tcnot\tq1,q0\n',
 '\tcnot\tq0,q1\n']

In [15]:
qm.read_instruction_line(qm.delete_instruction(instructions,3))


Out[15]:
['cnot', [['q0', 'q1']]]

In [6]:
qm.delete_instruction(instructions)


Out[6]:
['        qubit \tq1\n', '\n', '\tcnot\tq0,q1\n', '\tcnot\tq1,q0\n']

In [3]:
filename='test1.qasm'
quasm_file=[]
f=open(filename,'r')
for line in f:
    quasm_file.append(line)
    print(line)



qubit   q0  # Define a qubit

h   q0      # Apply a Hadamard gate

measure q0  # Measure in computational basis


In [20]:
quasm_instrunctions=[]
alphabet='abcdefghijklmnopqrstuvwxyz'
m=0
for tt, line in enumerate(quasm_file):
    if not line[0] in alphabet:
        m+=1
        pass
    else:
        quasm_instrunctions.append('')
        for char in line:
            if not char=='#' or char=='\n':
                quasm_instrunctions[tt-m]+=char
            else:
                break
print(quasm_instrunctions)


['qubit   q0  ', 'h   q0      ', 'measure q0  ']

In [13]:
num_qubits=0
for line in quasm_instrunctions:
    if 'qubit' in line:
        num_qubits+=1
print('Number of qubits is '+str(num_qubits))


Number of qubits is 1

In [11]:
def number_of_qubits(quasm_instrunctions):
    num_qubits=0
    for line in quasm_instrunctions:
        if 'qubit' in line:
            num_qubits+=1
    return num_qubits


Out[11]:
1

In [2]:
qm.operator_dict_default()


Out[2]:
{'h': array([[ 0.70710678,  0.70710678],
        [ 0.70710678, -0.70710678]]), 'i': array([[1, 0],
        [0, 1]]), 'x': array([[0, 1],
        [1, 0]]), 'y': array([[ 0.+0.j, -0.-1.j],
        [ 0.+1.j,  0.+0.j]]), 'z': array([[ 1,  0],
        [ 0, -1]])}

In [6]:
1/np.sqrt(2)*np.array([[1,1],[1,-1]])


Out[6]:
array([[ 0.70710678,  0.70710678],
       [ 0.70710678, -0.70710678]])

In [11]:
my_dict={}
my_dict['h']=1/np.sqrt(2)*np.array([[1,1],[1,-1]])

In [12]:
my_dict.update({'i':np.array([[1,0],[0,1]])})

In [ ]:


In [4]:
qm.single_qubit_gate(h,1,2)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-0db3a6d53a92> in <module>()
----> 1 qm.single_qubit_gate(h,1,2)

NameError: name 'h' is not defined

In [45]:
np.tensordot([[0,1],[0,1]],[[0,1],[0,1]])


Out[45]:
array(2)

In [52]:
A=np.array([[1,0],[0,1]])
print(A)
B=np.array([[1,0],[1,1]])
print(B)
print(np.kron(A,B))


[[1 0]
 [0 1]]
[[1 0]
 [1 1]]
[[1 0 0 0]
 [1 1 0 0]
 [0 0 1 0]
 [0 0 1 1]]

In [47]:
np.outer([[1,0],[0,1]],[[0,1],[0,1]])


Out[47]:
array([[0, 1, 0, 1],
       [0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 1, 0, 1]])

Basic Ideas

  • Read in the quasm file
  • Extract such that it contains only relevant information
  • Make a qubit class
  • Find how many quibts are needed

In [ ]: