Commit 4827c1bd authored by Philipp Arras's avatar Philipp Arras
Browse files

Seed-related bug in numpy has been fixed

parent 16827157
Pipeline #105816 passed with stages
in 21 minutes and 22 seconds
......@@ -48,8 +48,8 @@ setup(name="nifty8",
packages=find_packages(include=["nifty8", "nifty8.*"]),
setup_requires=['scipy>=1.4.1', 'numpy>=1.17'],
install_requires=['scipy>=1.4.1', 'numpy>=1.17'],
setup_requires=['scipy>=1.4.1', 'numpy>=1.19'],
install_requires=['scipy>=1.4.1', 'numpy>=1.19'],
"Development Status :: 5 - Production/Stable",
......@@ -78,17 +78,10 @@ objects, generate new ones via :func:`spawn_sseq()`.
import numpy as np
# fix for numpy issue #16539
def _fix_seed(seed):
if isinstance(seed, int):
return (seed, 0, 0, 0)
raise TypeError("random seed should have integer type")
# Stack of SeedSequence objects. Will always start out with a well-defined
# default. Users can change the "random seed" used by a calculation by pushing
# a different SeedSequence before invoking any other nifty8.random calls
_sseq = [np.random.SeedSequence(_fix_seed(42))]
_sseq = [np.random.SeedSequence(42)]
# Stack of random number generators associated with _sseq.
_rng = [np.random.default_rng(_sseq[-1])]
......@@ -204,7 +197,7 @@ def push_sseq_from_seed(seed):
In all other situations, it is highly recommended to use the
:class:`Context` class for managing the RNG state.
......@@ -284,7 +277,7 @@ class Context:
def __init__(self, inp):
if not isinstance(inp, np.random.SeedSequence):
inp = np.random.SeedSequence(_fix_seed(inp))
inp = np.random.SeedSequence(inp)
self._sseq = inp
def __enter__(self):
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