def test_prefactor_vacuum(): """test the correct prefactor of 0.5 is calculated for a vacuum state""" Q = np.identity(2) beta = np.zeros([2]) res = prefactor(Means(beta), Covmat(Q)) ex = 1 assert np.allclose(res, ex)
def test_gen_Qmat_from_graph(): """ Test the gen_Qmat_from_graph for the analytically solvable case of a single mode""" A = np.array([[10.0]]) n_mean = 1.0 cov = Covmat(gen_Qmat_from_graph(A, n_mean)) r = np.arcsinh(np.sqrt(n_mean)) cov_e = np.diag([(np.exp(2 * r)), (np.exp(-2 * r))]) assert np.allclose(cov, cov_e)
def test_density_matrix_element_no_disp(t): """Test density matrix elements for a state with no displacement""" beta = Beta(np.zeros([6])) Q = Qmat(V) el = t[0] ex = t[1] res = density_matrix_element(Means(beta), Covmat(Q), el[0], el[1]) assert np.allclose(ex, res)
def test_prefactor_TMS(): """test the correct prefactor of 0.5 is calculated for a TMS state""" q = np.fliplr(np.diag([2.0] * 4)) np.fill_diagonal(q, np.sqrt(2)) Q = np.fliplr(q) beta = np.zeros([4]) res = prefactor(Means(beta), Covmat(Q)) ex = 0.5 assert np.allclose(res, ex)
def test_density_matrix_element_vacuum(): """Test density matrix elements for the vacuum""" Q = np.identity(2) beta = np.zeros([2]) el = [[0], [0]] ex = 1 res = density_matrix_element(Means(beta), Covmat(Q), el[0], el[1]) assert np.allclose(ex, res) el = [[1], [1]] # res = density_matrix_element(beta, A, Q, el[0], el[1]) res = density_matrix_element(Means(beta), Covmat(Q), el[0], el[1]) assert np.allclose(0, res) el = [[1], [0]] # res = density_matrix_element(beta, A, Q, el[0], el[1]) res = density_matrix_element(Means(beta), Covmat(Q), el[0], el[1]) assert np.allclose(0, res)
def test_prefactor_with_displacement(): """test the correct prefactor of 0.5 is calculated for a TMS state""" q = np.fliplr(np.diag([2.0] * 4)) np.fill_diagonal(q, np.sqrt(2)) Q = np.fliplr(q) Qinv = np.linalg.inv(Q) vect = 1.2 * np.ones([2]) + 1j * np.ones(2) beta = np.concatenate([vect, vect.conj()]) res = prefactor(Means(beta), Covmat(Q), hbar=2) ex = np.exp(-0.5 * beta @ Qinv @ beta.conj()) / np.sqrt(np.linalg.det(Q)) assert np.allclose(res, ex)
def test_Covmat(): """ Test the Covmat function by checking that its inverse function is Qmat """ n = 1 B = np.random.rand(n, n) + 1j * np.random.rand(n, n) B = B + B.T sc = find_scaling_adjacency_matrix(B, 1) idm = np.identity(2 * n) X = Xmat(n) Bsc = sc * B A = np.block([[Bsc, 0 * Bsc], [0 * Bsc, Bsc.conj()]]) Q = np.linalg.inv(idm - X @ A) cov = Covmat(Q) Qrec = Qmat(cov) assert np.allclose(Q, Qrec)