def test_calculate_WAW(self): """Test that the calculate_WAW method calculates correctly""" const = 2 A = 0.1767767 * np.ones((4, 4)) params = const * np.ones(4) waw = StrawberryFieldsGBS.calculate_WAW(params, A) assert np.allclose(waw, const * A)
def test_calculate_covariance(self): """Test that the calculate_covariance method returns the correct covariance matrix for a fixed example.""" x = np.sqrt(0.5) A = np.array([[0, x], [x, 0]]) cov = StrawberryFieldsGBS.calculate_covariance(A, 2) target = np.array( [ [3.0, 0.0, 0.0, 2.82842712], [0.0, 3.0, 2.82842712, 0.0], [0.0, 2.82842712, 3.0, 0.0], [2.82842712, 0.0, 0.0, 3.0], ] ) assert np.allclose(cov, target)
def test_calculate_z_inv(self): """Test that the _calculate_z_inv returns correctly on a fixed example""" A = 0.1767767 * np.ones((4, 4)) z_inv = StrawberryFieldsGBS._calculate_z_inv(A) assert np.allclose(z_inv, 1 / np.sqrt(2))
def test_calculate_n_mean_singular_values_large(self): """Test that calculate_n_mean raises a ValueError when not all of the singular values are less than one""" A = np.ones((4, 4)) with pytest.raises(ValueError, match="Singular values of matrix A must be less than 1"): StrawberryFieldsGBS.calculate_n_mean(A)
def test_calculate_n_mean(self): """Test that calculate_n_mean computes the mean photon number correctly""" A = 0.1767767 * np.ones((4, 4)) n_mean = StrawberryFieldsGBS.calculate_n_mean(A) assert np.allclose(n_mean, 1)