Closed thomasjpfan closed 7 months ago
When using the random state for parallel processing, do we need the private API?
https://github.com/scientific-python/blog.scientific-python.org/blob/b51e4b9df0ea5fd740b0f04c43ab432388deed21/content/posts/numpy/numpy-rng/index.md?plain=1#L108
From my understanding, we can use the public API:
import numpy as np from joblib import Parallel, delayed def stochastic_function(high=10, rng=None): if not isinstance(rng, np.random.Generator): rng = np.random.default_rng(rng) return rng.integers(high, size=5) seed = 319929794527176038403653493598663843656 rng = np.random.default_rng(seed) child_states = rng.spawn(5) random_vector = Parallel(n_jobs=2)( delayed(stochastic_function)(rng=random_state) for random_state in child_states ) print(random_vector) random_vector = Parallel(n_jobs=2)( delayed(stochastic_function)(rng=random_state) for random_state in child_states ) print(random_vector)
CC @albertcthomas
xref: https://github.com/scientific-python/blog.scientific-python.org/pull/135#discussion_r1470002426
Yes thanks @thomasjpfan ! I will do the PR today :)
When using the random state for parallel processing, do we need the private API?
https://github.com/scientific-python/blog.scientific-python.org/blob/b51e4b9df0ea5fd740b0f04c43ab432388deed21/content/posts/numpy/numpy-rng/index.md?plain=1#L108
From my understanding, we can use the public API:
CC @albertcthomas