Skip to content

Commit 91cc5b5

Browse files
committed
feat(platforms): new gates for quantum circuits
1 parent 1d62ea2 commit 91cc5b5

File tree

4 files changed

+287
-12
lines changed

4 files changed

+287
-12
lines changed

qrand/platforms/circuit.py

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## _____ _____
22
## | __ \| __ \ AUTHOR: Pedro Rivero
33
## | |__) | |__) | ---------------------------------
4-
## | ___/| _ / DATE: April 5, 2021
4+
## | ___/| _ / DATE: May 18, 2021
55
## | | | | \ \ ---------------------------------
66
## |_| |_| \_\ https://github.com/pedrorrivero
77
##
@@ -36,14 +36,114 @@ def __init__(self, num_qubits: int) -> None:
3636
def num_qubits(self) -> int:
3737
pass
3838

39+
############################## SPECIAL GATES ##############################
40+
@abstractmethod
41+
def measure(self, target_qubit: int) -> None:
42+
pass
43+
44+
########################### SINGLE QUBIT GATES ###########################
3945
@abstractmethod
4046
def h(self, target_qubit: int) -> None:
4147
pass
4248

49+
@abstractmethod
50+
def rx(self, radians: float, target_qubit: int) -> None:
51+
pass
52+
53+
@abstractmethod
54+
def ry(self, radians: float, target_qubit: int) -> None:
55+
pass
56+
57+
@abstractmethod
58+
def rz(self, radians: float, target_qubit: int) -> None:
59+
pass
60+
61+
@abstractmethod
62+
def s(self, target_qubit: int) -> None:
63+
pass
64+
65+
@abstractmethod
66+
def t(self, target_qubit: int) -> None:
67+
pass
68+
69+
@abstractmethod
70+
def u1(self, theta: float, target_qubit: int) -> None:
71+
pass
72+
73+
@abstractmethod
74+
def u2(self, phi: float, lam: float, target_qubit: int) -> None:
75+
pass
76+
77+
@abstractmethod
78+
def u3(
79+
self, theta: float, phi: float, lam: float, target_qubit: int
80+
) -> None:
81+
pass
82+
83+
@abstractmethod
84+
def x(self, target_qubit: int) -> None:
85+
pass
86+
87+
@abstractmethod
88+
def y(self, target_qubit: int) -> None:
89+
pass
90+
91+
@abstractmethod
92+
def z(self, target_qubit: int) -> None:
93+
pass
94+
95+
############################# TWO QUBIT GATES #############################
96+
@abstractmethod
97+
def cs(self, control_qubit: int, target_qubit: int) -> None:
98+
pass
99+
43100
@abstractmethod
44101
def cx(self, control_qubit: int, target_qubit: int) -> None:
45102
pass
46103

47104
@abstractmethod
48-
def measure(self, target_qubit: int) -> None:
105+
def cz(self, control_qubit: int, target_qubit: int) -> None:
106+
pass
107+
108+
@abstractmethod
109+
def swap(self, target_qubit_1: int, target_qubit_2: int) -> None:
110+
pass
111+
112+
############################ THREE QUBIT GATES ############################
113+
@abstractmethod
114+
def ccx(
115+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
116+
) -> None:
117+
pass
118+
119+
@abstractmethod
120+
def cswap(
121+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
122+
) -> None:
49123
pass
124+
125+
############################## ALIAS GATES ##############################
126+
def cnot(self, control_qubit: int, target_qubit: int) -> None:
127+
self.cx(control_qubit, target_qubit)
128+
129+
def cphase(self, control_qubit: int, target_qubit: int) -> None:
130+
self.cs(control_qubit, target_qubit)
131+
132+
def fredkin(
133+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
134+
) -> None:
135+
self.cswap(control_qubit_1, control_qubit_2, target_qubit)
136+
137+
def hadamard(self, target_qubit: int) -> None:
138+
self.h(target_qubit)
139+
140+
def phase(self, target_qubit: int) -> None:
141+
self.s(target_qubit)
142+
143+
def pi8(self, target_qubit: int) -> None:
144+
self.t(target_qubit)
145+
146+
def toffoli(
147+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
148+
) -> None:
149+
self.ccx(control_qubit_1, control_qubit_2, target_qubit)

