Skip to content
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

Device random number generation #1327

Closed
albi3ro opened this issue May 17, 2021 · 1 comment
Closed

Device random number generation #1327

albi3ro opened this issue May 17, 2021 · 1 comment

Comments

@albi3ro
Copy link
Contributor

albi3ro commented May 17, 2021

Currently, PennyLane devices use legacy numpy random number generation, see NumPy documentation and PR #1267. In particular, this random number generation occurs on _qubit_device.py Line 484.

So that multiple devices and outside random number generation don't interfere with the reproducibility of a given device, we should assign each simulator device a Generator and pull random numbers from that generator.

To implement this:

  1. QubitDevice initialization accepts a optional seed keyword. This seed can be anything accepted by pennylane.numpy.random.default_rng(seed).

  2. Initialization of device creates a _rng attribute from provided seed.

  3. A new method, reset_rng(seed), redefines the _rng attribute with a new seed.

  4. Any random number generator (Line 484) pulls from _rng.

  5. Update documentation for QubitDevice and inheriting devices in pennylane/devices

  6. Write tests

As this is only possible for NumPy v1.17.0 onward, this may require consideration about versioning. According to NumPy's deprecation recommendations, support for version 1.16.0 and earlier could have been dropped Jan 13, 2021, so we may be fine.

@albi3ro
Copy link
Contributor Author

albi3ro commented Sep 22, 2023

The new default.qubit uses a local random number generator and accepts a seed argument. I'm going to mark this issue as closed.

@albi3ro albi3ro closed this as completed Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant