def test_kron_factor_fail(): with pytest.raises(ValueError): _ = cirq.kron_factor_4x4_to_2x2s( cirq.kron_with_controls(cirq.CONTROL_TAG, X)) with pytest.raises(ValueError): _ = cirq.kron_factor_4x4_to_2x2s(np.diag([1, 1, 1, 1j]))
def test_kron_factor_fail(): mat = cirq.kron_with_controls(cirq.CONTROL_TAG, X) g, f1, f2 = cirq.kron_factor_4x4_to_2x2s(mat) with pytest.raises(ValueError): assert_kronecker_factorization_not_within_tolerance(mat, g, f1, f2) mat = cirq.kron_factor_4x4_to_2x2s(np.diag([1, 1, 1, 1j])) with pytest.raises(ValueError): assert_kronecker_factorization_not_within_tolerance(mat, g, f1, f2)
def test_kron_factor(f1, f2): p = cirq.kron(f1, f2) g, g1, g2 = cirq.kron_factor_4x4_to_2x2s(p) assert abs(np.linalg.det(g1) - 1) < 0.00001 assert abs(np.linalg.det(g2) - 1) < 0.00001 assert np.allclose(g * cirq.kron(g1, g2), p) assert_kronecker_factorization_within_tolerance(p, g, g1, g2)
def test_kron_factor_special_unitaries(f1, f2): p = cirq.kron(f1, f2) g, g1, g2 = cirq.kron_factor_4x4_to_2x2s(p) assert np.allclose(cirq.kron(g1, g2), p) assert abs(g - 1) < 0.000001 assert cirq.is_special_unitary(g1) assert cirq.is_special_unitary(g2)
def test_kron_factor_special_unitaries(f1, f2): p = cirq.kron(f1, f2) g, g1, g2 = cirq.kron_factor_4x4_to_2x2s(p) assert np.allclose(cirq.kron(g1, g2), p) assert abs(g - 1) < 0.000001 assert cirq.is_special_unitary(g1) assert cirq.is_special_unitary(g2) assert_kronecker_factorization_within_tolerance(p, g, g1, g2)
def test_kron_factor(f1, f2): p = cirq.kron(f1, f2) g, g1, g2 = cirq.kron_factor_4x4_to_2x2s(p) assert abs(np.linalg.det(g1) - 1) < 0.00001 assert abs(np.linalg.det(g2) - 1) < 0.00001 assert np.allclose(g * cirq.kron(g1, g2), p)