-
Notifications
You must be signed in to change notification settings - Fork 603
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
Add rng
and prng_key
to get_final_state
, apply_operation
#5337
Conversation
[sc-58258] |
### Before submitting Please complete the following checklist when submitting a PR: - [x] All new features must include a unit test. If you've fixed a bug or added code that should be tested, add a test to the test directory! - [x] All new functions and code must be clearly commented and documented. If you do make documentation changes, make sure that the docs build and render correctly by running `make docs`. - [x] Ensure that the test suite passes, by running `make test`. - [x] Add a new entry to the `doc/releases/changelog-dev.md` file, summarizing the change, and including a link back to the PR. - [x] The PennyLane source code conforms to [PEP8 standards](https://www.python.org/dev/peps/pep-0008/). We check all of our code against [Pylint](https://www.pylint.org/). To lint modified files, simply `pip install pylint`, and then run `pylint pennylane/path/to/file.py`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** JAX RNG keys should not be reused (in production) according to the JAX documentation. The current usage only split the keys at the lowest level (`_sample_state_jax`). This could cause unwanted correlations. For example, we reuse the device key for each tape in a batch of tapes in `default.qubit`. **Description of the Change:** Add functions and methods to split RNG keys. Split RNG keys to avoid reusing keys. **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** #5337 [sc-61435]
Just testing out updating the durations file again. Before updating, this CI run had the following core test durations: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5337 +/- ##
==========================================
- Coverage 99.69% 99.69% -0.01%
==========================================
Files 410 412 +2
Lines 38278 38188 -90
==========================================
- Hits 38161 38070 -91
- Misses 117 118 +1 ☔ View full report in Codecov by Sentry. |
The new timings are: 11, 22, 21, 21, 24 minutes. |
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.
Looks good to me 🚀 Just a couple of quick comments/questions!
Context:
The seed provided to
DefaultQubit
during initialization is only used for measurements. However, we now have uses for it while applying operations, specifically with applying mid-circuit measurements withdynamic_one_shot
, and updating the number of shots with postselection withdefer_measurements
. This PR updatesdevices.qubit.simulate.get_final_state
anddevices.qubit.apply_operation
to use the RNG/PRNGKey provided during device initialization for stochastic behaviour.Description of the Change:
rng
andprng_key
arguments toget_final_state
and theMidMeasureMP
dispatcher ofapply_operation
.appy_operation
now uses the rng/PRNGKey to sample the measurement outcome.rng
andprng_key
arguments to_postselection_postprocess
. This function is used for renormalizing the state after aProjector
is applied to it, as well as to update the number of shots if provided. This function now uses the rng/PRNGKey to update shots using the binomial distribution.default.qubit
now set a seed on the device. With this change, I also removedflaky
from all the native MCM tests and instead increased the number of shots for the tests that were still failing.get_final_state
andapply_operation
to accept**execution_kwargs
arguments, which hiderng
,prng_key
,interface
, andmid_measurements
. All of these arguments impact execution outcomes, hence why they were collected. This also means that all of those arguments are now strictly keyword arguments and can no longer be passed to the functions as positional arguments.Benefits:
Possible Drawbacks:
Related GitHub Issues: