An error for Compiling circuit

i tried to run this code:
import pennylane as qml
from pennylane.transforms import commute_controlled, cancel_inverses
pipeline = [commute_controlled, cancel_inverses]

@partial(qml.compile, pipeline=pipeline)
@qml.qnode(dev)
def qfunc(x, y, z):
qml.Hadamard(wires=0)
qml.Hadamard(wires=1)
qml.Hadamard(wires=2)
qml.RZ(z, wires=2)
qml.CNOT(wires=[2, 1])
qml.RX(z, wires=0)
qml.CNOT(wires=[1, 0])
qml.RX(x, wires=0)
qml.CNOT(wires=[1, 0])
qml.RZ(-z, wires=2)
qml.RX(y, wires=2)
qml.Y(wires=2)
qml.CZ(wires=[1, 2])
return qml.expval(qml.Z(wires=0)), which i copied from this link for circuit decomposition and circuit compiling: Compiling circuits — PennyLane 0.36.0 documentation. i got this error: ---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[1], line 5
2 from pennylane.transforms import commute_controlled, cancel_inverses
3 pipeline = [commute_controlled, cancel_inverses]
----> 5 @partial(qml.compile, pipeline=pipeline)
6 @qml.qnode(dev)
7 def qfunc(x, y, z):
8 qml.Hadamard(wires=0)
9 qml.Hadamard(wires=1)

NameError: name ‘partial’ is not defined. I have the latest version of pennylane:
Version: 0.36.0

Hi @sassan_moradi ,

You need to import it with from functools import partial.

Did you find this code in an example in the documentation or somewhere else?

I hope this helps!

Many thanks @CatalinaAlbornoz. The command solved the problem. I found the code here: Compiling circuits — PennyLane 0.36.0 documentation
I think, you should fix it.

Hi @sassan_moradi, I’m glad this solved your problem.

Thanks for sharing the link. I agree with you. I’ll make a PR for adding this. Thank you for your question!

1 Like