Ejemplo n.º 1
0
def test_beta():
    """test the correct beta is returned"""
    mu = np.arange(4)
    res = Beta(mu)

    alpha = (mu[:2] + 1j * mu[2:]) / np.sqrt(2 * 2)
    ex = np.concatenate([alpha, alpha.conj()])
    assert np.allclose(res, ex)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def test_pure_state_amplitude_coherent(i):
    """ Tests pure state amplitude for a coherent state """
    cov = np.identity(2)
    mu = np.array([1.0, 2.0])
    beta = Beta(mu)
    alpha = beta[0]
    exact = np.exp(-0.5 * np.abs(alpha) ** 2) * alpha ** i / np.sqrt(np.math.factorial(i))
    num = pure_state_amplitude(mu, cov, [i])
    assert np.allclose(exact, num)
Ejemplo n.º 4
0
def test_state_vector_coherent():
    """ Tests state vector for a coherent state """
    cutoff = 5
    cov = np.identity(2)
    mu = np.array([1.0, 2.0])
    beta = Beta(mu)
    alpha = beta[0]
    exact = np.array([(np.exp(-0.5 * np.abs(alpha) ** 2) * alpha ** i / np.sqrt(np.math.factorial(i))) for i in range(cutoff)])
    num = state_vector(mu, cov, cutoff=cutoff)
    assert np.allclose(exact, num)
Ejemplo n.º 5
0
def test_Means():
    """test the correct beta is returned"""
    res = np.arange(4)
    mu = Beta(res)
    ex = Means(mu)
    assert np.allclose(res, ex)