Skip to content

Base

DynamicMemory dataclass

DynamicMemory(
    pyqrack_options: PyQrackOptions = _default_pyqrack_args(),
)

Bases: MemoryABC

allocate

allocate(n_qubits: int)

Allocate n_qubits qubits and return their ids.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
128
129
130
131
132
133
def allocate(self, n_qubits: int):
    start = self.sim_reg.num_qubits()
    for i in range(start, start + n_qubits):
        self.sim_reg.allocate_qubit(i)

    return tuple(range(start, start + n_qubits))

MemoryABC dataclass

MemoryABC(
    pyqrack_options: PyQrackOptions = _default_pyqrack_args(),
)

Bases: ABC

allocate abstractmethod

allocate(n_qubits: int) -> tuple[int, ...]

Allocate n_qubits qubits and return their ids.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
66
67
68
69
@abc.abstractmethod
def allocate(self, n_qubits: int) -> tuple[int, ...]:
    """Allocate `n_qubits` qubits and return their ids."""
    ...

reset

reset()

Reset the memory, releasing all qubits.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
71
72
73
74
75
76
77
def reset(self):
    """Reset the memory, releasing all qubits."""
    from pyqrack import QrackSimulator

    # do not reset the simulator it might be used by
    # results of the simulation
    self.sim_reg = QrackSimulator(**self.pyqrack_options)

MockMemory dataclass

MockMemory(
    pyqrack_options: PyQrackOptions = _default_pyqrack_args(),
)

Bases: MemoryABC

Mock memory for testing purposes.

allocate

allocate(n_qubits: int)

Allocate n_qubits qubits and return their ids.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
86
87
88
89
90
def allocate(self, n_qubits: int):
    allocated = self.allocated + n_qubits
    result = tuple(range(self.allocated, allocated))
    self.allocated = allocated
    return result

reset

reset()

Reset the memory, releasing all qubits.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
92
93
94
def reset(self):
    self.allocated = 0
    self.sim_reg = Mock()

PyQrackInterpreter dataclass

PyQrackInterpreter(
    *,
    memory: MemoryType,
    rng_state: Generator = np.random.default_rng(),
    loss_m_result: Measurement = Measurement.One
)

Bases: Interpreter, Generic[MemoryType]

loss_m_result class-attribute instance-attribute

loss_m_result: Measurement = field(
    default=One, kw_only=True
)

The value of a measurement result when a qubit is lost.

StackMemory dataclass

StackMemory(
    pyqrack_options: PyQrackOptions = _default_pyqrack_args(),
    *,
    total: int
)

Bases: MemoryABC

allocate

allocate(n_qubits: int)

Allocate n_qubits qubits and return their ids.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
102
103
104
105
106
107
108
109
110
111
112
113
def allocate(self, n_qubits: int):
    curr_allocated = self.allocated
    self.allocated += n_qubits

    if self.allocated > self.total:
        raise InterpreterError(
            f"qubit allocation exceeds memory, "
            f"{self.total} qubits, "
            f"{self.allocated} allocated"
        )

    return tuple(range(curr_allocated, self.allocated))

reset

reset()

Reset the memory, releasing all qubits.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/base.py
115
116
117
def reset(self):
    super().reset()
    self.allocated = 0