mimiqcircuits.BlockCall

class BlockCall(decl, args)[source]

Bases: Operation

A call to a BlockDecl with values for its arguments.

The call holds a reference to its declaration, not a copy. Pushing it to a circuit takes the declaration’s qubits, then its bits, then its z-variables. See BlockDecl for an example.

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

  • args (tuple) – One value (number or symbolic expression) per argument.

Raises:

ValueError – If the number of values does not match the arguments.

Examples

>>> from symengine import symbols
>>> from mimiqcircuits import *
>>> t = symbols("t")
>>> decl = BlockDecl("rot", (t,), Circuit().push(GateRX(t), 0))
>>> call = BlockCall(decl, (0.5,))
>>> call
rot(0.5)
>>> call.decompose()
1-qubit circuit with 1 instruction:
└── RX(0.5) @ 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)

copy()

Return a shallow copy of the operation.

decompose()

Decompose the operation one level into simpler operations.

deepcopy()

Return a deep copy of the operation and all its attributes.

evaluate(d)

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

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.

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 if every operation in the declaration body is unitary.

iswrapper()

Return False: a call is not a wrapper around a single operation.

listvars()

Return the symbols appearing in the call values.

numparams()

Return the number of parameters of the operation.

supports_canonical_rewrite()

Return True: a call can be expanded into its body during canonical rewriting.

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 BlockDecl 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 BlockDecl 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.

isunitary()[source]

Return True if every operation in the declaration body is unitary.

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 BlockCall.

The declaration is shared, not copied.

Parameters:

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

iswrapper()[source]

Return False: a call is not a wrapper around a single operation.

supports_canonical_rewrite()[source]

Return True: a call can be expanded into its body during canonical rewriting.