Exemple #1
0
def fock_amplitudes_one_mode(alpha, cov, cutoff):
    """ Returns the Fock space density matrix of gaussian state characterized
    by a complex displacement alpha and a (symmetric) covariance matrix
    The Fock ladder ladder goes from 0 to cutoff-1"""
    r = 2 * np.array([alpha.real, alpha.imag])
    if is_pure_cov(cov):
        psi = state_vector(r, cov, normalize=True, cutoff=cutoff)
        rho = np.outer(psi, psi.conj())
        return rho
    return density_matrix(r, cov, normalize=True, cutoff=cutoff)
Exemple #2
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)
Exemple #3
0
def test_state_vector_two_mode_squeezed():
    """ Tests state_vector for a two mode squeezed vacuum state """
    nbar = 1.0
    cutoff = 5
    phase = np.pi / 8
    r = np.arcsinh(np.sqrt(nbar))
    cov = two_mode_squeezing(2 * r, phase)
    mu = np.zeros([4], dtype=np.complex)
    exact = np.array([(np.exp(1j * i * phase) * (nbar / (1.0 + nbar)) ** (i / 2) / np.sqrt(1.0 + nbar)) for i in range(cutoff)])
    psi = state_vector(mu, cov, cutoff=cutoff)
    expected = np.diag(exact)
    assert np.allclose(psi, expected)
Exemple #4
0
def test_state_vector_two_mode_squeezed_post_normalize():
    """ Tests state_vector for a two mode squeezed vacuum state """
    nbar = 1.0
    cutoff = 5
    phase = np.pi / 8
    r = np.arcsinh(np.sqrt(nbar))
    cov = two_mode_squeezing(2 * r, phase)
    mu = np.zeros([4], dtype=np.complex)
    exact = np.diag(np.array([(np.exp(1j * i * phase) * (nbar / (1.0 + nbar)) ** (i / 2) / np.sqrt(1.0 + nbar)) for i in range(cutoff)]))
    val = 2
    post_select = {0: val}
    psi = state_vector(mu, cov, cutoff=cutoff, post_select=post_select, normalize=True)
    expected = exact[val]
    expected = expected / np.linalg.norm(expected)
    assert np.allclose(psi, expected)
Exemple #5
0
def test_cubic_phase():
    """Test that all the possible ways of obtaining a cubic phase state using the different methods agree"""
    mu = np.array([
        -0.50047867, 0.37373598, 0.01421683, 0.26999427, 0.04450994, 0.01903583
    ])

    cov = np.array([
        [
            1.57884241, 0.81035494, 1.03468307, 1.14908791, 0.09179507,
            -0.11893174
        ],
        [
            0.81035494, 1.06942863, 0.89359234, 0.20145142, 0.16202296,
            0.4578259
        ],
        [
            1.03468307, 0.89359234, 1.87560498, 0.16915661, 1.0836528,
            -0.09405278
        ],
        [
            1.14908791, 0.20145142, 0.16915661, 2.37765137, -0.93543385,
            -0.6544286
        ],
        [
            0.09179507, 0.16202296, 1.0836528, -0.93543385, 2.78903152,
            -0.76519088
        ],
        [
            -0.11893174, 0.4578259, -0.09405278, -0.6544286, -0.76519088,
            1.51724222
        ],
    ])

    cutoff = 7
    # the Fock state measurement of mode 0 to be post-selected
    m1 = 1
    # the Fock state measurement of mode 1 to be post-selected
    m2 = 2

    psi = state_vector(mu,
                       cov,
                       post_select={
                           0: m1,
                           1: m2
                       },
                       cutoff=cutoff,
                       hbar=2)
    psi_c = state_vector(mu, cov, cutoff=cutoff, hbar=2)[m1, m2, :]
    rho = density_matrix(mu,
                         cov,
                         post_select={
                             0: m1,
                             1: m2
                         },
                         cutoff=cutoff,
                         hbar=2)
    rho_c = density_matrix(mu, cov, cutoff=cutoff, hbar=2)[m1, m2, :, m1,
                                                           m2, :]
    assert np.allclose(np.outer(psi, psi.conj()), rho)
    assert np.allclose(np.outer(psi_c, psi_c.conj()), rho)
    assert np.allclose(rho_c, rho)
 def get_state_vector(self):
     return quantum.state_vector(self.mu, self.cov)