Module 'pennylane' has no attribute 'NumberOperator'

I tried to run the example at:

def photon_redirection(params):
qml.FockState(1, wires=0)
qml.Beamsplitter(params[0], params[1], wires=[0, 1])
return qml.expval(qml.NumberOperator(1))

But I got an error: module ‘pennylane’ has no attribute ‘NumberOperator’
I am using pennylane 0.4


Hi @cubicgate,

That’s unusual. Can you confirm your pennylane version by running the following command from within the same interactive python interpreter that you use to get the error?:

import pennylane as qml

Hi Nathan,

I found out the reason: on my computer, it is called NumberState.

Hi @cubicgate,

I figured out the issue. We’ve renamed a few operators in the latest development version of PennyLane, but this hasn’t made it into an official release yet. At the moment, the docs, by default, point to the development version, so there is some misalignment. This should be fixed shortly; we will release a new official version. Then the documentation will be up-to-date.


Yes, thanks @nathan for your help!