@@ -27,9 +27,11 @@ def test_convert_to_sycamore_gates_swap_zz():
27
27
)
28
28
29
29
compiled_circuit1 = circuit1 .copy ()
30
- cgoc .ConvertToSycamoreGates ()(compiled_circuit1 )
30
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
31
+ cgoc .ConvertToSycamoreGates ()(compiled_circuit1 )
31
32
compiled_circuit2 = circuit2 .copy ()
32
- cgoc .ConvertToSycamoreGates ()(compiled_circuit2 )
33
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
34
+ cgoc .ConvertToSycamoreGates ()(compiled_circuit2 )
33
35
34
36
cirq .testing .assert_same_circuits (compiled_circuit1 , compiled_circuit2 )
35
37
assert (
@@ -45,7 +47,8 @@ def test_convert_to_sycamore_gates_fsim():
45
47
q0 , q1 = cirq .LineQubit .range (2 )
46
48
circuit = cirq .Circuit (cirq .FSimGate (theta = np .pi / 2 , phi = np .pi / 6 )(q0 , q1 ))
47
49
compiled_circuit = circuit .copy ()
48
- cgoc .ConvertToSycamoreGates ()(compiled_circuit )
50
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
51
+ cgoc .ConvertToSycamoreGates ()(compiled_circuit )
49
52
50
53
cirq .testing .assert_same_circuits (circuit , compiled_circuit )
51
54
@@ -56,7 +59,8 @@ def test_single_qubit_gate():
56
59
gate = cirq .MatrixGate (mat , qid_shape = (2 ,))
57
60
circuit = cirq .Circuit (gate (q ))
58
61
converted_circuit = circuit .copy ()
59
- cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
62
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
63
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
60
64
ops = list (converted_circuit .all_operations ())
61
65
assert len (ops ) == 1
62
66
assert isinstance (ops [0 ].gate , cirq .PhasedXZGate )
@@ -70,7 +74,8 @@ def test_single_qubit_gate_phased_xz():
70
74
gate = cirq .PhasedXZGate (axis_phase_exponent = 0.2 , x_exponent = 0.3 , z_exponent = 0.4 )
71
75
circuit = cirq .Circuit (gate (q ))
72
76
converted_circuit = circuit .copy ()
73
- cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
77
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
78
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
74
79
ops = list (converted_circuit .all_operations ())
75
80
assert len (ops ) == 1
76
81
assert ops [0 ].gate == gate
@@ -80,24 +85,28 @@ def test_circuit_operation_inspection():
80
85
q0 , q1 = cirq .LineQubit .range (2 )
81
86
gate = cirq .PhasedXZGate (axis_phase_exponent = 0.2 , x_exponent = 0.3 , z_exponent = 0.4 )
82
87
cop = cirq .CircuitOperation (cirq .FrozenCircuit (gate (q0 )))
83
- assert cgoc .ConvertToSycamoreGates ()._is_native_sycamore_op (cop )
88
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
89
+ assert cgoc .ConvertToSycamoreGates ()._is_native_sycamore_op (cop )
84
90
85
91
cop2 = cirq .CircuitOperation (cirq .FrozenCircuit (cirq .SWAP (q0 , q1 )))
86
- assert not cgoc .ConvertToSycamoreGates ()._is_native_sycamore_op (cop2 )
92
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
93
+ assert not cgoc .ConvertToSycamoreGates ()._is_native_sycamore_op (cop2 )
87
94
88
95
89
96
def test_circuit_operation_conversion ():
90
97
q0 , q1 = cirq .LineQubit .range (2 )
91
98
subcircuit = cirq .FrozenCircuit (cirq .X (q0 ), cirq .SWAP (q0 , q1 ))
92
99
circuit = cirq .Circuit (cirq .CircuitOperation (subcircuit ))
93
100
converted_circuit = circuit .copy ()
94
- cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
101
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
102
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
95
103
# Verify that the CircuitOperation was preserved.
96
104
ops = list (converted_circuit .all_operations ())
97
105
assert isinstance (ops [0 ], cirq .CircuitOperation )
98
106
# Verify that the contents of the CircuitOperation were optimized.
99
107
reconverted_subcircuit = ops [0 ].circuit .unfreeze ().copy ()
100
- cgoc .ConvertToSycamoreGates ().optimize_circuit (reconverted_subcircuit )
108
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
109
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (reconverted_subcircuit )
101
110
assert ops [0 ].circuit == reconverted_subcircuit
102
111
cirq .testing .assert_circuits_with_terminal_measurements_are_equivalent (
103
112
circuit , converted_circuit , atol = 1e-8
@@ -111,7 +120,10 @@ class UnknownGate(cirq.testing.TwoQubitGate):
111
120
q0 , q1 = cirq .LineQubit .range (2 )
112
121
circuit = cirq .Circuit (UnknownGate ()(q0 , q1 ))
113
122
with pytest .raises (TypeError , match = 'gate with a known unitary' ):
114
- cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
123
+ with cirq .testing .assert_deprecated (
124
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
125
+ ):
126
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
115
127
116
128
117
129
def test_nested_unsupported_gate ():
@@ -123,7 +135,10 @@ class UnknownGate(cirq.testing.TwoQubitGate):
123
135
subcircuit = cirq .FrozenCircuit (UnknownGate ()(q0 , q1 ))
124
136
circuit = cirq .Circuit (cirq .CircuitOperation (subcircuit ))
125
137
with pytest .raises (TypeError , match = 'gate with a known unitary' ):
126
- cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
138
+ with cirq .testing .assert_deprecated (
139
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
140
+ ):
141
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
127
142
128
143
129
144
def test_unsupported_phased_iswap ():
@@ -133,7 +148,8 @@ def test_unsupported_phased_iswap():
133
148
q1 = cirq .LineQubit (1 )
134
149
circuit = cirq .Circuit (cirq .PhasedISwapPowGate (exponent = 0.5 , phase_exponent = 0.33 )(q0 , q1 ))
135
150
converted_circuit = circuit .copy ()
136
- cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
151
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
152
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
137
153
cirq .testing .assert_circuits_with_terminal_measurements_are_equivalent (
138
154
circuit , converted_circuit , atol = 1e-8
139
155
)
@@ -155,7 +171,8 @@ def with_qubits(self, *new_qubits):
155
171
q0 = cirq .LineQubit (0 )
156
172
circuit = cirq .Circuit (UnknownOperation ([q0 ]))
157
173
converted_circuit = circuit .copy ()
158
- cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
174
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
175
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (converted_circuit )
159
176
assert circuit == converted_circuit
160
177
161
178
@@ -168,7 +185,10 @@ class ThreeQubitGate(cirq.testing.ThreeQubitGate):
168
185
q2 = cirq .LineQubit (2 )
169
186
circuit = cirq .Circuit (ThreeQubitGate ()(q0 , q1 , q2 ))
170
187
with pytest .raises (TypeError ):
171
- cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
188
+ with cirq .testing .assert_deprecated (
189
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
190
+ ):
191
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (circuit )
172
192
173
193
174
194
def random_single_qubit_unitary ():
@@ -199,7 +219,10 @@ def test_zztheta_qaoa_like():
199
219
]
200
220
)
201
221
syc_circuit = cirq_circuit .copy ()
202
- cgoc .ConvertToSycamoreGates ().optimize_circuit (syc_circuit )
222
+ with cirq .testing .assert_deprecated (
223
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
224
+ ):
225
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (syc_circuit )
203
226
204
227
cirq .testing .assert_allclose_up_to_global_phase (
205
228
cirq .unitary (cirq_circuit ), cirq .unitary (syc_circuit ), atol = 1e-7
@@ -214,7 +237,8 @@ def test_zztheta_zzpow_unsorted_qubits():
214
237
cirq .ZZPowGate (exponent = exponent , global_shift = - 0.5 ).on (qubits [0 ], qubits [1 ]),
215
238
)
216
239
actual_circuit = expected_circuit .copy ()
217
- cgoc .ConvertToSycamoreGates ().optimize_circuit (actual_circuit )
240
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
241
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (actual_circuit )
218
242
219
243
cirq .testing .assert_allclose_up_to_global_phase (
220
244
cirq .unitary (expected_circuit ), cirq .unitary (actual_circuit ), atol = 1e-7
@@ -231,15 +255,19 @@ def test_swap_zztheta():
231
255
)
232
256
expected_unitary = cirq .unitary (expected_circuit )
233
257
actual_circuit = expected_circuit .copy ()
234
- cgoc .ConvertToSycamoreGates ().optimize_circuit (actual_circuit )
258
+ with cirq .testing .assert_deprecated (
259
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
260
+ ):
261
+ cgoc .ConvertToSycamoreGates ().optimize_circuit (actual_circuit )
235
262
actual_unitary = cirq .unitary (actual_circuit )
236
263
cirq .testing .assert_allclose_up_to_global_phase (actual_unitary , expected_unitary , atol = 1e-7 )
237
264
238
265
239
266
def test_known_two_q_operations_to_sycamore_operations_cnot ():
240
267
a , b = cirq .LineQubit .range (2 )
241
268
op = cirq .CNOT (a , b )
242
- decomposed = cirq .Circuit (cgoc .ConvertToSycamoreGates ().convert (op ))
269
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
270
+ decomposed = cirq .Circuit (cgoc .ConvertToSycamoreGates ().convert (op ))
243
271
244
272
# Should be equivalent.
245
273
cirq .testing .assert_allclose_up_to_global_phase (
@@ -271,7 +299,8 @@ def test_known_two_q_operations_to_sycamore_operations_cnot():
271
299
def test_convert_to_sycamore_equivalent_unitaries (gate ):
272
300
qubits = [cirq .NamedQubit ('a' ), cirq .NamedQubit ('b' )]
273
301
operation = gate .on (qubits [0 ], qubits [1 ])
274
- converted = cgoc .ConvertToSycamoreGates ().convert (operation )
302
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
303
+ converted = cgoc .ConvertToSycamoreGates ().convert (operation )
275
304
u1 = cirq .unitary (cirq .Circuit (converted ))
276
305
u2 = cirq .unitary (operation )
277
306
cirq .testing .assert_allclose_up_to_global_phase (u1 , u2 , atol = 1e-8 )
@@ -284,7 +313,8 @@ def test_convert_to_sycamore_tabulation():
284
313
)
285
314
qubits = [cirq .NamedQubit ('a' ), cirq .NamedQubit ('b' )]
286
315
operation = cirq .MatrixGate (cirq .unitary (cirq .CX ), qid_shape = (2 , 2 )).on (qubits [0 ], qubits [1 ])
287
- converted = cgoc .ConvertToSycamoreGates (sycamore_tabulation ).convert (operation )
316
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
317
+ converted = cgoc .ConvertToSycamoreGates (sycamore_tabulation ).convert (operation )
288
318
u1 = cirq .unitary (cirq .Circuit (converted ))
289
319
u2 = cirq .unitary (operation )
290
320
overlap = abs (np .trace (u1 .conj ().T @ u2 ))
@@ -295,7 +325,10 @@ def test_sycamore_invalid_tabulation():
295
325
# An object other than a tabulation.
296
326
sycamore_tabulation = {}
297
327
with pytest .raises (ValueError ):
298
- cgoc .ConvertToSycamoreGates (sycamore_tabulation )
328
+ with cirq .testing .assert_deprecated (
329
+ "Use cirq.optimize_for_target_gateset" , deadline = 'v1.0'
330
+ ):
331
+ cgoc .ConvertToSycamoreGates (sycamore_tabulation )
299
332
300
333
301
334
q = cirq .GridQubit .rect (1 , 3 )
@@ -315,4 +348,7 @@ def test_sycamore_invalid_tabulation():
315
348
)
316
349
def test_supported_operation (op , is_valid ):
317
350
c = cirq .Circuit (op )
318
- assert (cirq_google .ConvertToSycamoreGates ().optimization_at (c , 0 , op ) is not None ) == is_valid
351
+ with cirq .testing .assert_deprecated ("Use cirq.optimize_for_target_gateset" , deadline = 'v1.0' ):
352
+ assert (
353
+ cirq_google .ConvertToSycamoreGates ().optimization_at (c , 0 , op ) is not None
354
+ ) == is_valid
0 commit comments