Zach Lipp
30 October 2019
$whoamiScience is in a “reproducibility crisis”


What about us who don’t want our research reproduced?
If you are:
Can you still make unreproducible results?
import random
class ExtremelyRandomSeed:
@staticmethod
def _get_nondeterministic():
return random.randint(0, 100)
random.seedrandom.seed (Python<=3.8)class Random(_random.Random):
...
def seed(self, a=None, version=2):
"""Initialize internal state from hashable object.
...
base.pyimport random
class ExtremelyRandomSeed:
@staticmethod
def _get_nondeterministic():
return random.randint(0, 100)
class BaseSeed(ExtremelyRandomSeed):
def __hash__(self):
return self._get_nondeterministic()
if __name__ == "__main__":
seed = BaseSeed()
random.seed(seed)
print(random.random())
➜ python3 base.py
0.2718754143840908
➜ python3 base.py
0.7915259359614659
Same idea extends to the scientific Python stack:
numpy: __array__pytorch: __int__tensorflow>=2.0.0: __mod__Here’s a gist with a working example, more details coming soon
__<>__) methods are powerfulrandom.seed (Python>=3.9)class Random(_random.Random):
...
def seed(self, a=None, version=2):
...
elif not isinstance(a, (type(None), int, float, str, bytes, bytearray)):
_warn('Seeding based on hashing is deprecated\n'
'since Python 3.9 and will be removed in a subsequent '
'version. The only \n'
'supported seed types are: None, '
'int, float, str, bytes, and bytearray.',
DeprecationWarning, 2)