-
Notifications
You must be signed in to change notification settings - Fork 983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return unrecognized random state unmodified #2622
Conversation
@kevinsung Do you envision the PRNGs people use being written specifically for Cirq or from a general package? I think a PRNG abstract class would be better than allowing anything, but it would require a Cirq-specific implementation (or at least a wrapper). |
I have an application where the PRNG is not related to Cirq but can be used as a substitute for a RandomState in appropriate situations. |
Gotchya. In that case, we might as well just set |
elif isinstance(random_state, int): | ||
return np.random.RandomState(random_state) | ||
raise TypeError(f'Argument must be of type cirq.value.RANDOM_STATE_LIKE.') | ||
else: | ||
return cast(np.random.RandomState, random_state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check for one of the expected methods as a safety. Otherwise very pythonic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further thought, I'd prefer not to make any such check. The user should not be forced to implement any particular method; she should only have to implement the ones that she knows are needed for her use case. For instance, the Cirq simulator only uses prng.choice
, while the supremacy circuit generation code only uses prng.random
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our offline conversation, I have added documentation to RANDOM_STATE_LIKE
and left this alone.
Automerge cancelled: Need a fresh 🍪. |
Automerge cancelled: The automerge label was removed. |
This allows people to use their own custom pseudorandom number generator implementations.