-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhadamard_gate_3.py
52 lines (43 loc) · 2 KB
/
hadamard_gate_3.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from numpy import *
from measure_state import generate_state_count
def hadamard_gate_1(state_in):
H1 = (1 / sqrt(2)) * array([[1, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, -1, 0, 0, 0],
[0, 1, 0, 0, 0, -1, 0, 0],
[0, 0, 1, 0, 0, 0, -1, 0],
[0, 0, 0, 1, 0, 0, 0, -1]])
final_state = dot(H1, state_in)
return final_state
def hadamard_gate_2(state_in):
H2 = (1 / sqrt(2)) * array([[1, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0],
[1, 0, -1, 0, 0, 0, 0, 0],
[0, 1, 0, -1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 1, 0, -1, 0],
[0, 0, 0, 0, 0, 1, 0, -1]])
final_state = dot(H2, state_in)
return final_state
def hadamard_gate_3(state_in):
H3 = (1 / sqrt(2)) * array([[1, 1, 0, 0, 0, 0, 0, 0],
[1, -1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 1, -1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 1, -1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 1, -1]])
final_state = dot(H3, state_in)
return final_state
def driver():
state_1 = hadamard_gate_1([0, 0, 0, 0, 1, 0, 0, 0])
state_2 = hadamard_gate_2(state_1)
state_3 = hadamard_gate_3(state_2)
print(generate_state_count(state_1, 1000, True))
print(generate_state_count(state_3, 1000, True))
if __name__ == '__main__':
driver()