I couldn’t replicate your error but using the ctrl function you can achieve the result you want in an easier way. The following code should work for you:
import pennylane as qml
from pennylane import numpy as np
num_qubits = 4
dev = qml.device('default.qubit', wires=num_qubits, shots=8192)
return qml.MottonenStatePreparation(X, wires=range(2,4))
op = qml.ctrl(Stateper,control=[0,1])
X = np.array([1/2, 1/2, 1/2, 1/2])
You will notice a few things:
- I imported numpy directly from PennyLane. This is important, specially when you need to set your parameters as trainable or not.
- In the MottonenStatePreparation the wires are defined as a range because this value needs to be an iterable.
- I used the ctrl function to specify the control qubits. This is equivalent to
op1 = qml.ctrl(qml.ctrl(Stateper, 1), 0)
- X is set as a numpy array. If you don’t set it this way it will still work but when you use qml.draw_mpl you won’t see the details of the circuit.
Please let me know if this is what you were looking for!
If this code doesn’t work try making sure that you’re using the latest PennyLane version. If it still doesn’t work please let me know.