Hermitian observables and (avoiding) diagonalization of (large) matrices
See original GitHub issueFeature details
This is half a question and half a feature / documentation request.
One issue with the qml.Hermitian observable is that (at least when running on default.qubit) its .matrix is diagonalized (via .diagonalizing_gates) even to compute return values such as qml.expval(qml.Hermitiaion(...)) and qml.var(qml.Hermitiaion(...)), which could be computed via a simple matrix vector (inner)products. This is already not ideal performance wise when the qml.Hermitian observable acts on few wires, but gets worse exponentially for large number of wires.
Looking into DefaultQubit.expval() I get the impression that for qml.Hamiltonian and qml.SparseHamiltonian this diagonalization is avoided.
So, am I right that wrapping a qml.Hermitian observable in a qml.Hamiltonian (as also discussed here) avoids the diagonalization?
- Maybe it would be worth explaining this to users?
- Maybe the same trick could be enabled to also speed up
var()? - Maybe this wrapping, which is counter intuitive and difficult to explain to users could be avoided altogether by calculating the diagonalizing gates of
qml.Hermitianonly when the user executes aQNodewith a return type that requires diagonalization such asqml.probs()but not forexpvalorvar?
Implementation
No response
How important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)

Top Related StackOverflow Question
This is also related to #1344
Agree, but
tape.diagonalizing_gatesis not part of the public API, isn’t it? So breaking is not an issue here.