-
Notifications
You must be signed in to change notification settings - Fork 0
/
gates.py
79 lines (57 loc) · 2.06 KB
/
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
import qiskit
import os
class Gate:
def __init__(self, type):
self._type = type
def get_type(self):
return self._type
def __repr__(self):
return f"{self.get_type()} Gate"
class OneQubitGate(Gate):
def __init__(self, type, target):
self._target = target
Gate.__init__(self, type)
def get_target(self):
return self._target
def __repr__(self):
return f"{self.get_type()} Gate, Target = {self.get_target()}"
class TwoQubitGate(Gate):
def __init__(self, type, control, target):
self._target = target
self._control = control
Gate.__init__(self, type)
def get_target(self):
return self._target
def get_control(self):
return self._control
def __repr__(self):
return f"{self.get_type()} Gate, Control = {self.get_control()} Target = {self.get_target()}"
class ThreeQubitGate(Gate):
def __init__(self, type, control, target):
self._target = target
self._control = control
Gate.__init__(self, type)
def get_target(self):
return self._target
def get_control(self):
return self._control
def __repr__(self):
return f"{self.get_type()} Gate, Control = {self.get_control()} Target = {self.get_target()}"
class MeasureGate(Gate):
def __init__(self):
Gate.__init__(self, "Measure")
class HadamardGate(OneQubitGate):
def __init__(self, target):
OneQubitGate.__init__(self, "Hadamard", target)
class XGate(OneQubitGate):
def __init__(self, target):
OneQubitGate.__init__(self, "X", target)
class CNOTGate(TwoQubitGate):
def __init__(self, control, target):
TwoQubitGate.__init__(self, "X", control, target)
class ToffoliGate(ThreeQubitGate):
def __init__(self, control, target):
ThreeQubitGate.__init__(self, "Toffoli", control, target)
class SWAPGate(TwoQubitGate):
def __init__(self, target):
TwoQubitGate.__init__(self, "SWAP", None, target)