1919import numpy as np
2020import pytest
2121from cirq_ft .infra import bit_tools
22+ from cirq_ft .deprecation import allow_deprecated_cirq_ft_use_in_tests
2223
2324
2425def identity_map (n : int ):
2526 """Returns a dict of size `2**n` mapping each integer in range [0, 2**n) to itself."""
2627 return {i : i for i in range (2 ** n )}
2728
2829
30+ @allow_deprecated_cirq_ft_use_in_tests
2931def test_less_than_gate ():
3032 qubits = cirq .LineQubit .range (4 )
3133 gate = cirq_ft .LessThanGate (3 , 5 )
@@ -61,6 +63,7 @@ def test_less_than_gate():
6163
6264@pytest .mark .parametrize ("bits" , [* range (8 )])
6365@pytest .mark .parametrize ("val" , [3 , 5 , 7 , 8 , 9 ])
66+ @allow_deprecated_cirq_ft_use_in_tests
6467def test_decompose_less_than_gate (bits : int , val : int ):
6568 qubit_states = list (bit_tools .iter_bits (bits , 3 ))
6669 circuit = cirq .Circuit (
@@ -81,6 +84,7 @@ def test_decompose_less_than_gate(bits: int, val: int):
8184
8285@pytest .mark .parametrize ("n" , [* range (2 , 5 )])
8386@pytest .mark .parametrize ("val" , [3 , 4 , 5 , 7 , 8 , 9 ])
87+ @allow_deprecated_cirq_ft_use_in_tests
8488def test_less_than_consistent_protocols (n : int , val : int ):
8589 g = cirq_ft .LessThanGate (n , val )
8690 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):
9094 np .testing .assert_allclose (u @ u , np .eye (2 ** (n + 1 )))
9195
9296
97+ @allow_deprecated_cirq_ft_use_in_tests
9398def test_multi_in_less_equal_than_gate ():
9499 qubits = cirq .LineQubit .range (7 )
95100 op = cirq_ft .LessThanEqualGate (3 , 3 ).on (* qubits )
@@ -114,6 +119,7 @@ def test_multi_in_less_equal_than_gate():
114119
115120@pytest .mark .parametrize ("x_bitsize" , [* range (1 , 5 )])
116121@pytest .mark .parametrize ("y_bitsize" , [* range (1 , 5 )])
122+ @allow_deprecated_cirq_ft_use_in_tests
117123def test_less_than_equal_consistent_protocols (x_bitsize : int , y_bitsize : int ):
118124 g = cirq_ft .LessThanEqualGate (x_bitsize , y_bitsize )
119125 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):
138144 assert g .with_registers ([2 ] * 4 , [2 ] * 5 , [2 ]) == cirq_ft .LessThanEqualGate (4 , 5 )
139145
140146
147+ @allow_deprecated_cirq_ft_use_in_tests
141148def test_contiguous_register_gate ():
142149 gate = cirq_ft .ContiguousRegisterGate (3 , 6 )
143150 circuit = cirq .Circuit (gate .on (* cirq .LineQubit .range (12 )))
@@ -163,13 +170,15 @@ def test_contiguous_register_gate():
163170
164171
165172@pytest .mark .parametrize ('n' , [* range (1 , 10 )])
173+ @allow_deprecated_cirq_ft_use_in_tests
166174def test_contiguous_register_gate_t_complexity (n ):
167175 gate = cirq_ft .ContiguousRegisterGate (n , 2 * n )
168176 toffoli_complexity = cirq_ft .t_complexity (cirq .CCNOT )
169177 assert cirq_ft .t_complexity (gate ) == (n ** 2 + n - 1 ) * toffoli_complexity
170178
171179
172180@pytest .mark .parametrize ('a,b,num_bits' , itertools .product (range (4 ), range (4 ), range (3 , 5 )))
181+ @allow_deprecated_cirq_ft_use_in_tests
173182def test_add (a : int , b : int , num_bits : int ):
174183 num_anc = num_bits - 1
175184 gate = cirq_ft .AdditionGate (num_bits )
@@ -199,6 +208,7 @@ def test_add(a: int, b: int, num_bits: int):
199208@pytest .mark .parametrize ('mod' , [5 , 8 ])
200209@pytest .mark .parametrize ('add_val' , [1 , 2 ])
201210@pytest .mark .parametrize ('cv' , [[], [0 , 1 ], [1 , 0 ], [1 , 1 ]])
211+ @allow_deprecated_cirq_ft_use_in_tests
202212def test_add_mod_n (bitsize , mod , add_val , cv ):
203213 gate = cirq_ft .AddMod (bitsize , mod , add_val = add_val , cv = cv )
204214 basis_map = {}
@@ -225,6 +235,7 @@ def test_add_mod_n(bitsize, mod, add_val, cv):
225235 cirq .testing .assert_equivalent_repr (gate , setup_code = 'import cirq_ft' )
226236
227237
238+ @allow_deprecated_cirq_ft_use_in_tests
228239def test_add_mod_n_protocols ():
229240 with pytest .raises (ValueError , match = "must be between" ):
230241 _ = cirq_ft .AddMod (3 , 10 )
@@ -238,6 +249,7 @@ def test_add_mod_n_protocols():
238249 assert cirq .circuit_diagram_info (add_two ).wire_symbols == ('@' , '@(0)' ) + ('Add_2_Mod_5' ,) * 3
239250
240251
252+ @allow_deprecated_cirq_ft_use_in_tests
241253def test_add_truncated ():
242254 num_bits = 3
243255 num_anc = num_bits - 1
@@ -286,6 +298,7 @@ def test_add_truncated():
286298
287299
288300@pytest .mark .parametrize ('a,b,num_bits' , itertools .product (range (4 ), range (4 ), range (3 , 5 )))
301+ @allow_deprecated_cirq_ft_use_in_tests
289302def test_subtract (a , b , num_bits ):
290303 num_anc = num_bits - 1
291304 gate = cirq_ft .AdditionGate (num_bits )
@@ -309,13 +322,15 @@ def test_subtract(a, b, num_bits):
309322
310323
311324@pytest .mark .parametrize ("n" , [* range (3 , 10 )])
325+ @allow_deprecated_cirq_ft_use_in_tests
312326def test_addition_gate_t_complexity (n : int ):
313327 g = cirq_ft .AdditionGate (n )
314328 cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
315329 cirq .testing .assert_equivalent_repr (g , setup_code = 'import cirq_ft' )
316330
317331
318332@pytest .mark .parametrize ('a,b' , itertools .product (range (2 ** 3 ), repeat = 2 ))
333+ @allow_deprecated_cirq_ft_use_in_tests
319334def test_add_no_decompose (a , b ):
320335 num_bits = 5
321336 qubits = cirq .LineQubit .range (2 * num_bits )
@@ -335,6 +350,7 @@ def test_add_no_decompose(a, b):
335350
336351@pytest .mark .parametrize ("P,n" , [(v , n ) for n in range (1 , 4 ) for v in range (1 << n )])
337352@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
338354def test_decompose_less_than_equal_gate (P : int , n : int , Q : int , m : int ):
339355 qubit_states = list (bit_tools .iter_bits (P , n )) + list (bit_tools .iter_bits (Q , m ))
340356 circuit = cirq .Circuit (
@@ -353,6 +369,7 @@ def test_decompose_less_than_equal_gate(P: int, n: int, Q: int, m: int):
353369
354370
355371@pytest .mark .parametrize ("adjoint" , [False , True ])
372+ @allow_deprecated_cirq_ft_use_in_tests
356373def test_single_qubit_compare_protocols (adjoint : bool ):
357374 g = cirq_ft .algos .SingleQubitCompare (adjoint = adjoint )
358375 cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -370,6 +387,7 @@ def test_single_qubit_compare_protocols(adjoint: bool):
370387
371388
372389@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
373391def test_single_qubit_compare (v1 : int , v2 : int ):
374392 g = cirq_ft .algos .SingleQubitCompare ()
375393 qubits = cirq .LineQid .range (4 , dimension = 2 )
@@ -388,6 +406,7 @@ def test_single_qubit_compare(v1: int, v2: int):
388406
389407
390408@pytest .mark .parametrize ("adjoint" , [False , True ])
409+ @allow_deprecated_cirq_ft_use_in_tests
391410def test_bi_qubits_mixer_protocols (adjoint : bool ):
392411 g = cirq_ft .algos .BiQubitsMixer (adjoint = adjoint )
393412 cirq_ft .testing .assert_decompose_is_consistent_with_t_complexity (g )
@@ -399,6 +418,7 @@ def test_bi_qubits_mixer_protocols(adjoint: bool):
399418
400419@pytest .mark .parametrize ("x" , [* range (4 )])
401420@pytest .mark .parametrize ("y" , [* range (4 )])
421+ @allow_deprecated_cirq_ft_use_in_tests
402422def test_bi_qubits_mixer (x : int , y : int ):
403423 g = cirq_ft .algos .BiQubitsMixer ()
404424 qubits = cirq .LineQid .range (7 , dimension = 2 )
0 commit comments