Hi!

I am experimenting with QAOA and PennyLane following the tutorial. Everything works as expected. However, once that I have obtained the optimal parameters for the circuit, I would like to actually obtain solutions to the problem represented by the cost Hamiltonian and to compute the cost of those solutions.

What I am doing it to use qml.sample to obtain samples from the QAOA circuit with the optimal parameters and thus I obtain some arrays like [0 1 0] or [1 1 0]. I also have a Hamiltonian defined by

H1 = 2 * qml.PauliZ(0) @ qml.PauliZ(1) + qml.PauliZ(2)

My question is: what is the easiest way to obtain the expectation value of H1 with respect to, say, [0 1 0]? That is, I want to compute <010|H1|010> from my definition of H1 as above and from [0 1 0]. Is there a function to do that?

Thanks in advance!