in the quantum-classical hybird neural network, to avoid time consuming, I can not give the qubit a great value.
when I put 3 observables on one wire and put measurement process on, I get some error as below:
it says Only observables that are qubit-wise commuting Pauli words can be returned on the same wire.
when I take the middle observable as qml.Identity, same error happens.
are there some proper qubit-wise commuting observables in pennylane?
or some other methods broaden the output dimension beyond nqubits?
The error message actually says it all here: PennyLane allows for multiple measurements on the same wire in a simulation as long as the observables are Pauli words (i.e. Pauli operators, identities or tensor products thereof) and commute. Your measurements are unfortunately non-commuting.
One reason for this restriction is that internally, PL decomposes measurements into a pre-measurement circuit and a simple measurement. But if two measurements don’t commute, their pre-measurement circuits are not the same. However, this may be up for a refactor.
If you would like to champion the idea that PL allows non-commuting measurements on the same wires on simulators, you could open an issue with your feature request - the more users need something, the more likely it gets implemented soon
Hi @qhc. If I understand your question correctly, yes PennyLane supports multiple measurements of such commuting observables performed on the same wire. For instance, the error in your code can be fixed by removing one of the PauliX or PauliZ measurements while keeping the Identity one such as:
for ind in range(8):
output.append(qml.expval(qml.PauliX(ind)))
output.append(qml.expval(qml.Identity(ind)))
return output
PennyLane also supports measurements of tensor product of observables as explained here. Please let us know if you have any other question.