-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtf.py
More file actions
36 lines (31 loc) · 954 Bytes
/
qtf.py
File metadata and controls
36 lines (31 loc) · 954 Bytes
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
'''
qtf.py
Now we try out making the quantum fourier transform
'''
import sys, math
import numpy as np
from numpy.fft import ifft
from math import pi
from pyquil.quil import Program
import pyquil.api as api
from pyquil.api import QVMConnection
from pyquil.gates import *
def exampleQft3(q0, q1, q2):
p = Program()
p.inst( H(q2),
CPHASE(pi/2.0, q1, q2),
H(q1),
CPHASE(pi/4.0, q0, q2),
CPHASE(pi/2.0, q0, q1),
H(q0),
SWAP(q0, q2) ) # SWAP is necessary because the QTF swaps the qubits
return p
if __name__ == "__main__":
print('hi there, we will qtf [0, 1, 0, 0, 0, 0, 0, 0] \n')
qvm = QVMConnection()
state_prep = Program().inst(X(0), I(1), I(2))
# wavefunction = qvm.wavefunction(state_prep)
# print(wavefunction)
wavefunction = qvm.wavefunction(state_prep + exampleQft3(0, 1, 2))
print(wavefunction.amplitudes)
ifft([0, 1, 0, 0, 0, 0, 0, 0], norm="ortho")