0
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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]
$\endgroup$
1
  • $\begingroup$ THANKS A LOT @Josh Izaac $\endgroup$ Commented Feb 15, 2022 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.