Skip to content

Task

PyQrackSimulatorTask dataclass

PyQrackSimulatorTask(
    kernel: Method[Params, RetType],
    args: tuple[Any, ...],
    kwargs: dict[str, Any],
    pyqrack_interp: PyQrackInterpreter[MemoryType],
)

Bases: AbstractSimulatorTask[Param, RetType, MemoryType]

PyQrack simulator task for Bloqade.

state property

state: MemoryType

Returns the state of the simulator after running the task.

qubits

qubits() -> list[PyQrackQubit]

Returns the qubits in the simulator.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/task.py
41
42
43
44
45
46
47
48
49
50
51
52
53
def qubits(self) -> list[PyQrackQubit]:
    """Returns the qubits in the simulator."""
    try:
        N = self.state.sim_reg.num_qubits()
        return [
            PyQrackQubit(
                addr=i, sim_reg=self.state.sim_reg, state=QubitState.Active
            )
            for i in range(N)
        ]
    except AttributeError:
        Warning("Task has not been run, there are no qubits!")
        return []

run

run() -> RetType

Executes the kernel and returns the result.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/task.py
22
23
24
25
26
27
28
29
30
def run(self) -> RetType:
    return cast(
        RetType,
        self.pyqrack_interp.run(
            self.kernel,
            args=self.args,
            kwargs=self.kwargs,
        ),
    )

state_vector

state_vector() -> list[complex]

Returns the state vector of the simulator.

Source code in .venv/lib/python3.12/site-packages/bloqade/pyqrack/task.py
36
37
38
39
def state_vector(self) -> list[complex]:
    """Returns the state vector of the simulator."""
    self.run()
    return self.state.sim_reg.out_ket()