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
Allow Identity()
to have no wires
#5106
Conversation
Hello. You may have forgotten to update the changelog!
|
[sc-55334] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5106 +/- ##
==========================================
- Coverage 99.69% 99.68% -0.01%
==========================================
Files 394 394
Lines 35979 35711 -268
==========================================
- Hits 35868 35599 -269
- Misses 111 112 +1 ☔ View full report in Codecov by Sentry. |
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.
Mind adding some integration tests with "default.qubit"
? We might also want to make an associated test to the lightning repo adding an integration test for support for qml.Identity()
.
For the moment, we don't allow measuring |
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.
What will the repr look like for qml.Identity()
?
Co-authored-by: Christina Lee <christina@xanadu.ai>
…o identitynowires
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.
This may require some follow up work, both with hamiltonian_expand
, and sum_expand
and unknown unknowns, but I definitely think this will help in working in working with pauli sentences.
…ylane into identitynowires
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 great! left an optional comment, but otherwise good to go
@@ -153,6 +153,9 @@ | |||
and the codecov check itself would never execute. | |||
[(#5101)](https://github.com/PennyLaneAI/pennylane/pull/5101) | |||
|
|||
* `qml.Identity()` can be initialized without wires. Measuring it is currently not possible though. |
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.
Does that include something like qml.expval(qml.PauliX(0) @ qml.Identity())
or just strictly qml.expval(qml.Identity())
?
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.
Good point, this case is in fact not handled. Though it should also not appear accidentally since Identities are stripped from PauliWords upon initialization:
>>> pw = PauliWord({0:"X", 1:"I"})
>>> pw
X(0)
>>> pw.operation()
PauliX(wires=[0])
It could occur with still if a user specifically tries to compute qml.expval(qml.PauliX(0) @ qml.Identity())
though 😬 Luckily, a fix to handle empty-wire Identities is under way already anyway.
Allows
Identity()
to have no wires, similar to e.g.GlobalPhase
Also updating
PauliWord.operation()
to returnqml.Identity()
andPauliSentence.operation()
to returnqml.s_prod(0, qml.Identity())
in case of empty word and sentence, respectively.As a temporary fix, we explicitly dont allow expvals of
Identity()
, but plan to fix this by updating hamiltonian_expand and sum_expand immediately after.