-
Notifications
You must be signed in to change notification settings - Fork 617
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
[BUG] Grouping of measurements is inconsistent between legacy and new opmath #5512
Closed
1 task done
Labels
bug 🐛
Something isn't working
Comments
Thanks @lillian542!
This looks like a priority to fix before the 0.36 release. |
lillian542
added a commit
that referenced
this issue
Apr 17, 2024
Currently, the tests only run with the new opmath, so won't know if we introduced a bug that breaks the legacy opmath behaviour while it is still in its deprecation cycle. This PR creates a kwarg, `disable-opmath`, that can be passed when running the tests, and a corresponding workflow that runs tests with that kwarg set to True. This can also be used locally, i.e. `python -m pytest tests/ --disable-opmath=True` Right now, it runs with CI on the PR, but once the tests are all passing, the line triggering that will be removed and it will only run every 3-4 days, in the middle of the night. Then we will add it to the test matrix (separate PR to modify the plugin test matrix repo). The changes to .yml files and to the `conftest` files are all about allowing us to run these additional tests. A few modifications to tests were made to allow them to pass with both legacy opmath and new opmath. There is one test currently marked as xfail for new opmath that I would call a bug - I opened an issue here: #5512 --------- Co-authored-by: Mudit Pandey <[email protected]> Co-authored-by: qottmann <[email protected]>
astralcai
added a commit
that referenced
this issue
Apr 21, 2024
…miltonian (#5525) **Context:** The `_group_measurements` function in `qubit/sampling.py` groups measurement processes with commuting observables together to reduce the number of executions. Now it does not handle `Prod`, `SProd` or single-term `Hamiltonian` and `Sum`, which leads to inefficiencies with new opmath. **Description of the Change:** Removes the branch that places `Prod`, `SProd`, `Hamiltonian` and `Sum` in separate groups. Now `is_pauli_word` is used for everything. **Benefits:** Better grouping leads to fewer number of executions. **Related GitHub Issues:** Fixes #5512 [sc-61306]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
That
measurements=[qml.expval(qml.PauliX(0)), qml.expval(qml.PauliY(0)@qml.PauliX(1)]
would be grouped the same and be tracked as requiring the same number of executions to measure regardless of whether the observables wereTensor
orProd
instances.Actual behavior
There is a separate clause for grouping new opmath instances that causes mathematically identical measurements to be grouped differently. The legacy behaviour seems preferable and results in fewer executions.
Additional information
The issue arises in
pennylane.device.qubit.sampling._group_measurements
. It was found in a test for the tracker that passes with Legacy opmath but not with the new opmath, but it appears to be genuinely increasing the number of executions run, not just incorrectly counting in the tracker.There is an xfailed test in
test_default_qubit_tracker.py
that should pass (i.e. fail due to strict xfail) once this is resolved.Source code
Tracebacks
No response
System information
Existing GitHub issues
The text was updated successfully, but these errors were encountered: