-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra_gates.py
99 lines (74 loc) · 2.31 KB
/
extra_gates.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import qsearch
from qsearch.gates import *
# from IBM
SQISW = np.array([[1,0,0,0],
[0,1/np.sqrt(2), 1j/np.sqrt(2),0],
[0,1j/np.sqrt(2),1/np.sqrt(2),0],
[0,0,0,1]],
dtype='complex128')
# CRZ = # from IBM
# SQISW = np.array([[1,0,0,0],
# [0,1/np.sqrt(2), 1j/np.sqrt(2),0],
# [0,1j/np.sqrt(2),1/np.sqrt(2),0],
# [0,0,0,1]],
# dtype='complex128')
# from IONQ
MS = np.array([[1,0,0,-1j],
[0,1,-1j,0],
[0,-1j,1,0],
[-1j,0,0,1]],
dtype='complex128') / np.sqrt(2)
class SQISWGate(Gate):
def __init__(self):
self.num_inputs = 0
self.qudits = 2
def __eq__(self, other):
return type(self) == type(other)
def matrix(self, v):
return SQISW
def assemble(self, v, i=0):
return [("gate", "SQISW", (), (i, i+1))]
def __repr__(self):
return "SQISWGate()"
class MSGate(Gate):
def __init__(self):
self.num_inputs = 0
self.qudits = 2
def __eq__(self, other):
return type(self) == type(other)
def matrix(self, v):
return MS
def assemble(self, v, i=0):
return [("gate", "MS", (), (i, i+1))]
def __repr__(self):
return "MSGate()"
class RXXGate(Gate):
def __init__(self):
self.d = 2
self.qudits = 2
self.num_inputs = 1
def assemble(self, v, i=0):
return [("gate", "XX", (v[0]), (i, i+1))]
def __repr__(self):
return "RXXGate()"
def __eq__(self, other):
return type(self) == type(other)
def matrix(self, v):
return native_from_object(self).matrix(np.array(v, dtype='float64'))
def mat_jac(self, v):
return native_from_object(self).mat_jac(v)
class CRZGate(Gate):
def __init__(self):
self.d = 2
self.qudits = 2
self.num_inputs = 1
def assemble(self, v, i=0):
return [("gate", "CRZ", (v[0]), (i, i+1))]
def __repr__(self):
return "CRZGate()"
def __eq__(self, other):
return type(self) == type(other)
def matrix(self, v):
return native_from_object(self).matrix(np.array(v, dtype='float64'))
def mat_jac(self, v):
return native_from_object(self).mat_jac(v)