[MRG] Support RandomState instances in NumpyBackend.seed - #849
Open
CunjieLee wants to merge 2 commits into
Open
Conversation
CunjieLee
marked this pull request as ready for review
September 7, 2026 14:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Motivation and context / Related issue
Closes #848.
NumpyBackend.seed()currently forwards every non-Nonevalue toRandomState.seed(). Passing an existingnp.random.RandomStateinstance therefore raises:
This forces callers that support both integer seeds and existing
RandomStateinstances to special-case the NumPy backend.This change makes
NumpyBackendadopt an externally suppliedRandomState, matching the generator-handling behavior of the otherbackends. The NumPy-specific
RandomStatebranches in the slicedsampling utilities are removed accordingly.
The fourth occurrence mentioned in #848, in
get_projections_spiral,belongs to the still-open PR #838 and is not present on the current
masterbranch. That occurrence can use the unified backend path oncethis fix is incorporated into #838.
How has this been tested (if it applies)
The issue was reproduced on the unmodified
masterbranch using:The original code raises the reported
TypeError.The same code succeeds after the fix. Additional verification confirms
that:
NumpyBackend.rng_is the exact suppliedRandomStateinstance;nx.randn(...)calls use that generator's sequence;A regression test was added in
test/test_backend.py.The following checks pass:
The full test run completed with 1456 passed, 96 skipped, and 4 xfailed.
The skipped tests require optional dependencies that are not installed in
the local test environment.
PR checklist