mimiqcircuits.gatedecl¶
- gatedecl(name)[source]¶
Decorator that turns a function returning a circuit into a
GateDecl.The names of the function’s arguments become the symbolic parameters of the declaration. The function is called once, with those symbols, to build the body. The decorated name is bound to the
GateDecl, not to the function; calling it with values gives aGateCall.- Parameters:
name – Name of the declared gate.
- Returns:
A decorator that returns the
GateDecl.- Raises:
ValueError – If the decorated function does not return a
Circuit.
Examples
>>> from mimiqcircuits import * >>> # the argument name ``theta`` becomes the symbol of the declaration >>> @gatedecl("ansatz") ... def ansatz(theta): ... return Circuit().push(GateX(), 0).push(GateRX(theta), 1) >>> ansatz gate ansatz(theta) = ├── X @ q[0] └── RX(theta) @ q[1] >>> # call it with a value to get a gate >>> ansatz(0.5) ansatz(0.5) >>> ansatz(0.5).decompose() 2-qubit circuit with 2 instructions: ├── X @ q[0] └── RX(0.5) @ q[1] >>> # the call is pushed like any gate >>> Circuit().push(ansatz(0.5), 3, 4) 5-qubit circuit with 1 instruction: └── ansatz(0.5) @ q[3:4]