I have a problem when I use nested qml.ctrl
, indeed defining the following functions:
def fun_1(x):
qml.ctrl(qml.RY,control=[1,2])(x,wires = 3)
def fun_2(x):
qml.ctrl(fun_1,control=[0])(x)
Drawing the circuit yields the following:
0: ─╭●─────────┤ State
1: ─├RY(0.50)─┤ State
2: ─├RY(0.50)─┤ State
3: ─╰RY(0.50)─┤ State
While one would expect to have the following circuit
0: ─╭●─────────┤ State
1: ─├●─────────┤ State
2: ─├●─────────┤ State
3: ─╰RY(0.50)─┤ State
Am I missing something or is this a bug ?
Hey @alicewithoutbob! Welcome back to the forum
I can’t seem to replicate your error … I get the proper drawing:
import pennylane as qml
def fun_1(x):
qml.ctrl(qml.RY,control=[1,2])(x,wires = 3)
def fun_2(x):
qml.ctrl(fun_1,control=[0])(x)
dev = qml.device("default.qubit", wires=4)
@qml.qnode(dev)
def circuit():
fun_2(0.5)
return qml.state()
print(qml.draw(circuit)())
'''
0: ─╭●────────┤ State
1: ─├●────────┤ State
2: ─├●────────┤ State
3: ─╰RY(0.50)─┤ State
'''
Are you using the most up-to-date version of PennyLane? You can check by printing qml.__version__
— it should be 0.29.1 for the latest version. If it’s anything less than that, you can update it via pip install --upgrade pennylane
. Let me know if that helps!