-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhadamard_test.py
More file actions
46 lines (36 loc) · 912 Bytes
/
hadamard_test.py
File metadata and controls
46 lines (36 loc) · 912 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
37
38
39
40
41
42
43
44
45
46
from pyquil.quil import Program
#from pyquil.api import QPUConnection
from pyquil.api import QVMConnection
from pyquil.gates import *
#qpu = QPUConnection(device_name='19Q-Acorn')
qvm = QVMConnection()
def measurement_distribution(result):
num_zeros = 0
num_ones = 0
for x in result:
if x == [0]:
num_zeros += 1
else:
num_ones += 1
return [num_zeros, num_ones]
def get_Re(result):
dist = measurement_distribution(result)
return dist[0] - dist[1]
hadamard_test0 = Program(
X(0),
H(0),
CNOT(0, 1),
H(0),
)
print("Expected value will be closer to 0 than 100 or -100")
result = qvm.run_and_measure(hadamard_test0, [0], 100)
print(get_Re(result))
hadamard_test1 = Program(
H(1),
H(0),
CNOT(0, 1),
H(0),
)
print("Expected value will 1")
result = qvm.run_and_measure(hadamard_test1, [0], 1)
print(get_Re(result))