qrand/platforms/cirq/circuit.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## _____ _____
22
## | __ \| __ \ AUTHOR: Pedro Rivero
33
## | |__) | |__) | ---------------------------------
4-
## | ___/| _ / DATE: April 20, 2021
4+
## | ___/| _ / DATE: May 18, 2021
55
## | | | | \ \ ---------------------------------
66
## |_| |_| \_\ https://github.com/pedrorrivero
77
##
@@ -31,16 +31,73 @@ def __init__(self, num_qubits: int) -> None:
3131
self.ERROR_MSG = f"{self.__class__.__name__}" # TODO
3232
raise NotImplementedError(self.ERROR_MSG)
3333

34-
############################### PUBLIC API ###############################
3534
@property
3635
def num_qubits(self) -> int:
3736
raise NotImplementedError(self.ERROR_MSG)
3837

38+
############################## SPECIAL GATES ##############################
39+
def measure(self, target_qubit: int) -> None:
40+
raise NotImplementedError(self.ERROR_MSG)
41+
42+
########################### SINGLE QUBIT GATES ###########################
3943
def h(self, target_qubit: int) -> None:
4044
raise NotImplementedError(self.ERROR_MSG)
4145

46+
def rx(self, radians: float, target_qubit: int) -> None:
47+
raise NotImplementedError(self.ERROR_MSG)
48+
49+
def ry(self, radians: float, target_qubit: int) -> None:
50+
raise NotImplementedError(self.ERROR_MSG)
51+
52+
def rz(self, radians: float, target_qubit: int) -> None:
53+
raise NotImplementedError(self.ERROR_MSG)
54+
55+
def s(self, target_qubit: int) -> None:
56+
raise NotImplementedError(self.ERROR_MSG)
57+
58+
def t(self, target_qubit: int) -> None:
59+
raise NotImplementedError(self.ERROR_MSG)
60+
61+
def u1(self, theta: float, target_qubit: int) -> None:
62+
raise NotImplementedError(self.ERROR_MSG)
63+
64+
def u2(self, phi: float, lam: float, target_qubit: int) -> None:
65+
raise NotImplementedError(self.ERROR_MSG)
66+
67+
def u3(
68+
self, theta: float, phi: float, lam: float, target_qubit: int
69+
) -> None:
70+
raise NotImplementedError(self.ERROR_MSG)
71+
72+
def x(self, target_qubit: int) -> None:
73+
raise NotImplementedError(self.ERROR_MSG)
74+
75+
def y(self, target_qubit: int) -> None:
76+
raise NotImplementedError(self.ERROR_MSG)
77+
78+
def z(self, target_qubit: int) -> None:
79+
raise NotImplementedError(self.ERROR_MSG)
80+
81+
############################# TWO QUBIT GATES #############################
82+
def cs(self, control_qubit: int, target_qubit: int) -> None:
83+
raise NotImplementedError(self.ERROR_MSG)
84+
4285
def cx(self, control_qubit: int, target_qubit: int) -> None:
4386
raise NotImplementedError(self.ERROR_MSG)
4487

45-
def measure(self, target_qubit: int) -> None:
88+
def cz(self, control_qubit: int, target_qubit: int) -> None:
89+
raise NotImplementedError(self.ERROR_MSG)
90+
91+
def swap(self, target_qubit_1: int, target_qubit_2: int) -> None:
92+
raise NotImplementedError(self.ERROR_MSG)
93+
94+
############################ THREE QUBIT GATES ############################
95+
def ccx(
96+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
97+
) -> None:
98+
raise NotImplementedError(self.ERROR_MSG)
99+
100+
def cswap(
101+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
102+
) -> None:
46103
raise NotImplementedError(self.ERROR_MSG)

