mimiqcircuits.GateDecl¶
- class GateDecl(name, arguments, circuit, num_ancillas=0)[source]¶
Bases:
objectDeclaration of a named, parametric gate defined by a circuit.
A
GateDeclstores a name, a tuple of symbolic arguments and a body circuit of gates written with those symbols. Calling the declaration with values,decl(v1, v2, ...), returns aGateCallthat can be pushed to circuits like any other gate. The body is copied, so later changes to the original circuit do not affect the declaration.The
gatedecl()decorator is the usual way to build one.- Parameters:
- Raises:
TypeError – If an argument is not a
symengine.Symbol.ValueError – If the circuit is empty or contains an operation that is not a
Gate.
GateDecl(name, arguments, circuit, num_ancillas=0)declares a gate whose body iscircuit.num_ancillassays how many of its last qubits are clean ancillas: each call must find them in|0>, and gets them back in|0>. On other inputs the call is still a unitary on all its qubits, but not the gate it was built for.decompose()sets it when it wraps a decomposition that uses clean ancillas.Examples
>>> from symengine import symbols >>> from mimiqcircuits import * >>> x, y = symbols('x y') >>> # write the body with symbolic parameters >>> c = Circuit() >>> c.push(GateXXplusYY(x, y), 0, 1) 2-qubit circuit with 1 instruction: └── XXplusYY(x, y) @ q[0:1] >>> c.push(GateRX(x), 1) 2-qubit circuit with 2 instructions: ├── XXplusYY(x, y) @ q[0:1] └── RX(x) @ q[1] >>> # declare the gate from the body >>> decl = GateDecl("ansatz", (x, y), c) >>> decl gate ansatz(x, y) = ├── XXplusYY(x, y) @ q[0:1] └── RX(x) @ q[1] >>> # calling the declaration gives a gate with concrete parameters >>> g = decl(2, 4) >>> g ansatz(2, 4) >>> g.decompose() 2-qubit circuit with 2 instructions: ├── XXplusYY(2, 4) @ q[0:1] └── RX(2) @ q[1] >>> # push the call on any two qubits >>> Circuit().push(g, 10, 22) 23-qubit circuit with 1 instruction: └── ansatz(2, 4) @ q[10,22]
See also
Methods
__init__(name, arguments, circuit[, ...])Attributes
Number of clean ancillas, the last targets of each call.
Number of classical bits of the body circuit, always 0.
Number of qubits of the body circuit.
Number of z-variables of the body circuit, always 0.
- property num_ancillas¶
Number of clean ancillas, the last targets of each call.
- property num_qubits¶
Number of qubits of the body circuit. Read-only.
- property num_bits¶
Number of classical bits of the body circuit, always 0. Read-only.
- property num_zvars¶
Number of z-variables of the body circuit, always 0. Read-only.