mimiqcircuits.GateCall¶
- class GateCall(decl, args)[source]¶
Bases:
GateApplication of a
GateDeclto concrete parameter values.Usually built by calling the declaration,
decl(*args). The gate acts on as many qubits as the declaration’s body. Its decomposition is the body with the declaration’s symbols replaced byargs. Inverse, power and control wrap the call inInverse,PowerandControl.- Parameters:
- Raises:
ValueError – If
len(args)differs from the number of declaration arguments.
Examples
>>> from mimiqcircuits import * >>> from symengine import symbols >>> x = symbols('x') >>> decl = GateDecl("rot", (x,), Circuit().push(GateH(), 0).push(GateRZ(x), 0)) >>> g = GateCall(decl, (0.5,)) >>> g rot(0.5) >>> g.decompose() 1-qubit circuit with 2 instructions: ├── H @ q[0] └── RZ(0.5) @ q[0] >>> g.inverse().decompose() 1-qubit circuit with 2 instructions: ├── RZ(-0.5) @ q[0] └── H @ q[0]
Methods
__init__(decl, args)allow_bit_aliasing()Whether an instruction may list the same classical bit more than once.
allow_zvar_aliasing()Whether an instruction may list the same z-variable more than once.
asciiwidth(qubits, bits, zvars)control(*args)Return the gate controlled by
num_controlsqubits.copy()Return a shallow copy of the operation.
Return the body circuit with the declaration symbols replaced by the call values.
deepcopy()Return a deep copy of the operation and all its attributes.
evaluate(d)Substitute symbols in the call values and return a new
GateCall.get_operation()Return the operation that this one wraps, or the operation itself.
getparam(pn)Return the value of the parameter named
pn.getparams()Return the values of the operation's parameters.
gettypekey()Return the key used to look up registered decompositions: the gate class.
inverse()Return the inverse of the gate.
Return
Trueif any call value contains a free symbol.isidentity()Whether the operation is known to act as the identity.
isopalias()Whether the operation is a named alias of a wrapper.
isunitary()Return
True: gates are unitary.iswrapper()Return
False: a plain gate does not wrap another operation.listvars()Return the symbols appearing in the call values.
matrix()Return the unitary of the decomposed body as a SymEngine matrix.
numparams()Return the number of parameters of the operation.
opname()Return the name of the operator's class, for example
"SigmaMinus".parallel(*args)Return a
Parallelapplying the gate to separate qubit groups.power(*args)Return the gate raised to a power.
repeat(*args)Return a
Repeatapplying the gate several times in sequence on the same qubits.rescale(scale)Return a
RescaledGatewrapping this gate with factorscale.rescale_inplace(scale)Raise, as a gate cannot be rescaled in place.
supports_canonical_rewrite()Whether
CanonicalRewritemay decompose this operator.unwrappedmatrix()Return the numeric matrix of the operator as a NumPy array.
Attributes
The values passed for the declaration arguments, as a tuple.
cregsizesSize of each classical register, with one entry per register.
The
GateDeclbeing called.nameShort name of the operation type.
Number of clean ancillas of the operation.
num_bitsNumber of classical bits the operation acts on.
num_cregsNumber of classical registers (groups of bit targets) the operation takes.
num_qregsNumber of quantum registers (groups of qubit targets) the operation takes.
num_qubitsNumber of qubits the operation acts on.
num_zvarsNumber of complex-valued z-variables the operation acts on.
parnamesNames of the operation's parameters, as a tuple of strings.
qregsizesSize of each quantum register, as a list with one entry per register.
zregsizesSize of each z-variable register, with one entry per register.
- property num_ancillas¶
Number of clean ancillas of the operation.
The last
num_ancillasqubit targets must be in|0>when the operation starts, and are returned in|0>. On those inputs the operation acts as the one it was built for, which only touches the other qubits.It is set on
GateDecl,BlockDecl,Blockand calls to them, and is0for every other operation.decompose()sets it when it wraps a decomposition that uses clean ancillas, and marks the ancillas of each call withAncillaAllocandAncillaFree.
- property arguments¶
The values passed for the declaration arguments, as a tuple.
- decompose()[source]¶
Return the body circuit with the declaration symbols replaced by the call values.