Skip to content

Passing a random number generator to simulator/sampler methods should VS maintaing an internal random state #6567

Open
@NoureldinYosri

Description

All Cirq simulators maintain an internal np.random.RandomState

seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,

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 ways

  • the internal random state becomes a shared state that causes the different threads/processes blocked on each other.
  • the results of simulations become correlated.

Suggested solution: Start to prefer passing prngs to methods/functions over maitaining an internal state. this prng should be an np.random.Generator instead of an np.random.RandomState so that we get a spawn method to use when starting threads/processes.

related: #6531

Metadata

Assignees

No one assigned

    Labels

    good first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/design-issueA conversation around designtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions