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.
Expected to get the same expectation value of a qml.Hamiltonian no matter
how the operators and the corresponding coefficient are ordered when it was constructed.
applied the grouping method ('QWC') or not.
Actual behavior
When the below conditions are satisfied, the expectation value will not take the value (coefficient) of qml.Identity into account.
There is a "grouping_type" argument when qml.Hamiltonian is constructed.
The operator list is not in the order of qubit number.
Example
H_disordered = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(1), qml.PauliZ(0), qml.Identity(0)], grouping_type='QWC')
The list of operator is disordered in terms of qubit number.
However its expectation value differs with the value of qml.Identity from an ordered Hamiltonian H_ordered = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.Identity(0), qml.PauliZ(0), qml.PauliZ(1)], grouping_type='QWC')
Additional information
No response
Source code
import pennylane as qml
dev = qml.device("default.qubit", wires=2, shots=1000)
@qml.qnode(dev)
def circuit():
return qml.expval(H)
H = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(0), qml.PauliZ(1), qml.Identity(0)], grouping_type='QWC')
print(circuit())
H = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(1), qml.PauliZ(0), qml.Identity(0)], grouping_type='QWC')
print(circuit())
H = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(1), qml.PauliZ(0), qml.Identity(0)], grouping_type='commuting')
print(circuit())
H = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(1), qml.PauliZ(0), qml.Identity(0)])
print(circuit())
Expected behavior
Expected to get the same expectation value of a qml.Hamiltonian no matter
Actual behavior
When the below conditions are satisfied, the expectation value will not take the value (coefficient) of qml.Identity into account.
Example
H_disordered = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.PauliZ(1), qml.PauliZ(0), qml.Identity(0)], grouping_type='QWC')
The list of operator is disordered in terms of qubit number. However its expectation value differs with the value of qml.Identity from an ordered HamiltonianH_ordered = qml.Hamiltonian([1.0, 1.0, 1.0], [qml.Identity(0), qml.PauliZ(0), qml.PauliZ(1)], grouping_type='QWC')
Additional information
No response
Source code
Tracebacks
No response
System information
Existing GitHub issues