I wanted to compute the expectation value of the projector |000><000|+|111><111| in Pennylane. So I wrote down the representing matrix and used the qml.Hermitian function which worked as expected, but when I tried to measure the projector |100><100|+|011><011|.

I got an error message because the operator do not commute (which is weird, since the project on different spaces):

How can I fix this? And what is the proper way of measuring expectation values <\hat{O}>=Tr(O\rho) of a custom operator for a state \rho? Writing the matrix by hand everytime seems a bit too complicated.

The error is pennylane.QuantumFunctionError: Only observables that are qubit-wise commuting Pauli words can be returned on the same wire. But as far as I understand the two observables are commuting!