qml.transforms.merge_amplitude_embedding

merge_amplitude_embedding(tape)[source]

Quantum function transform to combine amplitude embedding templates that act on different qubits.

Parameters

tape (QNode or QuantumTape or Callable) – A quantum circuit.

Returns

The transformed circuit as described in qml.transform.

Return type

qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]

Example

>>> dev = qml.device('default.qubit', wires=4)

You can apply the transform directly on QNode:

@qml.transforms.merge_amplitude_embedding
@qml.qnode(device=dev)
def circuit():
    qml.CNOT(wires = [0,1])
    qml.AmplitudeEmbedding([0,1], wires = 2)
    qml.AmplitudeEmbedding([0,1], wires = 3)
    return qml.state()
>>> circuit()
[1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

You can also apply it on quantum function.

def qfunc():
    qml.CNOT(wires = [0,1])
    qml.AmplitudeEmbedding([0,1], wires = 2)
    qml.AmplitudeEmbedding([0,1], wires = 3)
    return qml.state()

The circuit before compilation will not work because of using two amplitude embedding.

Using the transformation we can join the different amplitude embedding into a single one:

>>> optimized_qfunc = qml.transforms.merge_amplitude_embedding(qfunc)
>>> optimized_qnode = qml.QNode(optimized_qfunc, dev)
>>> print(qml.draw(optimized_qnode)())
0: ─╭●──────────────────────┤  State
1: ─╰X──────────────────────┤  State
2: ─╭AmplitudeEmbedding(M0)─┤  State
3: ─╰AmplitudeEmbedding(M0)─┤  State
M0 =
[0.+0.j 0.+0.j 0.+0.j 1.+0.j]