qml.state() can’t read the quantum states of localized quantum bits, why is that? Let’s say I have 10 bits and I only need to read the quantum states of the 2nd and 4th qubits, how can I solve this in any other way?
Hey @RX1,
Great question! Let me just clarify: ideally you’d like to, say, return qml.state(wires=[2, 4])
from a quantum circuit with \geq 4 wires. This isn’t possible in general because of a couple reasons:

Firstly, and in theory, you most certainly can look at subsystems of a larger system by performing a partial trace — I’d be happy to explain that concept if you’re interested . Loosely speaking, you just sum over the degrees of freedom that you aren’t interested in; if you wanted the state of qubits 2 and 4, then you’d sum over qubits 1, 3, 5, etc. However, if the state is not separable, then the resulting state of the subsystem won’t be pure; it can only be represented by a density matrix, which brings me to point #2.

Returning
qml.state()
from a circuit assumes that the state is pure. As I said in point #1, the state of a subsystem is generally not pure. If you’re usingdefault.qubit
, then you can return qml.density_matrix instead, which behaves as you want it to, but it returns a density matrix . This code example is taken directly from the link to the documentation that I attached:
dev = qml.device("default.qubit", wires=2)
@qml.qnode(dev)
def circuit():
qml.PauliY(wires=0)
qml.Hadamard(wires=1)
return qml.density_matrix([0])
>>> circuit()
array([[0.+0.j 0.+0.j]
[0.+0.j 1.+0.j]])
Hope this helps!
If this answers your question, we have a new PennyLane survey . Let us know your thoughts about PennyLane so that we can keep bringing you amazing features .