I often need to change the observable (i.e. the basis for measurement) and investigate the effects of that.
I use draw_mpl() for debugging because it is easy to use, but it does not seem to display the observable.
Is it possible to obtain information about what observable is being measured as an image?
code:
import pennylane as qml
import matplotlib.pyplot as plt
observables = [qml.X(0)@qml.X(1), qml.Y(0)@qml.Y(1), qml.Z(0)@qml.Z(1)]
dev = qml.device("default.qubit", wires=2)
@qml.qnode(dev)
def circuit(x):
qml.RX(x, wires=0)
qml.Hadamard(wires=1)
qml.CNOT(wires=[0, 1])
# Even if these are set to observables[1] or [2], the output image will not change.
return qml.expval(observables[0])
fig, ax = qml.draw_mpl(circuit, level='device')(0.5)
plt.show()
Unfortunately I don’t think qml.draw_mpl() allows you to easily do this. If it’s just for debugging I would recommend using the text-based qml.draw() instead. When using this drawer you should print the output of your circuit as shown below:
I see, qml.draw() seems like a promising option. I’d like to try using it.
Also, I would like to contribute to the PennyLane community in some way. So, would it be okay if I made this feature request about qml.draw_mpl() into an enhancement issue on GitHub?
(At first glance, it seems that there is no similar issue on GitHub yet)
Yes absolutely! I think that could be a cool feature. Thanks for the suggestion!
Another very good way of contributing to the community is by going around the discussion Forum and answering someone’s question or contributing to the conversation on a topic that you like.