mimiqcircuits.GateCall

class GateCall(decl, args)[source]

Bases: Gate

Application of a GateDecl to 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 by args. Inverse, power and control wrap the call in Inverse, Power and Control.

Parameters:
  • decl (GateDecl) – The declaration to call.

  • args (tuple) – One value per declaration argument. Values may be numbers or symbolic expressions.

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]
__init__(decl, args)[source]

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_controls qubits.

copy()

Return a shallow copy of the operation.

decompose()

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.

is_symbolic()

Return True if 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 Parallel applying the gate to separate qubit groups.

power(*args)

Return the gate raised to a power.

repeat(*args)

Return a Repeat applying the gate several times in sequence on the same qubits.

rescale(scale)

Return a RescaledGate wrapping this gate with factor scale.

rescale_inplace(scale)

Raise, as a gate cannot be rescaled in place.

supports_canonical_rewrite()

Whether CanonicalRewrite may decompose this operator.

unwrappedmatrix()

Return the numeric matrix of the operator as a NumPy array.

Attributes

arguments

The values passed for the declaration arguments, as a tuple.

cregsizes

Size of each classical register, with one entry per register.

decl

The GateDecl being called.

name

Short name of the operation type.

num_ancillas

Number of clean ancillas of the operation.

num_bits

Number of classical bits the operation acts on.

num_cregs

Number of classical registers (groups of bit targets) the operation takes.

num_qregs

Number of quantum registers (groups of qubit targets) the operation takes.

num_qubits

Number of qubits the operation acts on.

num_zvars

Number of complex-valued z-variables the operation acts on.

parnames

Names of the operation's parameters, as a tuple of strings.

qregsizes

Size of each quantum register, as a list with one entry per register.

zregsizes

Size of each z-variable register, with one entry per register.

property decl

The GateDecl being called.

property num_ancillas

Number of clean ancillas of the operation.

The last num_ancillas qubit 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, Block and calls to them, and is 0 for every other operation. decompose() sets it when it wraps a decomposition that uses clean ancillas, and marks the ancillas of each call with AncillaAlloc and AncillaFree.

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.

is_symbolic()[source]

Return True if any call value contains a free symbol.

listvars()[source]

Return the symbols appearing in the call values.

evaluate(d)[source]

Substitute symbols in the call values and return a new GateCall.

Parameters:

d (dict) – Map from symbols to the values to substitute.

matrix()[source]

Return the unitary of the decomposed body as a SymEngine matrix.