Пример #1
0
def test_random_special_orthogonal_deterministic_given_seed():
    o1 = random_special_orthogonal(2, random_state=1234)
    o2 = random_special_orthogonal(2, random_state=1234)

    np.testing.assert_equal(o1, o2)
Пример #2
0
def test_random_special_orthgonal():
    o1 = random_special_orthogonal(2)
    o2 = random_special_orthogonal(2)
    assert is_special_orthogonal(o1)
    assert is_special_orthogonal(o2)
    assert not np.allclose(o1, o2)
Пример #3
0
def recompose_so4(a: np.ndarray, b: np.ndarray) -> np.ndarray:
    assert a.shape == (2, 2)
    assert b.shape == (2, 2)
    assert linalg.is_special_unitary(a)
    assert linalg.is_special_unitary(b)

    magic = np.array([[1, 0, 0, 1j], [0, 1j, 1, 0], [0, 1j, -1, 0],
                      [1, 0, 0, -1j]]) * np.sqrt(0.5)
    result = np.real(
        combinators.dot(np.conj(magic.T), linalg.kron(a, b), magic))
    assert linalg.is_orthogonal(result)
    return result


@pytest.mark.parametrize(
    'm', [testing.random_special_orthogonal(4) for _ in range(10)])
def test_so4_to_magic_su2s(m):
    a, b = linalg.so4_to_magic_su2s(m)
    m2 = recompose_so4(a, b)
    assert np.allclose(m, m2)


@pytest.mark.parametrize(
    'a,b',
    [(testing.random_special_unitary(2), testing.random_special_unitary(2))
     for _ in range(10)])
def test_so4_to_magic_su2s_known_factors(a, b):
    m = recompose_so4(a, b)
    a2, b2 = linalg.so4_to_magic_su2s(m)
    m2 = recompose_so4(a2, b2)