-
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
Improved handling for Identities on no wires #5570
Conversation
Awesome! Seems to fix my issues with qnodes that compute expectation values with CompositeOps that contain I() instances 👌
|
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.
Awesome, thanks so much @albi3ro
Just missing one integration test with a qnode perhaps? Otherwise happy to approve!
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.
One minor point about straight I()
not being allowed to be measured
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.
Great PR, thanks so much for the fix @albi3ro ! 🥂
My main concern of Hamiltonians/Sums containing I() being able to be handled is solved with this 👍
Would be good to also be able to directly measure I() as well, but for the moment this will do!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5570 +/- ##
==========================================
- Coverage 99.69% 99.68% -0.01%
==========================================
Files 410 411 +1
Lines 38278 38030 -248
==========================================
- Hits 38161 37912 -249
- Misses 117 118 +1 ☔ View full report in Codecov by Sentry. |
**Context:** In the latest run of legacy opmath tests: https://github.com/PennyLaneAI/pennylane/actions/runs/8837734136/job/24267397281, a newly added device test from #5570 is failing because `expval` of `Hamiltonian` containing `Identity` with no wires is not supported. **Description of the Change:** Update the test case to explicitly use `qml.sum` instead of the `+` operator. **Benefits:** Fixes failure in legacy opmath tests. **Possible Drawbacks:** `Hamiltonian` with `I()` is still not supported.
Context:
While we have added the ability to have
qml.I()
on no wires to better reflect the wire-independent nature of the identity and create operations again from a simplified form, we don't necessarily have extensive support and coverage for this new style of observable yet.Description of the Change:
This PR extends support for
qml.I()
fordevices.qubit
measurement pathwaysmeasure
andmeasure_with_samples
. It also allows us to calculate the eigenvalues for composite ops that contain an operator on no wires. And finally, it adds support for observables with no wires toqml.pauli.group_observables
.Throughout, I assume an observable with no wires commutes with everything, as
qml.I
does in fact commute with everything.Benefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-61509] Fixes #5532