qml.transforms.merge_amplitude_embedding

merge_amplitude_embedding(tape)[source]

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

Parameters

qfunc (function) – A quantum function.

Returns

the transformed quantum function

Return type

function

Example

Consider the following 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:

>>> dev = qml.device('default.qubit', wires=4)
>>> optimized_qfunc = qml.transforms.merge_amplitude_embedding(qfunc)
>>> optimized_qnode = qml.QNode(optimized_qfunc, dev)
>>> print(qml.draw(optimized_qnode, show_matrices=True)())
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]