I know ControlledQubitUnitary might be possible to achieve my goal, but I want the value inside the Unitary to become trainable instead of the fixed Unitary matrix.
Can anyone show me how to do this?
Thanks!
Thank you @isaacdevlugt ! I also wanted to change the layer number by myself, so I did this:
import pennylane as qml
from pennylane import numpy as np
dev = qml.device("default.qubit", wires=range(6))
def subcircuit(thetas):
for ii in range(layer_num):
for jj in range(3):
qml.RY(thetas[ii][jj], wires=jj)
for jj in range(2):
qml.CNOT(wires=[jj,jj+1])
@qml.qnode(dev)
def circuit(thetas):
qml.ctrl(subcircuit, (3, 4, 5), control_values=(1,1,1))(thetas)
return [qml.expval(qml.PauliY(i)) for i in dev.wires]
layer_num = 3
thetas = np.random.uniform(0, 2*np.pi, size=(layer_num,3))
qml.draw_mpl(circuit)(thetas)