I’m trying to answer codercise PF.4.1 (Circuits as Function) using the instruction which suggests there is a solution using BasicEntanglerLayer. That, however, doesn’t seem correct. I’ve tried the following to see if I can make it work using the template but no luck
n_wires=3
dev = qml.device("default.qubit", wires = n_wires)
def custom_rotation(theta):
qml.RX(theta, 0) # theta_0: RX on qubit 0
@qml.qnode(dev)
def circuit_as_function(params):
weights = np.array(params[:3]).reshape(1, 3)
qml.BasicEntanglerLayers(
weights=weights,
wires=0,
control_wires=[1,2],
rotation=custom_rotation(params[0])
)
for i in range(3):
qml.RY(params[i+1], wires=i)
return qml.expval(qml.PauliZ(0))
angles = np.linspace(0, 4 * np.pi, 200)
output_values = np.array([circuit_as_function([0.5, t, 0.5, 0.5]) for t in angles])
Can it actually be solved using a template function?
Hi, @alibaba ! Welcome to the forum.
I am confused about where the suggestion about using BasicEntanglerLayer is. I can’t find anything in the description of the Codercise that indicates it. Can you point me to it?
It seems to me that the Codercise is asking to implement the circuit shown in the image.
Thanks.
Ah! I see. Thanks for providing the screenshot.
What we meant by that first sentence was that the operations used by the template were going to be needed in the Codercise, it was not hinting that the Codercise should be solved using the template. Had it been the latter, the phrasing would have been more “To become familiar with using this template”. Apologies for the confusion this might have caused.
And to answer to your previous question, the solution doesn’t involve using the template. It was just asking to implement the circuit with gates.