-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathqa_simple_qft.py
More file actions
38 lines (27 loc) · 1.01 KB
/
qa_simple_qft.py
File metadata and controls
38 lines (27 loc) · 1.01 KB
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
37
38
#==============================================================================
# DFT
#==============================================================================
import numpy as np
x = np.array([0.5, 0.5, 0.5, 0.5])
y = np.fft.fft(x, norm='ortho')
print(y)
x = np.fft.ifft(y, norm='ortho')
print(x)
#==============================================================================
# QFT
#==============================================================================
import math
from pyquil import Program
from pyquil.gates import SWAP, H, CPHASE
from pyquil.api import WavefunctionSimulator
# Initilize program
prog = Program()
# Prepare state
prog = prog.inst(H(0),H(1))
print('Amplitudes a of input state psi: {}'.format(WavefunctionSimulator().wavefunction(prog).amplitudes))
# Perfrom QFT
prog += SWAP(0, 1)
prog += H(1)
prog += CPHASE(math.pi / 2, 0, 1)
prog += H(0)
print('Amplitudes b of output state phi: {}'.format(WavefunctionSimulator().wavefunction(prog).amplitudes))