default.tensor doesn’t support probs measurement, which is well documented. When I tried to calculate the probs from the qml.state() by multiplying each element inside state vector with its conjugate, the sum of the resultant array may not always be 1!
Is the state returned not a quantum state or am I missing something? Thank you
Hi @mchau ,
I think you might be missing something in your calculation. The sum should be one.
If you post a minimal version of your code I can try to see if I can find the issue.
yes, the missing thing is setting TrotterProduct(check_hermitian=False). There is then no reason we shouldn’t support probs measurement for default.tensor and lightning.tensor right? If possible can I submit a PR for this?
Those checks can result in a performance decrease so it’s not necessarily ideal to add them. Also, there may be another reason why probs isn’t supported in default.tensor. Usually we try to support everything if possible. My suggestion would be to add this Hermitian check in your own code if it fixes the issue. Does this resolve the problem for you?
Hi @mchau , if the probs don’t sum up to one the problem is not necessarily in the calculation for probs, it probably means that your matrices are not Hermitian, so this is what you might want to fix instead.
Let’s look at a code example.
The state is valid if sum(state*np.conj(state))==1. This is true for any quantum device.
import pennylane as qml
from pennylane import numpy as np
num_qubits = 10
dev = qml.device("default.tensor", wires=num_qubits)
@qml.qnode(dev)
def circuit(num_qubits):
for qubit in range(0, num_qubits - 1):
qml.CZ(wires=[qubit, qubit + 1])
qml.X(wires=[qubit])
qml.Z(wires=[qubit + 1])
return qml.state()
state = circuit(num_qubits)
state_check = np.sum(state*np.conj(state))
print("Is the output a valid state? ", state_check==1)
I think the issue that you’re having is that you’re using qml.TrotterProduct with check_hermitian=False, and using a Hamiltonian with one or more terms that are not Hermitian. This results in an invalid calculation. So my recommendation would be to set check_hermitian=True and ensure you’re only using qml.TrotterProduct with Hamiltonians where all terms are Hermitian.