def test_cov_is_pure():
    """Tests space unrolling when going into the Gaussian backend"""
    delays = [1, 6, 36]
    modes = 216
    angles = np.concatenate([
        generate_valid_bs_sequence(delays, modes),
        generate_valid_r_sequence(delays, modes)
    ])
    net = modes + sum(delays)
    d = len(delays)
    n, N = get_mode_indices(delays)
    prog = sf.TDMProgram([N])
    vac_modes = sum(delays)

    with prog.context(*angles) as (p, q):
        Sgate(0.8) | q[n[0]]
        for i in range(d):
            Rgate(p[i + d]) | q[n[i]]
            BSgate(p[i], np.pi / 2) | (q[n[i + 1]], q[n[i]])

    prog.space_unroll()

    eng = sf.Engine(backend="gaussian")
    results = eng.run(prog)
    cov = results.state.cov()
    mu = np.zeros(len(cov))
    mu_vac, cov_vac = reduced_state(mu, cov, list(range(vac_modes)))
    mu_comp, cov_comp = reduced_state(mu, cov, list(range(vac_modes, net)))
    assert np.allclose(cov_vac, 0.5 * (sf.hbar) * np.identity(2 * vac_modes))
    assert is_pure_cov(cov_comp, hbar=sf.hbar)
Esempio n. 2
0
def fock_prob(mu, cov, ocp):
    """
    Calculates the probability of measuring the gaussian state s2 in the photon number
    occupation pattern ocp"""
    if is_pure_cov(cov):
        return np.abs(pure_state_amplitude(mu, cov, ocp, check_purity=False)) ** 2

    return density_matrix_element(mu, cov, list(ocp), list(ocp)).real
Esempio n. 3
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)
Esempio n. 4
0
def test_is_pure_cov_thermal(nbar):
    """ Test if is_pure_cov for vacuum and thermal states"""
    hbar = 2
    dim = 10
    cov = (2 * nbar + 1) * np.identity(dim)
    val = is_pure_cov(cov, hbar=hbar)
    if nbar == 0:
        assert val
    else:
        assert not val
Esempio n. 5
0
def test_is_pure_cov():
    """ Test if is_pure_cov for a pure state"""
    hbar = 2
    val = is_pure_cov(V, hbar=hbar)
    assert val