PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
The expectation value obtained for the tensor product of an observable containing terms using qml.Hermitian is correct.
Actual behavior
Incorrect result.
Additional information
The example compares two equivalent cases:
Getting the expectation value of a tensor observable that contains qml.Hermitian terms;
Querying the matrix of the same observable and using qml.Hermitian.
The results are different with 2. being the expected result.
Note: the qml.operation.Tensor class is to be changed such that qml.Hermitian terms are not accepted. The reason for that is that under the hood, qml.Hermitian uses np.linalg.eigh to get the eigenvectors and eigenvalues of the matrix. NumPy seems to return eigenvalues always in a sorted order, which can cause issues when used with the Tensor class.
Expected behavior
The expectation value obtained for the tensor product of an observable containing terms using
qml.Hermitian
is correct.Actual behavior
Incorrect result.
Additional information
The example compares two equivalent cases:
qml.Hermitian
terms;qml.Hermitian
.The results are different with 2. being the expected result.
Note: the
qml.operation.Tensor
class is to be changed such thatqml.Hermitian
terms are not accepted. The reason for that is that under the hood,qml.Hermitian
usesnp.linalg.eigh
to get the eigenvectors and eigenvalues of the matrix. NumPy seems to return eigenvalues always in a sorted order, which can cause issues when used with theTensor
class.Source code
Tracebacks
No response
System information
Existing GitHub issues