@@ -23,10 +23,12 @@ def assert_optimizes(
23
23
before : cirq .Circuit ,
24
24
expected : cirq .Circuit ,
25
25
optimizer : Optional [Callable [[cirq .Circuit ], None ]] = None ,
26
+ deprecated_msg : str = "Use cirq.merge_k_qubit_unitaries" ,
26
27
):
27
- if optimizer is None :
28
- optimizer = cirq .MergeSingleQubitGates ().optimize_circuit
29
- optimizer (before )
28
+ with cirq .testing .assert_deprecated (deprecated_msg , deadline = 'v1.0' ):
29
+ if optimizer is None :
30
+ optimizer = cirq .MergeSingleQubitGates ().optimize_circuit
31
+ optimizer (before )
30
32
31
33
# Ignore differences that would be caught by follow-up optimizations.
32
34
followup_transformers = [cirq .drop_negligible_operations , cirq .drop_empty_moments ]
@@ -38,7 +40,8 @@ def assert_optimizes(
38
40
39
41
40
42
def test_leaves_singleton ():
41
- m = cirq .MergeSingleQubitGates ()
43
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
44
+ m = cirq .MergeSingleQubitGates ()
42
45
q = cirq .NamedQubit ('q' )
43
46
c = cirq .Circuit ([cirq .Moment ([cirq .X (q )])])
44
47
@@ -48,12 +51,16 @@ def test_leaves_singleton():
48
51
49
52
50
53
def test_not_both ():
51
- with pytest .raises (ValueError ):
52
- _ = cirq .MergeSingleQubitGates (synthesizer = lambda * args : None , rewriter = lambda * args : None )
54
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
55
+ with pytest .raises (ValueError ):
56
+ _ = cirq .MergeSingleQubitGates (
57
+ synthesizer = lambda * args : None , rewriter = lambda * args : None
58
+ )
53
59
54
60
55
61
def test_combines_sequence ():
56
- m = cirq .MergeSingleQubitGates ()
62
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
63
+ m = cirq .MergeSingleQubitGates ()
57
64
q = cirq .NamedQubit ('q' )
58
65
c = cirq .Circuit (cirq .X (q ) ** 0.5 , cirq .Z (q ) ** 0.5 , cirq .X (q ) ** - 0.5 )
59
66
@@ -83,7 +90,8 @@ def test_removes_identity_sequence():
83
90
84
91
85
92
def test_stopped_at_2qubit ():
86
- m = cirq .MergeSingleQubitGates ()
93
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
94
+ m = cirq .MergeSingleQubitGates ()
87
95
q = cirq .NamedQubit ('q' )
88
96
q2 = cirq .NamedQubit ('q2' )
89
97
c = cirq .Circuit (
@@ -109,7 +117,8 @@ def test_stopped_at_2qubit():
109
117
110
118
111
119
def test_ignores_2qubit_target ():
112
- m = cirq .MergeSingleQubitGates ()
120
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
121
+ m = cirq .MergeSingleQubitGates ()
113
122
q = cirq .NamedQubit ('q' )
114
123
q2 = cirq .NamedQubit ('q2' )
115
124
c = cirq .Circuit (
@@ -132,7 +141,8 @@ class UnsupportedDummy(cirq.SingleQubitGate):
132
141
UnsupportedDummy ()(q0 ),
133
142
)
134
143
c_orig = cirq .Circuit (circuit )
135
- cirq .MergeSingleQubitGates ().optimize_circuit (circuit )
144
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
145
+ cirq .MergeSingleQubitGates ().optimize_circuit (circuit )
136
146
137
147
assert circuit == c_orig
138
148
@@ -147,9 +157,10 @@ def test_rewrite():
147
157
cirq .CZ (q0 , q1 ),
148
158
cirq .Y (q1 ),
149
159
)
150
- cirq .MergeSingleQubitGates (rewriter = lambda ops : cirq .H (ops [0 ].qubits [0 ])).optimize_circuit (
151
- circuit
152
- )
160
+ with cirq .testing .assert_deprecated ("Use cirq.merge_k_qubit_unitaries" , deadline = 'v1.0' ):
161
+ cirq .MergeSingleQubitGates (rewriter = lambda ops : cirq .H (ops [0 ].qubits [0 ])).optimize_circuit (
162
+ circuit
163
+ )
153
164
circuit = cirq .drop_empty_moments (circuit )
154
165
155
166
cirq .testing .assert_same_circuits (
@@ -180,6 +191,7 @@ def test_merge_single_qubit_gates_into_phased_x_z():
180
191
(cirq .PhasedXPowGate (phase_exponent = - 0.5 )(a )) ** 0.5 ,
181
192
),
182
193
optimizer = cirq .merge_single_qubit_gates_into_phased_x_z ,
194
+ deprecated_msg = "Use cirq.merge_single_qubit_gates_to_phased_x_and_z" ,
183
195
)
184
196
185
197
@@ -207,4 +219,5 @@ def phxz(a, x, z):
207
219
phxz (- 0.5 , 0.5 , 0 ).on (a ),
208
220
),
209
221
optimizer = cirq .merge_single_qubit_gates_into_phxz ,
222
+ deprecated_msg = "Use cirq.merge_single_qubit_gates_to_phxz" ,
210
223
)
0 commit comments