-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfourier-dm.py
36 lines (29 loc) · 940 Bytes
/
fourier-dm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
print("""
-------------------------------------------------------------------------------------------------------
Problem Statement:
Setup an initial prepared state and compute the fourier transform on it.
-------------------------------------------------------------------------------------------------------
""")
import qsim
import numpy as np
nqbits = 8
try:
# setup an initial state to try out QFT
initstate = [None]*(2**nqbits)
p = 0
stsz = 2**nqbits
for i in range(stsz):
if (i % (stsz/8)) == 0:
initstate[i] = 1
else:
initstate[i] = 0
p += np.absolute(initstate[i])**2
initstate = np.transpose(np.matrix(initstate,dtype=complex))/np.sqrt(p)
# Start the Quantum Computer Simulator
q = qsim.DMQSimulator(nqbits,initstate=initstate, qtrace=True)
# Perform QFT
qftgate = qsim.QFT(nqbits)
q.qgate(qftgate, list(reversed(range(nqbits))))
except qsim.QSimError as ex:
print(ex.args)