@@ -132,7 +132,7 @@ def density_is_close(mat1: np.ndarray, mat2: np.ndarray):
132
132
133
133
134
134
135
- class single_qubit (TestCase ):
135
+ class single_qubit_test (TestCase ):
136
136
def compare_single_gate (self , gate_pair , qubit_num ):
137
137
passed = True
138
138
for index in range (0 , qubit_num ):
@@ -157,7 +157,7 @@ def test_single_gates(self):
157
157
158
158
159
159
160
- class Two_qubit (TestCase ):
160
+ class two_qubit_test (TestCase ):
161
161
def compare_two_qubit_gate (self , gate_pair , qubit_num ):
162
162
passed = True
163
163
for index1 in range (0 , qubit_num ):
@@ -184,5 +184,34 @@ def test_two_qubits_gates(self):
184
184
self .assertTrue (self .compare_two_qubit_gate (two_qubit_gate_list [i ], 5 ))
185
185
186
186
187
+ class three_qubit_test (TestCase ):
188
+ def compare_three_qubit_gate (self , gate_pair , qubit_num ):
189
+ passed = True
190
+ for index1 in range (0 , qubit_num ):
191
+ for index2 in range (0 , qubit_num ):
192
+ if (index1 == index2 ):
193
+ continue
194
+ for index3 in range (0 , qubit_num ):
195
+ if (index3 == index1 ) or (index3 == index2 ):
196
+ continue
197
+ qdev = tq .NoiseDevice (n_wires = qubit_num , bsz = 1 , device = "cpu" , record_op = True )
198
+ gate_pair ['tq' ](qdev , [index1 ,index2 ,index3 ])
199
+ mat1 = np .array (qdev .get_2d_matrix (0 ))
200
+ rho_qiskit = qiskitDensity .from_label ('0' * qubit_num )
201
+ rho_qiskit = rho_qiskit .evolve (gate_pair ['qiskit' ](), [qubit_num - 1 - index1 ,qubit_num - 1 - index2 ,qubit_num - 1 - index3 ])
202
+ mat2 = np .array (rho_qiskit .to_operator ())
203
+ if density_is_close (mat1 , mat2 ):
204
+ print ("Test passed for %s gate on qubit (%d,%d,%d) when qubit_number is %d!" % (
205
+ gate_pair ['name' ], index1 ,index2 ,index3 , qubit_num ))
206
+ else :
207
+ passed = False
208
+ print ("Test failed for %s gate on qubit (%d,%d,%d) when qubit_number is %d!" % (
209
+ gate_pair ['name' ], index1 ,index2 ,index3 ,qubit_num ))
210
+ return passed
211
+
212
+ def test_three_qubits_gates (self ):
213
+ for i in range (0 , len (three_qubit_gate_list )):
214
+ self .assertTrue (self .compare_three_qubit_gate (three_qubit_gate_list [i ], 5 ))
215
+
187
216
188
217
0 commit comments