コード例 #1
0
ファイル: test_inference.py プロジェクト: sid1993/mitiq
def test_linear_extr():
    """Tests extrapolation with a LinearFactory."""
    seeded_f = apply_seed_to_func(f_lin, SEED)
    fac = LinearFactory(X_VALS)
    assert not fac._opt_params
    fac.run_classical(seeded_f)
    assert np.isclose(fac.reduce(), seeded_f(0, err=0), atol=CLOSE_TOL)
    assert np.allclose(fac._opt_params, [B, A], atol=CLOSE_TOL)
コード例 #2
0
ファイル: test_inference.py プロジェクト: TripleR47/mitiq
def test_linear_extr():
    """Tests extrapolation with a LinearFactory."""
    seeded_f = apply_seed_to_func(f_lin, SEED)
    fac = LinearFactory(X_VALS)
    assert not fac._opt_params
    fac.run_classical(seeded_f)
    zne_value = fac.reduce()
    assert np.isclose(zne_value, seeded_f(0, err=0), atol=CLOSE_TOL)
    assert np.allclose(fac._opt_params, [B, A], atol=CLOSE_TOL)
    exp_vals = fac.get_expectation_values()
    assert np.isclose(fac.extrapolate(X_VALS, exp_vals), zne_value)
    assert np.isclose(
        fac.extrapolate(X_VALS, exp_vals, full_output=True)[0], zne_value,
    )