I am working with pennyLane library in Python and I have a circuit that involves several operations to 10 qubits. I want to measure the occupation probability of a target state. The function qml.probs() returns the probabilities |βŸ¨π‘–|πœ“βŸ©|^2 of measuring the computational basis state |π‘–βŸ© given the current state |πœ“βŸ©.

If I use qml.probs(wires=range(10)) the measurement is with respect to |+π‘–βŸ©/|-π‘–βŸ©, and I need to get the result with respect to the basis |0⟩/|1⟩. I have tried [qml.probs(op=qml.PauliZ(i)) for i in range(10)] , qml.probs(op=[qml.expval(qml.PauliZ(i)) for i in range(10)]) but it gives the individual result of each qubit instead of the whole 10-qubit state, or it doesn't give back the expected result.

I think that there must be an option to get the result I want, and will be related to the "op" parameter that I am not using correctly, so I would be grateful if someone could help me.


1 Answer 1


If you have 10 qubits there are $2^{10}$ possible measurement outcomes. Hence, qml.prob(wires=10) will return an array with $2^{10}$ elements. Each element of an array is the probability of observing the state $|i\rangle$ where $i \in \{0,\ldots,2^{10}-1\}$. The measurement is done with respect to the computational basis. Given that you wrote something that doesn't quite make sense, I feel like it is worth pointing out that $|i\rangle$ is an integer representation of a binary string of length 10.

Perhaps, you want to take a look at a simpler example with 2 qubits:

dev = qml.device("default.qubit", wires=2)
def circuit():
   return qml.probs(wires=[0, 1])

This code generates the state $$\tag{1} |0\rangle \left(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = \frac{|00\rangle}{\sqrt{2}} + \frac{|01\rangle}{\sqrt{2}}.$$ Given that the measurement is in the computational basis, your possible outcomes are: $|0\rangle \equiv |00\rangle, |1\rangle \equiv |01\rangle, |2\rangle \equiv |10\rangle, |3\rangle \equiv|11\rangle$. From (1) it is clear that qml.probs(wires=[0,1]) will yield an array [0.5, 0.5, 0, 0].

  • $\begingroup$ Please don't write $|i\rangle / |-i\rangle$ because this notation doesn't make any sense. $\endgroup$
    – MonteNero
    Jul 11, 2022 at 7:53
  • $\begingroup$ True, thank you. $\endgroup$ Jul 12, 2022 at 8:09

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.