bloqade.pyqrack.device.StackMemorySimulator
← Module overview
class
method
source
classStackMemorySimulator¶source
bloqade.pyqrack.device.StackMemorySimulator
Bases: PyQrackSimulatorBase
PyQrack simulator device with preallocated stack of qubits.
Signature
class StackMemorySimulator(options: PyQrackOptions = _default_pyqrack_args(), *, loss_m_result: MeasurementResultValue = MeasurementResultValue.One, rng_state: np.random.Generator = np.random.default_rng(), min_qubits: int = 0)This can be used to simulate kernels where the number of qubits is known ahead of time.
Usage examples
Section titled “Usage examples”# Define a kernel@qasm2.maindef main(): q = qasm2.qreg(2) c = qasm2.creg(2)
qasm2.h(q[0]) qasm2.cx(q[0], q[1])
qasm2.measure(q, c) return q
# Create the simulator objectsim = StackMemorySimulator(min_qubits=2)
# Execute the kernelqubits = sim.run(main)You can also obtain other information from it, such as the state vector:
ket = sim.state_vector(main)
from pyqrack.pauli import Pauliexpectation_vals = sim.pauli_expectation([Pauli.PauliX, Pauli.PauliI], qubits)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
options | PyQrackOptions | _default_pyqrack_args() | |
loss_m_result | MeasurementResultValue | MeasurementResultValue.One | |
rng_state | np.random.Generator | np.random.default_rng() | |
min_qubits | int | 0 |
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
min_qubits | int | field(default=0, kw_only=True) |
methodtask¶source
bloqade.pyqrack.device.StackMemorySimulator.task
Signature
def task(kernel: ir.Method[Params, RetType], args: tuple[Any, ...] = (), kwargs: dict[str, Any] | None = None)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
kernel | ir.Method[Params, RetType] | required | The kernel method to run. |
args | tuple[Any, ...] | () | Positional arguments to pass to the kernel method. |
kwargs | dict[str, Any] | None | None | Keyword arguments to pass to the kernel method. |
Returns
PyQrackSimulatorTask: The task object used to track execution.