mimiqcircuits.operations.block

Block operation for grouping instructions.

Classes

Block(*args)

Block operation: group and reuse a sequence of instructions.

class mimiqcircuits.operations.block.Block(*args)[source]

Bases: Operation

Block 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]

<BLANKLINE> >>> c.push(GateCX(), 1, 3) 4-qubit circuit with 2 instructions: ├── CX @ q[1], q[2] └── CX @ q[1], q[3] <BLANKLINE>

>>> 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]
>>> block = Block(c)
>>> block
4-qubit, 2-bit block 700db35cc170 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 700db35cc170 @ q[0,1,2,3], c[0,1]
>>> main.decompose()
4-qubit, 2-bit circuit with 3 instructions:
├── CX @ q[1], q[2]
├── CX @ q[1], q[3]
└── MZZ @ q[1:2], c[1]

See also

  • Instruction

  • Circuit

__init__(*args)[source]
push(operation, *args)[source]
iswrapper()[source]
blockid()[source]
format_with_targets(qubits, bits, zvars)[source]