qrand/platforms/qiskit/circuit.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## _____ _____
22
## | __ \| __ \ AUTHOR: Pedro Rivero
33
## | |__) | |__) | ---------------------------------
4-
## | ___/| _ / DATE: April 20, 2021
4+
## | ___/| _ / DATE: May 18, 2021
55
## | | | | \ \ ---------------------------------
66
## |_| |_| \_\ https://github.com/pedrorrivero
77
##
@@ -32,16 +32,77 @@ class QiskitCircuit(QuantumCircuit, QiskitQuantumCircuit):
3232
def __init__(self, num_qubits: int) -> None:
3333
super(QuantumCircuit, self).__init__(num_qubits, num_qubits)
3434

35-
############################### PUBLIC API ###############################
3635
@property
3736
def num_qubits(self) -> int:
3837
return super(QuantumCircuit, self).num_qubits
3938

39+
############################## SPECIAL GATES ##############################
40+
def measure(self, target_qubit: int) -> None:
41+
super(QuantumCircuit, self).measure(target_qubit, target_qubit)
42+
43+
########################### SINGLE QUBIT GATES ###########################
4044
def h(self, target_qubit: int) -> None:
4145
super(QuantumCircuit, self).h(target_qubit)
4246

47+
def rx(self, radians: float, target_qubit: int) -> None:
48+
super(QuantumCircuit, self).rx(radians, target_qubit)
49+
50+
def ry(self, radians: float, target_qubit: int) -> None:
51+
super(QuantumCircuit, self).ry(radians, target_qubit)
52+
53+
def rz(self, radians: float, target_qubit: int) -> None:
54+
super(QuantumCircuit, self).rz(radians, target_qubit)
55+
56+
def s(self, target_qubit: int) -> None:
57+
super(QuantumCircuit, self).s(target_qubit)
58+
59+
def t(self, target_qubit: int) -> None:
60+
super(QuantumCircuit, self).t(target_qubit)
61+
62+
def u1(self, theta: float, target_qubit: int) -> None:
63+
super(QuantumCircuit, self).u1(theta, target_qubit)
64+
65+
def u2(self, phi: float, lam: float, target_qubit: int) -> None:
66+
super(QuantumCircuit, self).u2(phi, lam, target_qubit)
67+
68+
def u3(
69+
self, theta: float, phi: float, lam: float, target_qubit: int
70+
) -> None:
71+
super(QuantumCircuit, self).u3(theta, phi, lam, target_qubit)
72+
73+
def x(self, target_qubit: int) -> None:
74+
super(QuantumCircuit, self).x(target_qubit)
75+
76+
def y(self, target_qubit: int) -> None:
77+
super(QuantumCircuit, self).y(target_qubit)
78+
79+
def z(self, target_qubit: int) -> None:
80+
super(QuantumCircuit, self).z(target_qubit)
81+
82+
############################# TWO QUBIT GATES #############################
83+
def cs(self, control_qubit: int, target_qubit: int) -> None:
84+
super(QuantumCircuit, self).cs(control_qubit, target_qubit)
85+
4386
def cx(self, control_qubit: int, target_qubit: int) -> None:
4487
super(QuantumCircuit, self).cx(control_qubit, target_qubit)
4588

46-
def measure(self, target_qubit: int) -> None:
47-
super(QuantumCircuit, self).measure(target_qubit, target_qubit)
89+
def cz(self, control_qubit: int, target_qubit: int) -> None:
90+
super(QuantumCircuit, self).cz(control_qubit, target_qubit)
91+
92+
def swap(self, target_qubit_1: int, target_qubit_2: int) -> None:
93+
super(QuantumCircuit, self).swap(target_qubit_1, target_qubit_2)
94+
95+
############################ THREE QUBIT GATES ############################
96+
def ccx(
97+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
98+
) -> None:
99+
super(QuantumCircuit, self).ccx(
100+
control_qubit_1, control_qubit_2, target_qubit
101+
)
102+
103+
def cswap(
104+
self, control_qubit: int, target_qubit_1: int, target_qubit_2: int
105+
) -> None:
106+
super(QuantumCircuit, self).cswap(
107+
control_qubit, target_qubit_1, target_qubit_2
108+
)

