Skip to content

bloqade.pyqrack.device.StackMemorySimulator

← Module overview

classStackMemorySimulatorsource

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.

# Define a kernel
@qasm2.main
def 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 object
sim = StackMemorySimulator(min_qubits=2)
# Execute the kernel
qubits = 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 Pauli
expectation_vals = sim.pauli_expectation([Pauli.PauliX, Pauli.PauliI], qubits)

Parameters

NameTypeDefaultDescription
optionsPyQrackOptions_default_pyqrack_args()
loss_m_resultMeasurementResultValueMeasurementResultValue.One
rng_statenp.random.Generatornp.random.default_rng()
min_qubitsint0

Attributes

NameTypeDefaultDescription
min_qubitsintfield(default=0, kw_only=True)

methodtasksource

bloqade.pyqrack.device.StackMemorySimulator.task

Signature
def task(kernel: ir.Method[Params, RetType], args: tuple[Any, ...] = (), kwargs: dict[str, Any] | None = None)

Parameters

NameTypeDefaultDescription
kernelir.Method[Params, RetType]requiredThe kernel method to run.
argstuple[Any, ...]()Positional arguments to pass to the kernel method.
kwargsdict[str, Any] | NoneNoneKeyword arguments to pass to the kernel method.

Returns

PyQrackSimulatorTask: The task object used to track execution.

source