19
19
import numpy as np
20
20
import pytest
21
21
from cirq_ft .infra import bit_tools
22
+ from cirq_ft .deprecation import allow_deprecated_cirq_ft_use_in_tests
22
23
23
24
24
25
def identity_map (n : int ):
25
26
"""Returns a dict of size `2**n` mapping each integer in range [0, 2**n) to itself."""
26
27
return {i : i for i in range (2 ** n )}
27
28
28
29
30
+ @allow_deprecated_cirq_ft_use_in_tests
29
31
def test_less_than_gate ():
30
32
qubits = cirq .LineQubit .range (4 )
31
33
gate = cirq_ft .LessThanGate (3 , 5 )
@@ -61,6 +63,7 @@ def test_less_than_gate():
61
63
62
64
@pytest .mark .parametrize ("bits" , [* range (8 )])
63
65
@pytest .mark .parametrize ("val" , [3 , 5 , 7 , 8 , 9 ])
66
+ @allow_deprecated_cirq_ft_use_in_tests
64
67
def test_decompose_less_than_gate (bits : int , val : int ):
65
68
qubit_states = list (bit_tools .iter_bits (bits , 3 ))
66
69
circuit = cirq .Circuit (
@@ -81,6 +84,7 @@ def test_decompose_less_than_gate(bits: int, val: int):
81
84
82
85
@pytest .mark .parametrize ("n" , [* range (2 , 5 )])
83
86
@pytest .mark .parametrize ("val" , [3 , 4 , 5 , 7 , 8 , 9 ])
87
+ @allow_deprecated_cirq_ft_use_in_tests
84
88
def test_less_than_consistent_protocols (n : int , val : int ):
85
89
g = cirq_ft .LessThanGate (n , val )
86
90
cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -90,6 +94,7 @@ def test_less_than_consistent_protocols(n: int, val: int):
90
94
np .testing .assert_allclose (u @ u , np .eye (2 ** (n + 1 )))
91
95
92
96
97
+ @allow_deprecated_cirq_ft_use_in_tests
93
98
def test_multi_in_less_equal_than_gate ():
94
99
qubits = cirq .LineQubit .range (7 )
95
100
op = cirq_ft .LessThanEqualGate (3 , 3 ).on (* qubits )
@@ -114,6 +119,7 @@ def test_multi_in_less_equal_than_gate():
114
119
115
120
@pytest .mark .parametrize ("x_bitsize" , [* range (1 , 5 )])
116
121
@pytest .mark .parametrize ("y_bitsize" , [* range (1 , 5 )])
122
+ @allow_deprecated_cirq_ft_use_in_tests
117
123
def test_less_than_equal_consistent_protocols (x_bitsize : int , y_bitsize : int ):
118
124
g = cirq_ft .LessThanEqualGate (x_bitsize , y_bitsize )
119
125
cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -138,6 +144,7 @@ def test_less_than_equal_consistent_protocols(x_bitsize: int, y_bitsize: int):
138
144
assert g .with_registers ([2 ] * 4 , [2 ] * 5 , [2 ]) == cirq_ft .LessThanEqualGate (4 , 5 )
139
145
140
146
147
+ @allow_deprecated_cirq_ft_use_in_tests
141
148
def test_contiguous_register_gate ():
142
149
gate = cirq_ft .ContiguousRegisterGate (3 , 6 )
143
150
circuit = cirq .Circuit (gate .on (* cirq .LineQubit .range (12 )))
@@ -163,13 +170,15 @@ def test_contiguous_register_gate():
163
170
164
171
165
172
@pytest .mark .parametrize ('n' , [* range (1 , 10 )])
173
+ @allow_deprecated_cirq_ft_use_in_tests
166
174
def test_contiguous_register_gate_t_complexity (n ):
167
175
gate = cirq_ft .ContiguousRegisterGate (n , 2 * n )
168
176
toffoli_complexity = cirq_ft .t_complexity (cirq .CCNOT )
169
177
assert cirq_ft .t_complexity (gate ) == (n ** 2 + n - 1 ) * toffoli_complexity
170
178
171
179
172
180
@pytest .mark .parametrize ('a,b,num_bits' , itertools .product (range (4 ), range (4 ), range (3 , 5 )))
181
+ @allow_deprecated_cirq_ft_use_in_tests
173
182
def test_add (a : int , b : int , num_bits : int ):
174
183
num_anc = num_bits - 1
175
184
gate = cirq_ft .AdditionGate (num_bits )
@@ -199,6 +208,7 @@ def test_add(a: int, b: int, num_bits: int):
199
208
@pytest .mark .parametrize ('mod' , [5 , 8 ])
200
209
@pytest .mark .parametrize ('add_val' , [1 , 2 ])
201
210
@pytest .mark .parametrize ('cv' , [[], [0 , 1 ], [1 , 0 ], [1 , 1 ]])
211
+ @allow_deprecated_cirq_ft_use_in_tests
202
212
def test_add_mod_n (bitsize , mod , add_val , cv ):
203
213
gate = cirq_ft .AddMod (bitsize , mod , add_val = add_val , cv = cv )
204
214
basis_map = {}
@@ -225,6 +235,7 @@ def test_add_mod_n(bitsize, mod, add_val, cv):
225
235
cirq .testing .assert_equivalent_repr (gate , setup_code = 'import cirq_ft' )
226
236
227
237
238
+ @allow_deprecated_cirq_ft_use_in_tests
228
239
def test_add_mod_n_protocols ():
229
240
with pytest .raises (ValueError , match = "must be between" ):
230
241
_ = cirq_ft .AddMod (3 , 10 )
@@ -238,6 +249,7 @@ def test_add_mod_n_protocols():
238
249
assert cirq .circuit_diagram_info (add_two ).wire_symbols == ('@' , '@(0)' ) + ('Add_2_Mod_5' ,) * 3
239
250
240
251
252
+ @allow_deprecated_cirq_ft_use_in_tests
241
253
def test_add_truncated ():
242
254
num_bits = 3
243
255
num_anc = num_bits - 1
@@ -286,6 +298,7 @@ def test_add_truncated():
286
298
287
299
288
300
@pytest .mark .parametrize ('a,b,num_bits' , itertools .product (range (4 ), range (4 ), range (3 , 5 )))
301
+ @allow_deprecated_cirq_ft_use_in_tests
289
302
def test_subtract (a , b , num_bits ):
290
303
num_anc = num_bits - 1
291
304
gate = cirq_ft .AdditionGate (num_bits )
@@ -309,13 +322,15 @@ def test_subtract(a, b, num_bits):
309
322
310
323
311
324
@pytest .mark .parametrize ("n" , [* range (3 , 10 )])
325
+ @allow_deprecated_cirq_ft_use_in_tests
312
326
def test_addition_gate_t_complexity (n : int ):
313
327
g = cirq_ft .AdditionGate (n )
314
328
cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
315
329
cirq .testing .assert_equivalent_repr (g , setup_code = 'import cirq_ft' )
316
330
317
331
318
332
@pytest .mark .parametrize ('a,b' , itertools .product (range (2 ** 3 ), repeat = 2 ))
333
+ @allow_deprecated_cirq_ft_use_in_tests
319
334
def test_add_no_decompose (a , b ):
320
335
num_bits = 5
321
336
qubits = cirq .LineQubit .range (2 * num_bits )
@@ -335,6 +350,7 @@ def test_add_no_decompose(a, b):
335
350
336
351
@pytest .mark .parametrize ("P,n" , [(v , n ) for n in range (1 , 4 ) for v in range (1 << n )])
337
352
@pytest .mark .parametrize ("Q,m" , [(v , n ) for n in range (1 , 4 ) for v in range (1 << n )])
353
+ @allow_deprecated_cirq_ft_use_in_tests
338
354
def test_decompose_less_than_equal_gate (P : int , n : int , Q : int , m : int ):
339
355
qubit_states = list (bit_tools .iter_bits (P , n )) + list (bit_tools .iter_bits (Q , m ))
340
356
circuit = cirq .Circuit (
@@ -353,6 +369,7 @@ def test_decompose_less_than_equal_gate(P: int, n: int, Q: int, m: int):
353
369
354
370
355
371
@pytest .mark .parametrize ("adjoint" , [False , True ])
372
+ @allow_deprecated_cirq_ft_use_in_tests
356
373
def test_single_qubit_compare_protocols (adjoint : bool ):
357
374
g = cirq_ft .algos .SingleQubitCompare (adjoint = adjoint )
358
375
cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -370,6 +387,7 @@ def test_single_qubit_compare_protocols(adjoint: bool):
370
387
371
388
372
389
@pytest .mark .parametrize ("v1,v2" , [(v1 , v2 ) for v1 in range (2 ) for v2 in range (2 )])
390
+ @allow_deprecated_cirq_ft_use_in_tests
373
391
def test_single_qubit_compare (v1 : int , v2 : int ):
374
392
g = cirq_ft .algos .SingleQubitCompare ()
375
393
qubits = cirq .LineQid .range (4 , dimension = 2 )
@@ -388,6 +406,7 @@ def test_single_qubit_compare(v1: int, v2: int):
388
406
389
407
390
408
@pytest .mark .parametrize ("adjoint" , [False , True ])
409
+ @allow_deprecated_cirq_ft_use_in_tests
391
410
def test_bi_qubits_mixer_protocols (adjoint : bool ):
392
411
g = cirq_ft .algos .BiQubitsMixer (adjoint = adjoint )
393
412
cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -399,6 +418,7 @@ def test_bi_qubits_mixer_protocols(adjoint: bool):
399
418
400
419
@pytest .mark .parametrize ("x" , [* range (4 )])
401
420
@pytest .mark .parametrize ("y" , [* range (4 )])
421
+ @allow_deprecated_cirq_ft_use_in_tests
402
422
def test_bi_qubits_mixer (x : int , y : int ):
403
423
g = cirq_ft .algos .BiQubitsMixer ()
404
424
qubits = cirq .LineQid .range (7 , dimension = 2 )
0 commit comments