qml.transforms.qcut.expand_fragment_tape

expand_fragment_tape(tape: pennylane.tape.tape.QuantumTape)Tuple[List[pennylane.tape.tape.QuantumTape], List[pennylane.transforms.qcut.PrepareNode], List[pennylane.transforms.qcut.MeasureNode]][source]

Expands a fragment tape into a sequence of tapes for each configuration of the contained MeasureNode and PrepareNode operations.

Note

This function is designed for use as part of the circuit cutting workflow. Check out the qml.cut_circuit() transform for more details.

Parameters

tape (QuantumTape) – the fragment tape containing MeasureNode and PrepareNode operations to be expanded

Returns

the tapes corresponding to each configuration and the order of preparation nodes and measurement nodes used in the expansion

Return type

Tuple[List[QuantumTape], List[PrepareNode], List[MeasureNode]]

Example

Consider the following circuit, which contains a MeasureNode and PrepareNode operation:

with qml.tape.QuantumTape() as tape:
    qml.transforms.qcut.PrepareNode(wires=0)
    qml.RX(0.5, wires=0)
    qml.transforms.qcut.MeasureNode(wires=0)

We can expand over the measurement and preparation nodes using:

>>> tapes, prep, meas = qml.transforms.qcut.expand_fragment_tape(tape)
>>> for t in tapes:
...     print(qml.drawer.tape_text(t, decimals=1))
0: ──I──RX(0.5)─┤  <I>  <Z>
0: ──I──RX(0.5)─┤  <X>
0: ──I──RX(0.5)─┤  <Y>
0: ──X──RX(0.5)─┤  <I>  <Z>
0: ──X──RX(0.5)─┤  <X>
0: ──X──RX(0.5)─┤  <Y>
0: ──H──RX(0.5)─┤  <I>  <Z>
0: ──H──RX(0.5)─┤  <X>
0: ──H──RX(0.5)─┤  <Y>
0: ──H──S──RX(0.5)─┤  <I>  <Z>
0: ──H──S──RX(0.5)─┤  <X>
0: ──H──S──RX(0.5)─┤  <Y>