--------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-15dc944c6be8> in <module>
----> 1 circuitBasis(pparams)
D:\Anaconda3\lib\site-packages\pennylane\qnode.py in __call__(self, *args, **kwargs)
665 if self.mutable or self.qtape is None:
666 # construct the tape
--> 667 self.construct(args, kwargs)
668
669 # If the observable contains a Hamiltonian and the device does not
D:\Anaconda3\lib\site-packages\pennylane\qnode.py in construct(self, args, kwargs)
577
578 with self.qtape:
--> 579 self.qfunc_output = self.func(*args, **kwargs)
580
581 if not isinstance(self.qfunc_output, Sequence):
<ipython-input-22-62e7b3038ff9> in circuitBasis(params)
5 def circuitBasis(params):
6 qml.BasisState(params, wires = [0, 1, 2, 3])
----> 7 return [qml.expval(qml.PauliZ(i) for i in range(4))]
D:\Anaconda3\lib\site-packages\pennylane\measure.py in expval(op)
253 if not isinstance(op, (Observable, qml.Hamiltonian)):
254 raise qml.QuantumFunctionError(
--> 255 "{} is not an observable: cannot be used with expval".format(op.name)
256 )
257
AttributeError: 'generator' object has no attribute 'name'
Hi @RX1! It seems to be a small syntax error in your QNode return Note that the for i in range(4)
should occur outside the expval
function:
pparams = np.array([0, 1, 1, 1])
@qml.qnode(dev2)
def circuitBasis(params):
qml.BasisState(params, wires=[0, 1, 2, 3])
return [qml.expval(qml.PauliZ(i)) for i in range(4)]
thank you !!!
Hi @RX1, if you want to use the Strawberry Fields devices, you will need to install the PennyLane-SF plugin:
pip install pennylane-sf
1 Like