@@ -170,9 +170,11 @@ def test_str() -> None:
170170 assert str (cirq .CSWAP ) == 'FREDKIN'
171171 assert str (cirq .FREDKIN ) == 'FREDKIN'
172172 assert str (cirq .CCZ ) == 'CCZ'
173+ assert str (cirq .CCY ) == 'CCY'
173174
174175 assert str (cirq .CCX ** 0.5 ) == 'TOFFOLI**0.5'
175176 assert str (cirq .CCZ ** 0.5 ) == 'CCZ**0.5'
177+ assert str (cirq .CCY ** 0.5 ) == 'CCY**0.5'
176178
177179
178180def test_repr () -> None :
@@ -181,9 +183,11 @@ def test_repr() -> None:
181183 assert repr (cirq .CSWAP ) == 'cirq.FREDKIN'
182184 assert repr (cirq .FREDKIN ) == 'cirq.FREDKIN'
183185 assert repr (cirq .CCZ ) == 'cirq.CCZ'
186+ assert repr (cirq .CCY ) == 'cirq.CCY'
184187
185188 assert repr (cirq .CCX ** 0.5 ) == '(cirq.TOFFOLI**0.5)'
186189 assert repr (cirq .CCZ ** 0.5 ) == '(cirq.CCZ**0.5)'
190+ assert repr (cirq .CCY ** 0.5 ) == '(cirq.CCY**0.5)'
187191
188192
189193def test_eq () -> None :
@@ -200,6 +204,12 @@ def test_eq() -> None:
200204 eq .add_equality_group (cirq .TOFFOLI (a , b , c ), cirq .CCX (a , b , c ))
201205 eq .add_equality_group (cirq .TOFFOLI (a , c , b ), cirq .TOFFOLI (c , a , b ))
202206 eq .add_equality_group (cirq .TOFFOLI (a , b , d ))
207+ eq .add_equality_group (cirq .CCY (a , b , c ), cirq .CCY (b , a , c ))
208+ eq .add_equality_group (
209+ cirq .CCY (a , b , c ) ** 0.5 , cirq .CCY (b , a , c ) ** 2.5 , cirq .CCY (a , b , c ) ** - 1.5
210+ )
211+ eq .add_equality_group (cirq .CCY (a , c , b ), cirq .CCY (c , a , b ))
212+ eq .add_equality_group (cirq .CCY (a , b , d ))
203213 eq .add_equality_group (cirq .CSWAP (a , b , c ), cirq .FREDKIN (a , b , c ), cirq .FREDKIN (a , b , c ) ** - 1 )
204214 eq .add_equality_group (cirq .CSWAP (b , a , c ), cirq .CSWAP (b , c , a ))
205215
@@ -210,6 +220,7 @@ def test_gate_equality() -> None:
210220 eq .add_equality_group (cirq .CZPowGate (), cirq .CZPowGate ())
211221 eq .add_equality_group (cirq .CCXPowGate (), cirq .CCXPowGate (), cirq .CCNotPowGate ())
212222 eq .add_equality_group (cirq .CCZPowGate (), cirq .CCZPowGate ())
223+ eq .add_equality_group (cirq .CCYPowGate (), cirq .CCYPowGate ())
213224
214225
215226def test_identity_multiplication () -> None :
@@ -218,13 +229,18 @@ def test_identity_multiplication() -> None:
218229 assert cirq .CCX (a , b , c ) * cirq .I (b ) == cirq .CCX (a , b , c )
219230 assert cirq .CCX (a , b , c ) ** 0.5 * cirq .I (c ) == cirq .CCX (a , b , c ) ** 0.5
220231 assert cirq .I (c ) * cirq .CCZ (a , b , c ) ** 0.5 == cirq .CCZ (a , b , c ) ** 0.5
232+ assert cirq .CCY (a , b , c ) * cirq .I (a ) == cirq .CCY (a , b , c )
233+ assert cirq .CCY (a , b , c ) * cirq .I (b ) == cirq .CCY (a , b , c )
234+ assert cirq .CCY (a , b , c ) ** 0.5 * cirq .I (c ) == cirq .CCY (a , b , c ) ** 0.5
235+ assert cirq .I (c ) * cirq .CCY (a , b , c ) ** 0.5 == cirq .CCY (a , b , c ) ** 0.5
221236
222237
223238@pytest .mark .parametrize (
224239 'op,max_two_cost' ,
225240 [
226241 (cirq .CCZ (* cirq .LineQubit .range (3 )), 8 ),
227242 (cirq .CCX (* cirq .LineQubit .range (3 )), 8 ),
243+ (cirq .CCY (* cirq .LineQubit .range (3 )), 8 ),
228244 (cirq .CCZ (cirq .LineQubit (0 ), cirq .LineQubit (2 ), cirq .LineQubit (1 )), 8 ),
229245 (cirq .CCZ (cirq .LineQubit (0 ), cirq .LineQubit (2 ), cirq .LineQubit (1 )) ** sympy .Symbol ("s" ), 8 ),
230246 (cirq .CSWAP (* cirq .LineQubit .range (3 )), 9 ),
@@ -259,7 +275,13 @@ def test_diagonal_gate_property() -> None:
259275
260276@pytest .mark .parametrize (
261277 'gate' ,
262- [cirq .CCX , cirq .CSWAP , cirq .CCZ , cirq .ThreeQubitDiagonalGate ([2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 ])],
278+ [
279+ cirq .CCX ,
280+ cirq .CCY ,
281+ cirq .CSWAP ,
282+ cirq .CCZ ,
283+ cirq .ThreeQubitDiagonalGate ([2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 ]),
284+ ],
263285)
264286def test_decomposition_respects_locality (gate ) -> None :
265287 a = cirq .GridQubit (0 , 0 )
@@ -279,6 +301,8 @@ def test_diagram() -> None:
279301 cirq .TOFFOLI (a , b , c ) ** 0.5 ,
280302 cirq .TOFFOLI (c , b , a ) ** 0.5 ,
281303 cirq .CCX (a , c , b ),
304+ cirq .CCY (a , b , c ),
305+ cirq .CCY (a , b , c ) ** 0.5 ,
282306 cirq .CCZ (a , d , b ),
283307 cirq .CCZ (a , d , b ) ** 0.5 ,
284308 cirq .CSWAP (a , c , d ),
@@ -287,25 +311,25 @@ def test_diagram() -> None:
287311 cirq .testing .assert_has_diagram (
288312 circuit ,
289313 """
290- 0: ───@───@───────X^0.5───@───@───@───────@───@───
291- │ │ │ │ │ │ │ │
292- 1: ───@───@───────@───────X───@───@───────┼───×───
293- │ │ │ │ │ │ │ │
294- 2: ───X───X^0.5───@───────@───┼───┼───────×───×───
295- │ │ │
296- 3: ───────────────────────────@───@^0.5───×───────
314+ 0: ───@───@───────X^0.5───@───@───@───────@───@───────@───@───
315+ │ │ │ │ │ │ │ │ │ │
316+ 1: ───@───@───────@───────X───@───@───────@───@─────── ┼───×───
317+ │ │ │ │ │ │ │ │ │ │
318+ 2: ───X───X^0.5───@───────@───Y───Y^0.5─── ┼───┼───────×───×───
319+ │ │ │
320+ 3: ─────────────────────────────────────── @───@^0.5───×───────
297321""" ,
298322 )
299323 cirq .testing .assert_has_diagram (
300324 circuit ,
301325 """
302- 0: ---@---@-------X^0.5---@---@---@-------@------@------
303- | | | | | | | |
304- 1: ---@---@-------@-------X---@---@-------|------swap---
305- | | | | | | | |
306- 2: ---X---X^0.5---@-------@---|---|-------swap---swap---
307- | | |
308- 3: ---------------------------@---@^0.5---swap----------
326+ 0: ---@---@-------X^0.5---@---@---@-------@---@-------@--- ---@------
327+ | | | | | | | | | |
328+ 1: ---@---@-------@-------X---@---@-------@---@------- |------swap---
329+ | | | | | | | | | |
330+ 2: ---X---X^0.5---@-------@---Y---Y^0.5--- |---|-------swap---swap---
331+ | | |
332+ 3: --------------------------------------- @---@^0.5---swap----------
309333""" ,
310334 use_unicode_characters = False ,
311335 )
@@ -365,7 +389,7 @@ def test_resolve(resolve_fn) -> None:
365389 assert not cirq .is_parameterized (diagonal_gate )
366390
367391
368- @pytest .mark .parametrize ('gate' , [cirq .CCX , cirq .CCZ , cirq .CSWAP ])
392+ @pytest .mark .parametrize ('gate' , [cirq .CCX , cirq .CCY , cirq . CCZ , cirq .CSWAP ])
369393def test_controlled_ops_consistency (gate ) -> None :
370394 a , b , c , d = cirq .LineQubit .range (4 )
371395 assert gate .controlled (0 ) is gate
0 commit comments