def test_yxxy_matrix():
    cirq.testing.assert_has_consistent_apply_unitary_for_various_exponents(
        ofc.YXXY, exponents=[1, -0.5, 0.5, 0.25, -0.25, 0.1,
                             cirq.Symbol('s')])

    np.testing.assert_allclose(cirq.unitary(ofc.YXXYPowGate(exponent=2)),
                               np.array([[1, 0, 0, 0], [0, -1, 0, 0],
                                         [0, 0, -1, 0], [0, 0, 0, 1]]),
                               atol=1e-8)

    np.testing.assert_allclose(cirq.unitary(ofc.YXXYPowGate(exponent=1)),
                               np.array([[1, 0, 0, 0], [0, 0, -1, 0],
                                         [0, 1, 0, 0], [0, 0, 0, 1]]),
                               atol=1e-8)

    np.testing.assert_allclose(cirq.unitary(ofc.YXXYPowGate(exponent=0)),
                               np.array([[1, 0, 0, 0], [0, 1, 0, 0],
                                         [0, 0, 1, 0], [0, 0, 0, 1]]),
                               atol=1e-8)

    np.testing.assert_allclose(cirq.unitary(ofc.YXXYPowGate(exponent=-1)),
                               np.array([[1, 0, 0, 0], [0, 0, 1, 0],
                                         [0, -1, 0, 0], [0, 0, 0, 1]]),
                               atol=1e-8)

    X = np.array([[0, 1], [1, 0]])
    Y = np.array([[0, -1j], [1j, 0]])
    YX = kron(Y, X)
    XY = kron(X, Y)
    np.testing.assert_allclose(cirq.unitary(ofc.YXXYPowGate(exponent=0.25)),
                               expm(-1j * np.pi * 0.25 * (YX - XY) / 4))
def test_yxxy_eq():
    eq = cirq.testing.EqualsTester()

    eq.add_equality_group(ofc.YXXYPowGate(exponent=3.5),
                          ofc.YXXYPowGate(exponent=-0.5))

    eq.add_equality_group(ofc.YXXYPowGate(exponent=1.5),
                          ofc.YXXYPowGate(exponent=-2.5))

    eq.make_equality_group(lambda: ofc.YXXYPowGate(exponent=0))
    eq.make_equality_group(lambda: ofc.YXXYPowGate(exponent=0.5))
def test_yxxy_repr():
    assert repr(ofc.YXXYPowGate(exponent=1)) == 'YXXY'
    assert repr(ofc.YXXYPowGate(exponent=0.5)) == 'YXXY**0.5'
def test_yxxy_init():
    assert ofc.YXXYPowGate(exponent=0.5).exponent == 0.5
    assert ofc.YXXYPowGate(exponent=1.5).exponent == 1.5
    assert ofc.YXXYPowGate(exponent=5).exponent == 5
Ejemplo n.º 5
0
def test_compare_yxxy_to_cirq_equivalent(exponent):
    old_gate = ofc.YXXYPowGate(exponent=exponent)
    new_gate = cirq.PhasedISwapPowGate(exponent=exponent)
    np.testing.assert_allclose(cirq.unitary(old_gate), cirq.unitary(new_gate))