Hi, I had some problems using Controlled-Unitary, the Unitary in my circuit should be the Amplitude Embedding circuit based on the given inputs. The Quantum Circuit that I want might look like the figure shown below
I tried to build the Quantum Circuit with the code:
%matplotlib inline
import pennylane as qml
import torch
total_qubit = 3
dev = qml.device("default.qubit", wires=total_qubit)
@qml.qnode(dev)
def q_node(inputs):
qml.Hadamard(wires=0)
qml.ctrl(qml.AmplitudeEmbedding(features=inputs, wires=range(1, total_qubit), normalize=True), control=0, control_values=(0))
return qml.probs(wires=range(total_qubit))
qml.draw_mpl(q_node)(inputs=torch.arange(1,5))
output = q_node(inputs=torch.arange(1,5))
And the error message shows
ValueError: prep operation Controlled(QubitStateVector(tensor([0.1826+0.j, 0.3651+0.j, 0.5477+0.j, 0.7303+0.j], dtype=torch.complex128), wires=[1, 2]), control_wires=[0]) must occur prior to ops. Please place earlier in the queue.
Quantum Circuit seems to operate the Amplitude Embedding circuit before the Control Gate, which is incorrect.
How can I fix this error and make my system work?