def run(function, queue, indices, rseed, *args): # randomize np_seed(rseed) py_seed(rseed) # compute and store results queue.put(dict(zip(indices, map(function, *args))))
def run(function, queue, idx, rnd, *args): """ A helper function for handling return values. Takes a function and its arguments and stores its result in a queue. @type function: function @param function: handle to function that will be called @type queue: Queue @param queue: stores returned function values @type idx: integer @param idx: index used to identify return values @type rnd: float @param rnd: a random number to seed random number generator """ # compute random seed rnd_seed = int(1e6 * rnd + 1e6 * time()) # without it, different processes are likely to use the same seed numpy_seed(rnd_seed) py_seed(rnd_seed) # evaluate function queue.put((idx, function(*args)))
def set_seeds(): # set all random seeds import tensorflow as tf from numpy.random import seed as np_seed from random import seed as py_seed from snorkel.utils import set_seed as snork_seed snork_seed(123) tf.random.set_seed(123) np_seed(123) py_seed(123)