Add support for numpy.random.Generator

Open
#8,374 23 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@arettig is already working on this.

Since Oct 1, 2026.

Assessment

This issue has not been assessed yet.

Description

good first issue kind/feature-request kind/health triage/accepted

Is your feature request related to a use case or problem? Please explain

np.RandomState has been effectively deprecated by numpy but it is still used throughout much of Cirq. Additionally, when multiple threads are used, RandomState also becomes a shared object, causing blocking between threads.

Describe the solution you would prefer

We should instead use numpy.random.Generator, the modern approach. We should provide a separate path for generating random numbers with Generators and ensure multithreading support. The old RandomState based paths may then be deprecated. Per previous work on this issue, the general approach should be:

  • A new type such as PRNG_OR_SEED_LIKE should be added, allowing for either a generator or a seed.
  • parse_random_generator should be added, which returns a np.random.Generator.
  • Existing calls to parse_random_state within cirq should be replaced with parse_random_generator.
  • parse_random_state should be deprecated.
  • Remove standalone references to RandomState

How urgent is this for you? Is it blocking important work?

P2 – we should do it in the next couple of quarters

Provide additional information or context (e.g., screenshots)

This is an amalgamation of the discussion and conclusions reached within several issues and PRs: #6566, #6531, #6321, #8184

Related: #6567

Dominant language
Python
Stars
5.1k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
48

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quantumlib/Cirq

All issues in quantumlib/Cirq

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.