qrand/platforms/qsharp/circuit.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## _____ _____
22
## | __ \| __ \ AUTHOR: Pedro Rivero
33
## | |__) | |__) | ---------------------------------
4-
## | ___/| _ / DATE: April 20, 2021
4+
## | ___/| _ / DATE: May 18, 2021
55
## | | | | \ \ ---------------------------------
66
## |_| |_| \_\ https://github.com/pedrorrivero
77
##
@@ -31,16 +31,73 @@ def __init__(self, num_qubits: int) -> None:
3131
self.ERROR_MSG = f"{self.__class__.__name__}" # TODO
3232
raise NotImplementedError(self.ERROR_MSG)
3333

34-
############################### PUBLIC API ###############################
3534
@property
3635
def num_qubits(self) -> int:
3736
raise NotImplementedError(self.ERROR_MSG)
3837

38+
############################## SPECIAL GATES ##############################
39+
def measure(self, target_qubit: int) -> None:
40+
raise NotImplementedError(self.ERROR_MSG)
41+
42+
########################### SINGLE QUBIT GATES ###########################
3943
def h(self, target_qubit: int) -> None:
4044
raise NotImplementedError(self.ERROR_MSG)
4145

46+
def rx(self, radians: float, target_qubit: int) -> None:
47+
raise NotImplementedError(self.ERROR_MSG)
48+
49+
def ry(self, radians: float, target_qubit: int) -> None:
50+
raise NotImplementedError(self.ERROR_MSG)
51+
52+
def rz(self, radians: float, target_qubit: int) -> None:
53+
raise NotImplementedError(self.ERROR_MSG)
54+
55+
def s(self, target_qubit: int) -> None:
56+
raise NotImplementedError(self.ERROR_MSG)
57+
58+
def t(self, target_qubit: int) -> None:
59+
raise NotImplementedError(self.ERROR_MSG)
60+
61+
def u1(self, theta: float, target_qubit: int) -> None:
62+
raise NotImplementedError(self.ERROR_MSG)
63+
64+
def u2(self, phi: float, lam: float, target_qubit: int) -> None:
65+
raise NotImplementedError(self.ERROR_MSG)
66+
67+
def u3(
68+
self, theta: float, phi: float, lam: float, target_qubit: int
69+
) -> None:
70+
raise NotImplementedError(self.ERROR_MSG)
71+
72+
def x(self, target_qubit: int) -> None:
73+
raise NotImplementedError(self.ERROR_MSG)
74+
75+
def y(self, target_qubit: int) -> None:
76+
raise NotImplementedError(self.ERROR_MSG)
77+
78+
def z(self, target_qubit: int) -> None:
79+
raise NotImplementedError(self.ERROR_MSG)
80+
81+
############################# TWO QUBIT GATES #############################
82+
def cs(self, control_qubit: int, target_qubit: int) -> None:
83+
raise NotImplementedError(self.ERROR_MSG)
84+
4285
def cx(self, control_qubit: int, target_qubit: int) -> None:
4386
raise NotImplementedError(self.ERROR_MSG)
4487

45-
def measure(self, target_qubit: int) -> None:
88+
def cz(self, control_qubit: int, target_qubit: int) -> None:
89+
raise NotImplementedError(self.ERROR_MSG)
90+
91+
def swap(self, target_qubit_1: int, target_qubit_2: int) -> None:
92+
raise NotImplementedError(self.ERROR_MSG)
93+
94+
############################ THREE QUBIT GATES ############################
95+
def ccx(
96+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
97+
) -> None:
98+
raise NotImplementedError(self.ERROR_MSG)
99+
100+
def cswap(
101+
self, control_qubit_1: int, control_qubit_2: int, target_qubit: int
102+
) -> None:
46103
raise NotImplementedError(self.ERROR_MSG)

0 commit comments

Comments
 (0)