mimiqcircuits.blockdecl

blockdecl(name)[source]

Decorator that turns a function returning a circuit into a BlockDecl.

The names of the function’s arguments become the symbolic arguments of the declaration. The function is called once, with those symbols, to build the body. The decorated name is bound to the BlockDecl, not to the function; calling it with values gives a BlockCall.

Parameters:

name – Name of the declared block.

Returns:

A decorator that returns the BlockDecl.

Raises:

ValueError – If the decorated function does not return a Circuit or a Block.

Examples

>>> from mimiqcircuits import *
>>> # the argument name ``phi`` becomes the symbol of the declaration
>>> @blockdecl("prepare")
... def prepare(phi):
...     return Circuit().push(GateRY(phi), 0).push(Measure(), 0, 0)
>>> prepare
block prepare(phi) =
├── RY(phi) @ q[0]
└── M @ q[0], c[0]

>>> # call it with a value and push it on qubit 2 and bit 1
>>> Circuit().push(prepare(0.5), 2, 1)
3-qubit, 2-bit circuit with 1 instruction:
└── prepare(0.5) @ q[2], c[1]