I'm trying to use qml.AmplitudeEmbedding()
two times in a circuit but it raises an error saying that the device used does not support this feature.
1 Answer
$\begingroup$
$\endgroup$
1
This is a current restriction with PennyLane, in that only a single, initial state preparation routine can be used.
However, you can use the qml.transforms.merge_amplitude_embedding
transform to merge multiple amplitude embeddings in your quantum function, as long as they act on different wires:
dev = qml.device('default.qubit', wires=4)
@qml.qnode(dev)
@qml.transforms.merge_amplitude_embedding
def qfunc():
qml.CNOT(wires=[0, 1])
qml.AmplitudeEmbedding([0, 1], wires=2)
qml.AmplitudeEmbedding([0, 1], wires=3)
return qml.probs(wires=[0, 1, 2, 3])
Using the transformation we can join the different amplitude embeddings into a single one:
>>> print(qml.draw(qfunc)())
0: ──╭C───────────────────────╭┤ Probs
1: ──╰X───────────────────────├┤ Probs
2: ──╭AmplitudeEmbedding(M0)──├┤ Probs
3: ──╰AmplitudeEmbedding(M0)──╰┤ Probs
M0 = [0.+0.j 0.+0.j 0.+0.j 1.+0.j]