-
Notifications
You must be signed in to change notification settings - Fork 605
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
State that Evolution
has matrix if target is Hamiltonian
#4768
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4768 +/- ##
==========================================
- Coverage 99.64% 99.64% -0.01%
==========================================
Files 381 381
Lines 34305 34048 -257
==========================================
- Hits 34184 33926 -258
- Misses 121 122 +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.
Looks good to me! 🎉
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
We discovered a difference between `default.qubit` and `default.qubit.legacy` over their treatment of the evolution of hamiltonians: ```python dev = qml.device('default.qubit', wires=3) coeffs = [0.1, 0.2] operators = [qml.PauliZ(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliZ(2)] hamiltonian = qml.Hamiltonian(coeffs, operators) @qml.qnode(dev) def f(): qml.evolve(hamiltonian, 0.5) return qml.density_matrix([0]) f() ``` Previously `qml.evolve(hamiltonain, t)` worked because `Evolution` was hardcoded as an accepted observable. This meant it became an accepted operation as well, even though it stated it didn't have a matrix. In `ScalarSymbolicOp`, the parent for `Evolution`, we added a special logical pathway for the matrix if the target is a Hamiltonian, but we didn't include that special logical pathway for the `has_matrix` property. This PR updates the `has_matrix` property for and allows the evolution of a hamiltonian to execute on `default.qubit`. **Warning:** This matrix is not backprop compatible. ``` dev = qml.device('default.qubit.legacy', wires=3) coeffs = [0.1, 0.2] operators = [qml.PauliZ(0) @ qml.PauliZ(1), qml.PauliZ(0) @ qml.PauliZ(2)] @qml.qnode(dev) def f(x): hamiltonian = qml.Hamiltonian(x, operators) qml.evolve(hamiltonian, 0.5) return qml.density_matrix([0]) qml.grad(f)(qml.numpy.array(coeffs)) ``` Gives ``` AttributeError: 'ArrayBox' object has no attribute 'tocsr' ``` `qml.dot` and operator arithemetic does not have these problems. --------- Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
**Context:** These three bugs were identified as good to be released in a bugfix. **Description of the Change:** Cherry-pick the 3 commits to master onto this branch for the 0.33.1 bugfix release **Benefits:** Fixed bugs pushed out! **Possible Drawbacks:** Extra work in a critical time. **Related GitHub Issues:** #4768, #4781, #4787 --------- Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com> Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
[sc-50818] |
We discovered a difference between
default.qubit
anddefault.qubit.legacy
over their treatment of the evolution of hamiltonians:Previously
qml.evolve(hamiltonain, t)
worked becauseEvolution
was hardcoded as an accepted observable. This meant it became an accepted operation as well, even though it stated it didn't have a matrix.In
ScalarSymbolicOp
, the parent forEvolution
, we added a special logical pathway for the matrix if the target is a Hamiltonian, but we didn't include that special logical pathway for thehas_matrix
property.This PR updates the
has_matrix
property for and allows the evolution of a hamiltonian to execute ondefault.qubit
.Warning:
This matrix is not backprop compatible.
Gives
qml.dot
and operator arithemetic does not have these problems.