Commit f82b084e authored by Martin Reinecke's avatar Martin Reinecke
Browse files

make sure that the RNG is in a reproducible state for every single test

parent 9020c956
Pipeline #71181 passed with stages
in 16 minutes and 58 seconds
......@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2019 Max-Planck-Society
# Copyright(C) 2013-2020 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
......@@ -24,3 +24,13 @@ def list2fixture(lst):
return request.param
return myfixture
def setup_function():
import nifty6 as ift
ift.random.push_sseq_from_seed(42)
def teardown_function():
import nifty6 as ift
ift.random.pop_sseq()
......@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2019 Max-Planck-Society
# Copyright(C) 2013-2020 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
......@@ -20,6 +20,7 @@ import pytest
import nifty6 as ift
from itertools import product
from .common import setup_function, teardown_function
# Currently it is not possible to parametrize fixtures. But this will
# hopefully be fixed in the future.
......@@ -124,11 +125,9 @@ def testPoissonian(field):
def test_bernoulli(field):
if isinstance(field.domain, ift.MultiDomain):
return
ift.random.push_sseq_from_seed(42)
field = field.sigmoid()
space = field.domain
d = ift.random.current_rng().binomial(1, 0.1, size=space.shape)
d = ift.Field(space, d)
energy = ift.BernoulliEnergy(d)
ift.extra.check_jacobian_consistency(energy, field, tol=1e-5)
ift.random.pop_sseq()
......@@ -20,6 +20,7 @@ import pytest
from numpy.testing import assert_allclose, assert_equal, assert_raises
import nifty6 as ift
from .common import setup_function, teardown_function
pmp = pytest.mark.parametrize
SPACES = [ift.RGSpace((4,)), ift.RGSpace((5))]
......
......@@ -19,6 +19,7 @@ import numpy as np
import pytest
import nifty6 as ift
from .common import setup_function, teardown_function
def _flat_PS(k):
......
......@@ -20,6 +20,7 @@ import numpy as np
import nifty6 as ift
from numpy.testing import assert_, assert_allclose
import pytest
from .common import setup_function, teardown_function
pmp = pytest.mark.parametrize
......
......@@ -20,6 +20,7 @@ import pytest
from numpy.testing import assert_, assert_allclose
import nifty6 as ift
from .common import setup_function, teardown_function
pmp = pytest.mark.parametrize
......
......@@ -22,6 +22,7 @@ import pytest
from numpy.testing import assert_allclose, assert_equal
import nifty6 as ift
from .common import setup_function, teardown_function
pmp = pytest.mark.parametrize
IC = ift.GradientNormController(tol_abs_gradnorm=1e-5, iteration_limit=1000)
......@@ -119,7 +120,6 @@ def test_rosenbrock(minimizer):
from scipy.optimize import rosen, rosen_der, rosen_hess_prod
except ImportError:
raise SkipTest
ift.random.push_sseq_from_seed(42)
space = ift.DomainTuple.make(ift.UnstructuredDomain((2,)))
starting_point = ift.Field.from_random('normal', domain=space)*10
......@@ -171,7 +171,6 @@ def test_rosenbrock(minimizer):
assert_equal(convergence, IC.CONVERGED)
assert_allclose(energy.position.val, 1., rtol=1e-3, atol=1e-3)
ift.random.pop_sseq()
@pmp('minimizer', minimizers + slow_minimizers)
......
......@@ -19,6 +19,7 @@ import numpy as np
from numpy.testing import assert_allclose, assert_equal
import nifty6 as ift
from .common import setup_function, teardown_function
dom = ift.makeDomain({"d1": ift.RGSpace(10)})
......
......@@ -20,7 +20,7 @@ import pytest
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
_h_RG_spaces = [
ift.RGSpace(7, distances=0.2, harmonic=True),
......
......@@ -19,7 +19,7 @@ from numpy.testing import assert_allclose, assert_equal
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
space1 = list2fixture([
ift.RGSpace(4),
......
......@@ -20,7 +20,7 @@ from numpy.testing import assert_allclose
import nifty6 as ift
import numpy as np
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
space = list2fixture([
ift.RGSpace(4),
......
......@@ -19,6 +19,7 @@ import pytest
from numpy.testing import assert_allclose
import nifty6 as ift
from ..common import setup_function, teardown_function
@pytest.mark.parametrize('sspace', [
......
......@@ -19,7 +19,7 @@ from numpy.testing import assert_allclose, assert_equal
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
space = list2fixture([
ift.RGSpace(4),
......
......@@ -21,7 +21,7 @@ from numpy.testing import assert_, assert_allclose
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
def _get_rtol(tp):
......
......@@ -21,7 +21,7 @@ from numpy.testing import assert_allclose
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
def _get_rtol(tp):
......
......@@ -22,7 +22,7 @@ from scipy.stats import invgamma, norm
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
pmp = pytest.mark.parametrize
pmp = pytest.mark.parametrize
......
......@@ -20,7 +20,7 @@ import pytest
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
pmp = pytest.mark.parametrize
space = list2fixture([
......
......@@ -20,6 +20,7 @@ import pytest
from numpy.testing import assert_
import nifty6 as ift
from ..common import setup_function, teardown_function
pmp = pytest.mark.parametrize
......
......@@ -21,7 +21,7 @@ from numpy.testing import assert_, assert_allclose
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
pmp = pytest.mark.parametrize
dtype = list2fixture([np.float64, np.float32, np.complex64, np.complex128])
......
......@@ -19,7 +19,7 @@ from numpy.testing import assert_allclose
import nifty6 as ift
from ..common import list2fixture
from ..common import list2fixture, setup_function, teardown_function
s = list2fixture([
ift.RGSpace(8, distances=12.9),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment