qml.transforms.make_tape

make_tape(fn)[source]

Returns a function that generates the tape from a quantum function without any operation queuing taking place.

This is useful when you would like to manipulate or transform the tape created by a quantum function without evaluating it.

Parameters

fn (function) – the quantum function to generate the tape from

Returns

The returned function takes the same arguments as the quantum function. When called, it returns the generated quantum tape without any queueing occuring.

Return type

function

Example

Consider the following quantum function:

def qfunc(x):
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RX(x, wires=0)

We can use make_tape to extract the tape generated by this quantum function, without any of the operations being queued by any existing queuing contexts:

>>> with qml.tape.QuantumTape() as active_tape:
...     qml.RY(1.0, wires=0)
...     tape = make_tape(qfunc)(0.5)
>>> tape.operations
[Hadamard(wires=[0]), CNOT(wires=[0, 1]), RX(0.5, wires=[0])]

Note that the currently recording tape did not queue any of these quantum operations:

>>> active_tape.operations
[RY(1.0, wires=[0])]