mimiqcircuits.operations.block¶
Block operation for grouping instructions.
Classes
|
Block operation: group and reuse a sequence of instructions. |
- class mimiqcircuits.operations.block.Block(*args)[source]¶
Bases:
OperationBlock operation: group and reuse a sequence of instructions.
The Block class represents a reusable subcircuit. It encapsulates a fixed number of qubits, bits, and z-variables, along with a list of instructions. Blocks are used to define logical units in a circuit that can be inserted as composite operations.
You can construct a block in several ways:
Block(): Create an empty block with 0 qubits, bits, and zvars.
Block(circuit): Copy instructions from a circuit (or block) into a new block.
Block(instructions): Create a block from a list of Instruction objects.
Block(num_qubits, num_bits, num_zvars[, instructions]): Fully specify a block.
Notes
Once created, a block has a fixed number of qubits, bits, and zvars.
Adding an instruction that exceeds the declared dimensions will raise a ValueError.
Blocks are deep-copied upon construction to avoid accidental mutations.
Examples
>>> from mimiqcircuits import * >>> c = Circuit()
>>> c.push(GateCX(), 1, 2) 3-qubit circuit with 1 instruction: └── CX @ q[1], q[2]
>>> c.push(GateCX(), 1, 3) 4-qubit circuit with 2 instructions: ├── CX @ q[1], q[2] └── CX @ q[1], q[3]
>>> c.push(MeasureZZ(), 1, 2, 1) 4-qubit, 2-bit circuit with 3 instructions: ├── CX @ q[1], q[2] ├── CX @ q[1], q[3] └── MZZ @ q[1:2], c[1]
Each block prints with a unique identifier, shown as
...here.>>> block = Block(c) >>> block 4-qubit, 2-bit block ... with 3 instructions: ├── CX @ q[1], q[2] ├── CX @ q[1], q[3] └── MZZ @ q[1:2], c[1]
>>> main = Circuit() >>> main.push(block, 0, 1, 2, 3, 0, 1) 4-qubit, 2-bit circuit with 1 instruction: └── block ... @ q[0,1,2,3], c[0,1]
Decomposing expands the block, and decomposes
MeasureZZfurther:>>> main.decompose() 4-qubit, 2-bit circuit with 5 instructions: ├── CX @ q[1], q[2] ├── CX @ q[1], q[3] ├── CX @ q[1], q[2] ├── M @ q[2], c[1] └── CX @ q[1], q[2]
See also
InstructionCircuit
- listvars()[source]¶
List the symbolic variables of all the instructions of the block.
- Returns:
Each
symengine.Symbolonce, in no particular order.- Return type: