Esempio n. 1
0
def test_marginal_calcs_2d():
    """Tests that marginal_calcs_2d returns the correct values as an array"""
    nmean = 1.0
    ps = twinbeam_pmf({"n_modes": 1.0, "sq_0": nmean})
    res = marginal_calcs_2d(ps, as_dict=False)
    expected = np.array([nmean, nmean, 2 + 1 / nmean, 2, 2, 0])
    assert np.allclose(res, expected)
Esempio n. 2
0
def test_twin_correct_stats(sq_0, sq_1, noise_s, noise_i, eta_s, eta_i):
    """Test that dark counts are correctly included by calculating expected g2s and mean photon numbers"""
    cutoff = 40
    params = {
        "n_modes": 2,
        "eta_s": eta_s,
        "eta_i": eta_i,
        "noise_s": noise_s,
        "noise_i": noise_i,
        "sq_0": sq_0,
        "sq_1": sq_1,
    }
    pmf = twinbeam_pmf(params, cutoff=cutoff)
    K = (sq_0 + sq_1)**2 / (sq_0**2 + sq_1**2)
    M = sq_0 + sq_1
    g2noiseless = 1.0 + 1.0 / K
    eps_s = noise_s / (eta_s * M)
    eps_i = noise_i / (eta_i * M)
    g2s = (g2noiseless + 2 * eps_s + eps_s**2) / (1.0 + 2 * eps_s + eps_s**2)
    g2i = (g2noiseless + 2 * eps_i + eps_i**2) / (1.0 + 2 * eps_i + eps_i**2)
    marginals = marginal_calcs_2d(pmf)
    np.allclose(g2s, marginals["g2_s"])
    np.allclose(g2i, marginals["g2_i"])
    np.allclose(noise_s + eta_s * M, marginals["n_s"])
    np.allclose(noise_i + eta_i * M, marginals["n_i"])
Esempio n. 3
0
def test_gen_hist_2d_poisson(ns, ni):
    """Test the histograms are correctly generated for pure noise"""
    nsamples = 1000000
    mat = gen_hist_2d(np.random.poisson(ns, nsamples),
                      np.random.poisson(ni, nsamples))
    n, m = mat.shape
    nmax = np.max([n, m])
    expected = twinbeam_pmf({"noise_s": ns, "noise_i": ni})[:n, :m]
    np.allclose(expected, mat, atol=0.01)
Esempio n. 4
0
def test_exact_model_2d(n_modes, do_not_vary, threshold):
    """Test that the fitting is correct when the guess is exactly the correct answer"""
    sq_n = 0.7 * (0.5**np.arange(n_modes))
    noise_s = 0.1
    noise_i = 0.15
    eta_s = 0.7
    eta_i = 0.6
    params = {"sq_" + str(i): sq_n[i] for i in range(n_modes)}
    params["n_modes"] = n_modes
    params["eta_s"] = eta_s
    params["eta_i"] = eta_i
    params["noise_s"] = noise_s
    params["noise_i"] = noise_i
    if threshold:
        probs = threshold_2d(twinbeam_pmf(params), threshold, threshold)
    else:
        probs = twinbeam_pmf(params)
    fit = fit_2d(probs, params, do_not_vary=do_not_vary, threshold=threshold)
    assert np.allclose(fit.chisqr, 0.0)
Esempio n. 5
0
def test_gen_hist_2d_twin(sq_0):
    """Check that a histogram is constructed correctly for a lossless pure twin-beam source"""
    nsamples = 1000000
    p = 1 / (1.0 + sq_0)
    samples = np.random.geometric(p, nsamples) - 1
    mat = gen_hist_2d(samples, samples)
    n, m = mat.shape
    assert n == m
    expected = twinbeam_pmf({"sq_0": sq_0, "n_modes": 1}, cutoff=n)
    assert np.allclose(mat, expected, atol=0.01)
Esempio n. 6
0
def test_two_schmidt_mode_guess_exact(eta_s, eta_i, sq_0, sq_1):
    """Test that one can invert correctly when there are two Schmidt modes
    and no dark counts.
    """
    pmf = twinbeam_pmf({
        "sq_0": sq_0,
        "sq_1": sq_1,
        "n_modes": 2,
        "eta_s": eta_s,
        "eta_i": eta_i
    })
    guess = two_schmidt_mode_guess(pmf)
    assert np.allclose(eta_s, guess["eta_s"], atol=1.0e-2)
    assert np.allclose(eta_i, guess["eta_i"], atol=1.0e-2)
    sq_ns = [sq_0,
             sq_1]  # We need to sort sq_n1 and sq_n2 so that sq_n1 >= sq_n2
    sq_0 = np.max(sq_ns)
    sq_1 = np.min(sq_ns)
    assert np.allclose(sq_0, guess["sq_0"], atol=1.0e-2)
    assert np.allclose(sq_1, guess["sq_1"], atol=1.0e-2)
Esempio n. 7
0
 def model_2d(params, jpd_data):
     (dim_s, dim_i) = pd_data.shape
     joint_pmf = twinbeam_pmf(params, cutoff=cutoff)[:dim_s, :dim_i]
     return joint_pmf - jpd_data
Esempio n. 8
0
 def model_2d(params, jpd_data):
     (dim_s, dim_i) = pd_data.shape
     joint_pmf = twinbeam_pmf(params, cutoff=cutoff)
     return threshold_2d(joint_pmf, dim_s, dim_i) - threshold_2d(
         jpd_data, dim_s, dim_i)