3333 ZGate ,
3434 ZPowGate ,
3535)
36- from qualtran .bloqs .basic_gates .rotation import _crz , _cz_pow , _rx , _ry , _rz , _z_pow , CRz
36+ from qualtran .bloqs .basic_gates .rotation import _crz , _cz_pow , _rx , _ry , _rz , _z_pow , CRy , CRz
3737from qualtran .resource_counting import GateCounts , get_cost_value , QECGatesCost
3838from qualtran .resource_counting .classify_bloqs import bloq_is_rotation , bloq_is_t_like
3939
@@ -156,6 +156,7 @@ def test_t_like_rotation_gates():
156156 assert not bloq_is_rotation (Rx (angle ))
157157 assert not bloq_is_rotation (Ry (angle ))
158158 assert not bloq_is_rotation (Rz (angle ))
159+ assert not bloq_is_rotation (CRy (angle ))
159160 assert bloq_is_t_like (Rx (angle ))
160161 assert bloq_is_t_like (Ry (angle ))
161162 assert bloq_is_t_like (Rz (angle ))
@@ -267,6 +268,8 @@ def test_str():
267268 assert str (CZPowGate (1.0 )) == 'CZ(pow=1.0)'
268269 assert str (CZPowGate (0.9 )) == 'CZ(pow=0.9)'
269270
271+ assert str (CRz (1.0 )) == 'CRz(1.0)'
272+
270273
271274def test_rx (bloq_autotester ):
272275 bloq_autotester (_rx )
@@ -278,3 +281,27 @@ def test_ry(bloq_autotester):
278281
279282def test_rz (bloq_autotester ):
280283 bloq_autotester (_rz )
284+
285+
286+ def test_cry ():
287+ from qualtran .bloqs .basic_gates .rotation import CRy
288+
289+ rs = np .random .RandomState (52 )
290+ angle = rs .uniform (0 , 2 * np .pi )
291+
292+ u1 = CRy (angle = angle ).tensor_contract ()
293+ u2 = cirq .unitary (cirq .Ry (rads = angle ).controlled ())
294+ u3 = Controlled (Ry (angle = angle ), CtrlSpec ()).tensor_contract ()
295+ np .testing .assert_allclose (u1 , u2 , atol = 1e-8 )
296+ np .testing .assert_allclose (u1 , u3 , atol = 1e-8 )
297+
298+ ry = Ry (angle = angle )
299+ assert ry .controlled () == CRy (angle = angle )
300+
301+ ctrl_bloq = Controlled (ry .as_composite_bloq (), CtrlSpec ()).decompose_bloq ()
302+ (cry_inst ,) = list (ctrl_bloq .bloq_instances )
303+ assert cry_inst .bloq == CRy (angle = angle )
304+
305+ # testing the specialized ctrl
306+ ctrl , bloq_with_ctrl = ry .get_ctrl_system (CtrlSpec ())
307+ assert ctrl == CRy (angle = angle )
0 commit comments