-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
qml.expval
to correctly cast value type (#6939)
**Context:** Prior to this PR we had the expectation value being silently converted to a real type, ```python obs = (0.2 + 0.7j) * qml.PauliZ(0) @qml.qnode(qml.device("default.qubit", 1)) def qnode(): return qml.expval(obs) >>> qnode() 0.2 ``` **Description of the Change:** This PR stops casting to a real number when calculating expval and instead casts to whatever the eigenvalue type is. **Benefits:** Code is now correct with the following behaviour, ```python obs = (0.2 + 0.7j) * qml.PauliZ(0) @qml.qnode(qml.device("default.qubit", 1)) def qnode(): return qml.expval(obs) >>> qnode() (0.2+0.7j) ``` **Possible Drawbacks:** The math is now correct, but this result is non-physical. However, after some discussion we do not want to support silently type casting and instead leave this to the researchers. **Related GitHub Issues:** Fixes #6076 [sc-70629] --------- Co-authored-by: Yushao Chen (Jerry) <chenys13@outlook.com>
- Loading branch information
1 parent
e0b2174
commit 67fbcba
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters