def test_map_to_fakenodes(): """Test the fake nodes map in FakeNodesFactory.""" fac = FakeNodesFactory(UNIFORM_X) test_argument = 1.0 assert np.isclose( fac._map_to_fake_nodes([1.0], 2.0, test_argument), [1.0], )
def test_fake_nodes_factory(): """Test FakeNodesFactory in a specific regime in which the fake nodes interpolation method works well. """ fac = FakeNodesFactory(UNIFORM_X) assert not fac._opt_params fac.run_classical(f_runge) zne_value = fac.reduce() assert np.isclose(zne_value, f_runge(0.0), atol=LARGE_TOL) assert len(fac._opt_params) == len(UNIFORM_X) assert np.isclose(fac._opt_params[-1], zne_value)
def test_fakenodes_scale_factors_equally_spaced(): """FakeNodesFactory should only accept equally spaced scale factors.""" y_vals = [0.5, 1.0, 1.5] with raises( ValueError, match=r"The scale factors must be equally spaced." ): _ = FakeNodesFactory(X_VALS).extrapolate(X_VALS, y_vals)
def test_fake_nodes_extrapolation(): """Test that there exists a regime in which FakeNodesFactory is better than RichardsonFactory. Note: in many cases RichardsonFactory is better. """ y_vals = [f_runge(x) for x in UNIFORM_X] zne_runge = FakeNodesFactory.extrapolate(UNIFORM_X, y_vals) zne_richard = RichardsonFactory.extrapolate(UNIFORM_X, y_vals) abs_err_runge = np.abs(zne_runge - f_runge(0.0)) abs_err_richard = np.abs(zne_richard - f_runge(0.0)) # Test Richardson extrapolation error is much larger assert 500 * abs_err_runge < abs_err_richard
def test_fake_nodes_factory(): """Test FakeNodesFactory in a specific regime in which the fake nodes interpolation method works well. """ fac = FakeNodesFactory(UNIFORM_X) assert not fac._opt_params fac.run_classical(f_runge) zne_value = fac.reduce() assert np.isclose(zne_value, f_runge(0.0), atol=LARGE_TOL) assert len(fac._opt_params) == len(UNIFORM_X) assert np.isclose(fac._opt_params[-1], zne_value) assert np.isclose(fac.extrapolate(UNIFORM_X, f_runge(UNIFORM_X)), zne_value) exp_vals = fac.get_expectation_values() assert np.isclose(fac.extrapolate(UNIFORM_X, exp_vals), zne_value) assert np.isclose( fac.extrapolate(UNIFORM_X, exp_vals, full_output=True)[0], zne_value, )