Skip to content

AbstractDevice

Bases: ABC, Generic[TaskType]

Abstract base class for devices. Defines the minimum interface for devices.

task abstractmethod

task(
    kernel: Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
) -> TaskType

Creates a remote task for the device.

Source code in .venv/lib/python3.12/site-packages/bloqade/device.py
25
26
27
28
29
30
31
32
@abc.abstractmethod
def task(
    self,
    kernel: ir.Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
) -> TaskType:
    """Creates a remote task for the device."""

AbstractRemoteDevice

Bases: AbstractDevice[RemoteTaskType]

Abstract base class for remote devices.

run

run(
    kernel: Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1,
    timeout: float | None = None
) -> list[RetType]

Runs the kernel and returns the result.

Parameters:

Name Type Description Default
kernel Method

The kernel method to run.

required
args tuple[Any, ...]

Positional arguments to pass to the kernel method.

()
kwargs dict[str, Any] | None

Keyword arguments to pass to the kernel method.

None
shots int

The number of times to run the kernel method.

1
timeout float | None

Timeout in seconds for the asynchronous execution. If None, wait indefinitely.

None

Returns:

Type Description
list[RetType]

list[RetType]: The result of the kernel method, if any.

Source code in .venv/lib/python3.12/site-packages/bloqade/device.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def run(
    self,
    kernel: ir.Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1,
    timeout: float | None = None,
) -> list[RetType]:
    """Runs the kernel and returns the result.

    Args:
        kernel (ir.Method):
            The kernel method to run.
        args (tuple[Any, ...]):
            Positional arguments to pass to the kernel method.
        kwargs (dict[str, Any] | None):
            Keyword arguments to pass to the kernel method.
        shots (int):
            The number of times to run the kernel method.
        timeout (float | None):
            Timeout in seconds for the asynchronous execution. If None, wait indefinitely.

    Returns:
        list[RetType]:
            The result of the kernel method, if any.

    """
    return self.task(kernel, args, kwargs).run(shots=shots, timeout=timeout)

run_async

run_async(
    kernel: Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1
) -> BatchFuture[RetType]

Runs the kernel asynchronously and returns a Future object.

Parameters:

Name Type Description Default
kernel Method

The kernel method to run.

required
args tuple[Any, ...]

Positional arguments to pass to the kernel method.

()
kwargs dict[str, Any] | None

Keyword arguments to pass to the kernel method.

None
shots int

The number of times to run the kernel method.

1

Returns:

Type Description
BatchFuture[RetType]

Future[list[RetType]]: The Future for all executions of the kernel method.

Source code in .venv/lib/python3.12/site-packages/bloqade/device.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def run_async(
    self,
    kernel: ir.Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1,
) -> BatchFuture[RetType]:
    """Runs the kernel asynchronously and returns a Future object.

    Args:
        kernel (ir.Method):
            The kernel method to run.
        args (tuple[Any, ...]):
            Positional arguments to pass to the kernel method.
        kwargs (dict[str, Any] | None):
            Keyword arguments to pass to the kernel method.
        shots (int):
            The number of times to run the kernel method.

    Returns:
        Future[list[RetType]]:
            The Future for all executions of the kernel method.


    """
    return self.task(kernel, args, kwargs).run_async(shots=shots)

AbstractSimulatorDevice

Bases: AbstractDevice[SimulatorTaskType]

Abstract base class for simulator devices.

run

run(
    kernel: Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
) -> RetType

Runs the kernel and returns the result.

Source code in .venv/lib/python3.12/site-packages/bloqade/device.py
123
124
125
126
127
128
129
130
def run(
    self,
    kernel: ir.Method[Params, RetType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
) -> RetType:
    """Runs the kernel and returns the result."""
    return self.task(kernel, args, kwargs).run()

ExpectationDeviceMixin

Bases: AbstractDevice[ExpectTaskType]

expect

expect(
    kernel: Method[Params, RetType],
    observable: Method[[RetType], ObsType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1
) -> ObsType

Returns the expectation value of the given observable after running the task.

Source code in .venv/lib/python3.12/site-packages/bloqade/device.py
39
40
41
42
43
44
45
46
47
48
49
def expect(
    self,
    kernel: ir.Method[Params, RetType],
    observable: ir.Method[[RetType], ObsType],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    *,
    shots: int = 1,
) -> ObsType:
    """Returns the expectation value of the given observable after running the task."""
    return self.task(kernel, args, kwargs).expect(observable, shots)