qp.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 (QNode or quantum function).

Returns:

The transformed circuit as described in qp.transform.

Return type:

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

Example

You can apply the transform directly on a QNode:

import pennylane as qp

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

@qp.transforms.merge_amplitude_embedding
@qp.qnode(device=dev)
def circuit():
    qp.CNOT(wires = [0,1])
    qp.AmplitudeEmbedding([0, 1], wires = 2)
    qp.AmplitudeEmbedding([0, 1], wires = 3)
    return qp.state()
>>> print(qp.draw(circuit)())
0: ─╭●───┤  State
1: ─╰X───┤  State
2: ─╭|Ψ⟩─┤  State
3: ─╰|Ψ⟩─┤  State
>>> circuit()
array([0.+0.j, 0.+0.j, 0.+0.j, 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])