def test_even_validation(self): """Test that the graph_embed decomposition raises exception if not even number of rows""" A = np.random.rand(5, 5) + 1j * np.random.rand(5, 5) A += A.T with pytest.raises(ValueError, match="must have an even number of rows/columns"): williamson(A)
def test_pure_state(self, create_cov, hbar, tol): """Test pure state""" n = 3 O = omega(n) cov, _ = create_cov(np.zeros([n])) Db, S = williamson(cov) nbar = np.diag(Db) / hbar - 0.5 # check decomposition is correct assert np.allclose(S @ Db @ S.T, cov, atol=tol, rtol=0) # check nbar = 0 assert np.allclose(nbar, 0, atol=tol, rtol=0) # check S is symplectic assert np.allclose(S @ O @ S.T, O, atol=tol, rtol=0)
def test_mixed_state(self, create_cov, hbar, tol): """Test mixed state""" n = 3 O = omega(n) nbar_in = np.abs(np.random.rand(n)) cov, _ = create_cov(nbar_in) Db, S = williamson(cov) nbar = np.diag(Db) / hbar - 0.5 # check decomposition is correct assert np.allclose(S @ Db @ S.T, cov, atol=tol, rtol=0) # check nbar assert np.allclose(sorted(nbar[:n]), sorted(nbar_in), atol=tol, rtol=0) # check S is symplectic assert np.allclose(S @ O @ S.T, O, atol=tol, rtol=0)
def test_symmetric_validation(self): """Test that the graph_embed decomposition raises exception if not symmetric""" A = np.random.rand(5, 5) + 1j * np.random.rand(5, 5) with pytest.raises(ValueError, match="matrix is not symmetric"): williamson(A)
def test_vacuum_state(self, tol): """Test vacuum state""" V = np.identity(4) Db, S = williamson(V) assert np.allclose(Db, np.identity(4), atol=tol, rtol=0) assert np.allclose(S, np.identity(4), atol=tol, rtol=0)
def test_positive_definite_validation(self): """Test that the graph_embed decomposition raises exception if not positive definite""" A = np.diag([-2, 0.1, 2, 3]) with pytest.raises(ValueError, match="matrix is not positive definite"): williamson(A)