Closed minhtriet closed 3 months ago
Thanks for opening this issue @minhtriet . While our legacy Hamiltonian class never defined a matrix, our new analogues Sum
and LinearCombination
do. So you should be able to do the above on master
now!
I would just be aware that computing the matrix via H.matrix()
could get expensive for larger systems. In those cases, H.sparse_matrix()
might be a more performant alternative if you do not need to preserve differentiability.
Additionally, qml.matrix(H)
should work in this case.
On PennyLane 0.35.1, the following code prints a 16x16 matrix.
import pennylane as qml
h2_dataset = qml.data.load("qchem", molname="H2", bondlength=0.742, basis="STO-3G")
h2 = h2_dataset[0]
H, qubits = h2.hamiltonian, len(h2.hamiltonian.wires)
print(qml.matrix(H))
@minhtriet Mind if we close this issue?
Feature details
When running
We will have
pennylane.operation.MatrixUndefinedError
Implementation
I have a working implementation that works on the above example.
Here is the Hamilton of
H2
We cannot add the matrix of
Z2
withY0 Y1 X2 X3
, so the main idea is forZ(2)
, we convert intoI(0) @ Z(1) @ I(1) @ I(2)
, and do the same for every Hamiltonian operator in the listDraft implementation
How important would you say this feature is?
2: Somewhat important. Needed this quarter.
Additional information
No response