Passing a random number generator to simulator/sampler methods should VS maintaing an internal random state #6567
Labels
good first issue
This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.
kind/design-issue
A conversation around design
triage/accepted
A consensus emerged that this bug report, feature request, or other action should be worked on
All Cirq simulators maintain an internal
np.random.RandomState
Cirq/cirq-core/cirq/sim/sparse_simulator.py
Line 130 in e1b03ef
This is fine when running in a single thread, however we are starting to have more places where use multiprocessing/multithreads (e.g. using
multiprocessing.Pool
,concurrent.futures.ThreadPoolExecutor
, or other multiprocessing/multithreading libraries) and in these cases this internal random state negatively affects the simulations in two waysSuggested solution: Start to prefer passing
prng
s to methods/functions over maitaining an internal state. thisprng
should be annp.random.Generator
instead of annp.random.RandomState
so that we get aspawn
method to use when starting threads/processes.related: #6531
The text was updated successfully, but these errors were encountered: