# sf.utils.operation¶

class operation(ns)[source]

Bases: object

Groups a sequence of gates into a single operation to be used within a Program context.

For example:

@sf.operation(3)
def custom_operation(v1, v2, q):
CZgate(v1) | (q[0], q[1])
Vgate(v2) | q[2]


Here, the operation decorator must recieve an argument detailing the number of subsystems the resulting custom operation acts on.

The function it acts on can contain arbitrary Python and Blackbird code that may normally be placed within a Program context. Note that it must always accept the register q it acts on as the last argument of the function.

Once defined, it can be used like any other quantum operation:

prog = sf.Program(3)
with prog.context as q:
custom_operation(0.5719, 2.0603) | (q[0], q[1], q[3])


Note that here, we do not pass the register q directly to the function - instead, it is defined on the right hand side of the | operation, like all other Blackbird code.

Parameters

ns (int) – number of subsystems required by the operation

 __call__(func) Call self as a function.
__call__(func)[source]

Call self as a function.