Add support for numpy.random.Generator
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
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_LIKEshould be added, allowing for either a generator or a seed. -
parse_random_generatorshould be added, which returns anp.random.Generator. - Existing calls to
parse_random_statewithin cirq should be replaced withparse_random_generator. -
parse_random_stateshould 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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantumlib/Cirq
-
Potential missed optimization: `drop_diagonal_before_measurement` leaves an identity `PhasedXZGate` that blocks further removalPossibly taken @jangyoujin0917 claimed this 22 days ago. Openarea/gates area/optimization kind/feature-request triage/accepted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quantumlib/Cirq#8523 · 1 comment ·
Maintainers usually reply within 1 day
-
`defer_measurements` ignores `BitMaskKeyCondition.index` and changes circuit behaviorMay be free again @Tejendra-06 claimed this 54 days ago, and no pull request is open. Opengood for learning help wanted kind/bug-report skill/experienced triage/accepted triage/wont-fix
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
quantumlib/Cirq#8361 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
kind/feature-request triage/discuss
quantumlib/Cirq#8598 ·
Maintainers usually reply within 1 day
-
area/docstrings area/google kind/bug-report triage/discuss
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
quantumlib/Cirq#8587 ·
Maintainers usually reply within 1 day
-
kind/bug-report triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
quantumlib/Cirq#8580 ·
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day