Hello! I am trying to do pauli_decompose
on a CSR matrix. I tried SparseHamiltonian
on a sparse matrix, but looks like the qml.expval
and qml.exp
doesn’t return the same result as dense version.
Here is how I do this
arr = np.array([[0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0]])
qml.pauli_decompose(arr)
Then for the sparse part
row = np.array([0, 1, 2, 3, 4, 5, 6, 7])
col = np.array([3, 2, 1, 0, 7, 6, 5, 4])
data = np.array([1, 1, 1, 1, 1, 1, 1, 1])
sparse = csr_matrix((data, (row, col)), shape=(8, 8))
qml.SparseHamiltonian(sparse, wires=[0,1,2])
How can I correctly do the Pauli decomposition for a sparse matrix?