def test_xxyy_matrix(): cirq.testing.assert_has_consistent_apply_unitary_for_various_exponents( ofc.XXYY, exponents=[1, -0.5, 0.5, 0.25, -0.25, 0.1, cirq.Symbol('s')]) np.testing.assert_allclose(cirq.unitary(ofc.XXYYPowGate(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.XXYYPowGate(exponent=1)), np.array([[1, 0, 0, 0], [0, 0, -1j, 0], [0, -1j, 0, 0], [0, 0, 0, 1]]), atol=1e-8) np.testing.assert_allclose(cirq.unitary(ofc.XXYYPowGate(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.XXYYPowGate(exponent=-1)), np.array([[1, 0, 0, 0], [0, 0, 1j, 0], [0, 1j, 0, 0], [0, 0, 0, 1]]), atol=1e-8) X = np.array([[0, 1], [1, 0]]) Y = np.array([[0, -1j], [1j, 0]]) XX = kron(X, X) YY = kron(Y, Y) np.testing.assert_allclose(cirq.unitary(ofc.XXYYPowGate(exponent=0.25)), expm(-1j * np.pi * 0.25 * (XX + YY) / 4))
def test_xxyy_eq(): eq = cirq.testing.EqualsTester() eq.add_equality_group(ofc.XXYYPowGate(exponent=3.5), ofc.XXYYPowGate(exponent=-0.5)) eq.add_equality_group(ofc.XXYYPowGate(exponent=1.5), ofc.XXYYPowGate(exponent=-2.5)) eq.make_equality_group(lambda: ofc.XXYYPowGate(exponent=0)) eq.make_equality_group(lambda: ofc.XXYYPowGate(exponent=0.5))
def test_xxyy_repr(): assert repr(ofc.XXYYPowGate(exponent=1)) == 'XXYY' assert repr(ofc.XXYYPowGate(exponent=0.5)) == 'XXYY**0.5'
def test_xxyy_init(): assert ofc.XXYYPowGate(exponent=0.5).exponent == 0.5 assert ofc.XXYYPowGate(exponent=1.5).exponent == 1.5 assert ofc.XXYYPowGate(exponent=5).exponent == 5
def test_compare_xxyy_to_cirq_equivalent(exponent): old_gate = ofc.XXYYPowGate(exponent=exponent) new_gate = cirq.ISwapPowGate(exponent=-exponent) np.testing.assert_allclose(cirq.unitary(old_gate), cirq.unitary(new_gate))