@@ -33,8 +33,11 @@ def assert_optimizes(before: cirq.Circuit, expected: cirq.Circuit, **kwargs):
33
33
``MergeInteractionsToSqrtIswap`` constructor.
34
34
"""
35
35
actual = before .copy ()
36
- opt = cirq .MergeInteractionsToSqrtIswap (** kwargs )
37
- opt .optimize_circuit (actual )
36
+ with cirq .testing .assert_deprecated (
37
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
38
+ ):
39
+ opt = cirq .MergeInteractionsToSqrtIswap (** kwargs )
40
+ opt .optimize_circuit (actual )
38
41
39
42
# Ignore differences that would be caught by follow-up optimizations.
40
43
followup_transformers : List [cirq .TRANSFORMER ] = [
@@ -57,15 +60,23 @@ def assert_optimization_not_broken(circuit: cirq.Circuit, **kwargs):
57
60
circuit."""
58
61
u_before = circuit .unitary (sorted (circuit .all_qubits ()))
59
62
c_sqrt_iswap = circuit .copy ()
60
- cirq .MergeInteractionsToSqrtIswap (** kwargs ).optimize_circuit (c_sqrt_iswap )
63
+ with cirq .testing .assert_deprecated (
64
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
65
+ ):
66
+ cirq .MergeInteractionsToSqrtIswap (** kwargs ).optimize_circuit (c_sqrt_iswap )
61
67
u_after = c_sqrt_iswap .unitary (sorted (circuit .all_qubits ()))
62
68
63
69
# Not 1e-8 because of some unaccounted accumulated error in some of Cirq's linalg functions
64
70
cirq .testing .assert_allclose_up_to_global_phase (u_before , u_after , atol = 1e-6 )
65
71
66
72
# Also test optimization with SQRT_ISWAP_INV
67
73
c_sqrt_iswap_inv = circuit .copy ()
68
- cirq .MergeInteractionsToSqrtIswap (use_sqrt_iswap_inv = True ).optimize_circuit (c_sqrt_iswap_inv )
74
+ with cirq .testing .assert_deprecated (
75
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
76
+ ):
77
+ cirq .MergeInteractionsToSqrtIswap (use_sqrt_iswap_inv = True ).optimize_circuit (
78
+ c_sqrt_iswap_inv
79
+ )
69
80
u_after2 = c_sqrt_iswap_inv .unitary (sorted (circuit .all_qubits ()))
70
81
71
82
cirq .testing .assert_allclose_up_to_global_phase (u_before , u_after2 , atol = 1e-6 )
@@ -230,79 +241,112 @@ def test_optimizes_single_iswap():
230
241
a , b = cirq .LineQubit .range (2 )
231
242
c = cirq .Circuit (cirq .ISWAP (a , b ))
232
243
assert_optimization_not_broken (c )
233
- cirq .MergeInteractionsToSqrtIswap ().optimize_circuit (c )
244
+ with cirq .testing .assert_deprecated (
245
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
246
+ ):
247
+ cirq .MergeInteractionsToSqrtIswap ().optimize_circuit (c )
234
248
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 2
235
249
236
250
237
251
def test_optimizes_single_inv_sqrt_iswap ():
238
252
a , b = cirq .LineQubit .range (2 )
239
253
c = cirq .Circuit (cirq .SQRT_ISWAP_INV (a , b ))
240
254
assert_optimization_not_broken (c )
241
- cirq .MergeInteractionsToSqrtIswap ().optimize_circuit (c )
255
+ with cirq .testing .assert_deprecated (
256
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
257
+ ):
258
+ cirq .MergeInteractionsToSqrtIswap ().optimize_circuit (c )
242
259
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 1
243
260
244
261
245
262
def test_init_raises ():
246
263
with pytest .raises (ValueError , match = 'must be 0, 1, 2, or 3' ):
247
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 4 )
264
+ with cirq .testing .assert_deprecated (
265
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
266
+ ):
267
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 4 )
248
268
249
269
250
270
def test_optimizes_single_iswap_require0 ():
251
271
a , b = cirq .LineQubit .range (2 )
252
272
c = cirq .Circuit (cirq .CNOT (a , b ), cirq .CNOT (a , b )) # Minimum 0 sqrt-iSWAP
253
273
assert_optimization_not_broken (c , required_sqrt_iswap_count = 0 )
254
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 0 ).optimize_circuit (c )
274
+ with cirq .testing .assert_deprecated (
275
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
276
+ ):
277
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 0 ).optimize_circuit (c )
255
278
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 0
256
279
257
280
258
281
def test_optimizes_single_iswap_require0_raises ():
259
282
a , b = cirq .LineQubit .range (2 )
260
283
c = cirq .Circuit (cirq .CNOT (a , b )) # Minimum 2 sqrt-iSWAP
261
284
with pytest .raises (ValueError , match = 'cannot be decomposed into exactly 0 sqrt-iSWAP gates' ):
262
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 0 ).optimize_circuit (c )
285
+ with cirq .testing .assert_deprecated (
286
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
287
+ ):
288
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 0 ).optimize_circuit (c )
263
289
264
290
265
291
def test_optimizes_single_iswap_require1 ():
266
292
a , b = cirq .LineQubit .range (2 )
267
293
c = cirq .Circuit (cirq .SQRT_ISWAP_INV (a , b )) # Minimum 1 sqrt-iSWAP
268
294
assert_optimization_not_broken (c , required_sqrt_iswap_count = 1 )
269
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 1 ).optimize_circuit (c )
295
+ with cirq .testing .assert_deprecated (
296
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
297
+ ):
298
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 1 ).optimize_circuit (c )
270
299
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 1
271
300
272
301
273
302
def test_optimizes_single_iswap_require1_raises ():
274
303
a , b = cirq .LineQubit .range (2 )
275
304
c = cirq .Circuit (cirq .CNOT (a , b )) # Minimum 2 sqrt-iSWAP
276
305
with pytest .raises (ValueError , match = 'cannot be decomposed into exactly 1 sqrt-iSWAP gates' ):
277
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 1 ).optimize_circuit (c )
306
+ with cirq .testing .assert_deprecated (
307
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
308
+ ):
309
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 1 ).optimize_circuit (c )
278
310
279
311
280
312
def test_optimizes_single_iswap_require2 ():
281
313
a , b = cirq .LineQubit .range (2 )
282
314
c = cirq .Circuit (cirq .SQRT_ISWAP_INV (a , b )) # Minimum 1 sqrt-iSWAP but 2 possible
283
315
assert_optimization_not_broken (c , required_sqrt_iswap_count = 2 )
284
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 2 ).optimize_circuit (c )
316
+ with cirq .testing .assert_deprecated (
317
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
318
+ ):
319
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 2 ).optimize_circuit (c )
285
320
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 2
286
321
287
322
288
323
def test_optimizes_single_iswap_require2_raises ():
289
324
a , b = cirq .LineQubit .range (2 )
290
325
c = cirq .Circuit (cirq .SWAP (a , b )) # Minimum 3 sqrt-iSWAP
291
326
with pytest .raises (ValueError , match = 'cannot be decomposed into exactly 2 sqrt-iSWAP gates' ):
292
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 2 ).optimize_circuit (c )
327
+ with cirq .testing .assert_deprecated (
328
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
329
+ ):
330
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 2 ).optimize_circuit (c )
293
331
294
332
295
333
def test_optimizes_single_iswap_require3 ():
296
334
a , b = cirq .LineQubit .range (2 )
297
335
c = cirq .Circuit (cirq .ISWAP (a , b )) # Minimum 2 sqrt-iSWAP but 3 possible
298
336
assert_optimization_not_broken (c , required_sqrt_iswap_count = 3 )
299
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 3 ).optimize_circuit (c )
337
+ with cirq .testing .assert_deprecated (
338
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
339
+ ):
340
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 3 ).optimize_circuit (c )
300
341
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 3
301
342
302
343
303
344
def test_optimizes_single_inv_sqrt_iswap_require3 ():
304
345
a , b = cirq .LineQubit .range (2 )
305
346
c = cirq .Circuit (cirq .SQRT_ISWAP_INV (a , b ))
306
347
assert_optimization_not_broken (c , required_sqrt_iswap_count = 3 )
307
- cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 3 ).optimize_circuit (c )
348
+ with cirq .testing .assert_deprecated (
349
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' , count = 2
350
+ ):
351
+ cirq .MergeInteractionsToSqrtIswap (required_sqrt_iswap_count = 3 ).optimize_circuit (c )
308
352
assert len ([1 for op in c .all_operations () if len (op .qubits ) == 2 ]) == 3
0 commit comments