示例#1
0
def test_pure_state_amplitude_squeezed_coherent():
    """Test density matrix for a squeezed coherent state"""
    r = 0.43

    mu = np.array([0.24, -0.2])
    V = np.diag(np.array(np.exp([-2 * r, 2 * r])))

    amps = np.array([pure_state_amplitude(mu, V, [i]) for i in range(5)])
    numerical = np.outer(amps, amps.conj())
    # fmt: off
    expected = np.array(
        [[
            0.89054874, 0.15018085 + 0.05295904j, -0.23955467 + 0.01263025j,
            -0.0734589 - 0.02452154j, 0.07862323 - 0.00868528j
        ],
         [
             0.15018085 - 0.05295904j, 0.02847564, -0.03964706 + 0.01637575j,
             -0.01384625 + 0.00023317j, 0.01274241 - 0.00614023j
         ],
         [
             -0.23955467 - 0.01263025j, -0.03964706 - 0.01637575j, 0.06461854,
             0.01941242 + 0.00763805j, -0.02127257 + 0.00122123j
         ],
         [
             -0.0734589 + 0.02452154j, -0.01384625 - 0.00023317j,
             0.01941242 - 0.00763805j, 0.00673463, -0.00624626 + 0.00288134j
         ],
         [
             0.07862323 + 0.00868528j, 0.01274241 + 0.00614023j,
             -0.02127257 - 0.00122123j, -0.00624626 - 0.00288134j, 0.00702606
         ]])
    # fmt:on
    assert np.allclose(expected, numerical)
示例#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
示例#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)
示例#4
0
def test_pure_state_amplitude_two_mode_squeezed(i, j):
    """ Tests pure state amplitude for a two mode squeezed vacuum state """
    nbar = 1.0
    phase = np.pi / 8
    r = np.arcsinh(np.sqrt(nbar))
    cov = two_mode_squeezing(2 * r, phase)
    mu = np.zeros([4], dtype=np.complex)
    if i != j:
        exact = 0.0
    else:
        exact = np.exp(1j * i * phase) * (nbar / (1.0 + nbar)) ** (i / 2) / np.sqrt(1.0 + nbar)
    num = pure_state_amplitude(mu, cov, [i, j])

    assert np.allclose(exact, num)
示例#5
0
def prob_photon_sample(A: np.ndarray, sample: np.ndarray) -> float:
    """Calculate the probability of a sample of photon counts.

    The input adjacency matrix must have singular values not exceeding one. This can be achieved
    by rescaling an arbitrary adjacency matrix using :func:`rescale_adjacency`.

    Args:
        A (array): the adjacency matrix
        sample (array): the sample

    Returns:
        float: the probability
    """
    n = len(A)
    mu = np.zeros(2 * n)
    cov = A_to_cov(A)
    sample = np.array(sample, dtype="int")
    return np.abs(pure_state_amplitude(mu, cov, sample, hbar=sf.hbar))**2