예제 #1
0
def test_exact_model_1d(n_modes, threshold, do_not_vary):
    """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 = 0.1
    eta = 0.7
    params = {"sq_" + str(i): sq_n[i] for i in range(n_modes)}
    params["n_modes"] = n_modes
    params["eta"] = eta
    params["noise"] = noise
    if threshold:
        probs = threshold_1d(degenerate_pmf(params), threshold)
    else:
        probs = degenerate_pmf(params)
    fit = fit_1d(probs, params, threshold=threshold, do_not_vary=do_not_vary)
    assert np.allclose(fit.chisqr, 0.0)
예제 #2
0
def test_marginal_calcs_1d():
    """Tests that marginal_calcs_1d returns the correct values as an array"""
    nmean = 1.0
    ps = degenerate_pmf({"n_modes": 1, "sq_0": nmean}, cutoff=100)
    assert np.allclose(
        marginal_calcs_1d(ps, as_dict=False), np.array([nmean, 3 + 1 / nmean, 15 + 9 / nmean])
    )
예제 #3
0
 def model_1d(params, pd_data):
     ndim = pd_data.shape[0]
     return (
         degenerate_pmf(params, cutoff=cutoff, sq_label=sq_label, noise_label=noise_label)[
             :ndim
         ]
         - pd_data
     )
예제 #4
0
def test_gen_hist_1d(sq_0):
    """Check that a histogram is constructed correctly for a degenerate squeezing source"""
    nsamples = 1_000_000
    q = 1.0 - np.tanh(np.arcsinh(np.sqrt(sq_0)))**2
    r = 0.5
    samples = 2 * np.random.negative_binomial(r, q, size=nsamples)
    nmax = max(samples)
    expected_pmf = degenerate_pmf({"sq_0": sq_0, "n_modes": 1}, cutoff=nmax)
    pmf = gen_hist_1d(samples)
    atol = 5 / np.sqrt(nsamples)
    assert np.allclose(pmf, expected_pmf, atol=atol)
예제 #5
0
def test_two_schmidt_mode_guess_exact(eta, sq_0, sq_1):
    """Test that one can invert correctly when there are two Schmidt modes
    and no dark counts
    """
    pmf = degenerate_pmf({"sq_0": sq_0, "sq_1": sq_1, "n_modes": 2, "eta": eta})
    guess = two_schmidt_mode_guess(pmf)
    assert np.allclose(eta, guess["eta"], atol=1.0e-2)
    sq_ns = [sq_0, sq_1]  # We need to sort sq_n0 and sq_n1 so that sq_n0 >= sq_n1
    sq_0 = np.max(sq_ns)
    sq_1 = np.min(sq_ns)
    assert np.allclose(sq_0, guess["sq_0"], atol=0.1)
    assert np.allclose(sq_1, guess["sq_1"], atol=0.1)
예제 #6
0
def test_degenerate_correct_stats(eta, sq_0, sq_1, noise):
    """Test that the g2 of a single mode degenerate squeezer is 3+1/n regardless of the loss, where n is the mean photon number"""
    params = {
        "n_modes": 2,
        "eta": eta,
        "noise": noise,
        "sq_0": sq_0,
        "sq_1": sq_1
    }
    ps = degenerate_pmf(params)
    vals = marginal_calcs_1d(ps)
    K = (sq_0 + sq_1)**2 / (sq_0**2 + sq_1**2)
    M = sq_0 + sq_1
    g2noiseless = 1.0 + 1.0 / M + 2.0 / K
    eps = noise / (eta * M)
    g2 = (g2noiseless + 2 * eps + eps**2) / (1 + 2 * eps + eps**2)
    assert np.allclose(vals["g2"], g2, atol=0.05)
    assert np.allclose(vals["n"], eta * M + noise, atol=0.05)
예제 #7
0
 def model_1d(params, pd_data):
     ndim = pd_data.shape[0]
     dpmf = degenerate_pmf(params, cutoff=cutoff)
     return threshold_1d(dpmf, ndim) - pd_data