qpandalite.circuit_builder.qubit module#

Named quantum register and qubit types.

This module provides: - Qubit: Named reference to a single qubit within a register - QReg: Named quantum register with indexing and slicing support - QRegSlice: Slice view of a QReg for multi-qubit operations

Example usage:

qr = QReg(name="a", size=4, base_index=0) q0 = qr[0] # Qubit(name="a[0]", index=0, base_index=0) q_slice = qr[1:3] # QRegSlice with qubits at indices 1, 2 int(q0) # 0 (physical qubit index) int(qr[2]) # 2

class qpandalite.circuit_builder.qubit.QReg(name, size, base_index=0)[源代码]

基类:object

Named quantum register with indexing and slicing support.

QReg provides named access to qubits within a circuit, supporting integer indexing, negative indexing, and slicing.

参数:
  • name (str)

  • size (int)

  • base_index (int)

name

Name of the register

size

Number of qubits in the register

base_index

Starting physical qubit index (set when mapped to circuit)

示例

>>> qr = QReg(name="a", size=4, base_index=0)
>>> qr[0]
Qubit('a[0]', index=0, base_index=0)
>>> qr[1:3]
QRegSlice(a[1, 2])
>>> len(qr)
4
property base_index: int
property name: str
property qubits: list[Qubit]

Return list of all Qubit objects in this register.

property size: int
class qpandalite.circuit_builder.qubit.QRegSlice(register, indices)[源代码]

基类:object

Slice view of a QReg for multi-qubit operations.

This class provides iteration and indexing over a subset of qubits from a parent register.

参数:
  • register (QReg)

  • indices (list[int])

register

Parent QReg

indices

List of indices within the parent register

property indices: list[int]
property register: QReg
class qpandalite.circuit_builder.qubit.Qubit(name, index, base_index)[源代码]

基类:object

Named reference to a single qubit within a quantum register.

参数:
  • name (str)

  • index (int)

  • base_index (int)

name

Full name of the qubit, e.g., "a[0]"

Type:

str

index

Index within the parent register

Type:

int

base_index

Starting physical qubit index for the parent register

Type:

int

示例

>>> q = Qubit(name="a[2]", index=2, base_index=10)
>>> int(q)
12
base_index: int
index: int
name: str