make_qscript(fn, shots=None)[source]

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

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

  • fn (function) – the quantum function to generate the qscript from

  • shots (None, int, Sequence[int], Shots) – number and/or batches of executions


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

Return type



Consider the following quantum function:

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

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

>>> with qml.queuing.AnnotatedQueue() as active_queue:
...     _ = qml.RY(1.0, wires=0)
...     qs = make_qscript(qfunc)(0.5)
>>> qs.operations
[Hadamard(wires=[0]), CNOT(wires=[0, 1]), RX(0.5, wires=[0])]

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

>>> active_queue.queue
[RY(1.0, wires=[0])]