Closed mlxd closed 2 years ago
If wires
aren't passed to qml.utils.sparse_hamiltonian
, it assumes that the only wires are those in the Hamiltonian
, which in this case is only two.
Providing wires to that function fixes the problem:
import pennylane as qml
dev = qml.device("default.qubit", wires=4)
Hmat = qml.utils.sparse_hamiltonian( 1.1 * qml.PauliX(wires=0) @ qml.PauliZ(wires=2) , wires=(0,1,2,3))
@qml.qnode(dev, diff_method="parameter-shift")
def circuit():
qml.PauliX(0)
return qml.expval(qml.SparseHamiltonian(Hmat, wires=(0,1,2,3)))
circuit()
I'll add some validation in qml.SparseHamiltonian
to check for this kind of error earlier.
Now validated.
Expected behavior
The following example should run to completion:
Actual behavior
The internal representation does not build a sparse H of the correct size for application to the dense statevector:
Additional information
This is in the most recent released and master branches of PennyLane.
Source code
No response
Tracebacks
No response
System information
Existing GitHub issues