Task
KernelBatchTask dataclass
KernelBatchTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
future_cls: type[FutureType] = Future,
kernels: list[Method],
arguments: list[dict] | None = None,
num_shots: int | list[int],
metadata: list[dict] | None = None
)
Bases: TaskABC[FutureType]
flowchart TD
bloqade.core.device.task.KernelBatchTask[KernelBatchTask]
bloqade.core.device.task.TaskABC[TaskABC]
bloqade.core.device.mixins.AuthMixin[AuthMixin]
bloqade.core.device.task.TaskABC --> bloqade.core.device.task.KernelBatchTask
bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
click bloqade.core.device.task.KernelBatchTask href "" "bloqade.core.device.task.KernelBatchTask"
click bloqade.core.device.task.TaskABC href "" "bloqade.core.device.task.TaskABC"
click bloqade.core.device.mixins.AuthMixin href "" "bloqade.core.device.mixins.AuthMixin"
Task that runs multiple kernels, one subtask per kernel.
Attributes:
| Name | Type | Description |
|---|---|---|
kernels | list[Method] | Kernels to execute. |
arguments | list[dict] | None | Per-kernel argument dictionaries. Defaults to None. |
num_shots | int | list[int] | Shot count per kernel, or one value broadcast to every kernel. |
metadata | list[dict] | None | Per-kernel metadata. Defaults to None. |
num_subtasks property
num_subtasks: int
Number of subtasks in this task's definition.
get_arguments
get_arguments() -> list[dict] | None
Return per-subtask argument dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One argument dictionary per subtask, or None when no arguments are set. |
Source code in src/bloqade/core/device/task.py
506 507 | |
get_kernels
get_kernels() -> list[ir.Method]
Return the kernels used to build the task's programs.
Returns:
| Type | Description |
|---|---|
list[Method] | list[ir.Method]: Kernels in program-index order. |
Source code in src/bloqade/core/device/task.py
503 504 | |
get_metadata
get_metadata() -> list[dict] | None
Return per-subtask metadata dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One metadata dictionary per subtask, or None when no metadata is set. |
Source code in src/bloqade/core/device/task.py
514 515 | |
get_num_shots
get_num_shots() -> list[int]
Return the per-subtask shot counts.
Returns:
| Type | Description |
|---|---|
list[int] | list[int]: Shot count for each subtask, in subtask order. |
Source code in src/bloqade/core/device/task.py
509 510 511 512 | |
summary
summary() -> str
Return a human-readable summary printed on dry-run.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Summary describing what would be submitted. |
Source code in src/bloqade/core/device/task.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
KernelSerializer
Bases: Protocol
flowchart TD
bloqade.core.device.task.KernelSerializer[KernelSerializer]
click bloqade.core.device.task.KernelSerializer href "" "bloqade.core.device.task.KernelSerializer"
Structural interface for kernel serializers.
encode
encode(encoded_module: Any) -> str | bytes
Encode a Kirin serialization module for Program.content.
Source code in src/bloqade/core/device/task.py
27 28 29 | |
ParameterScanTask dataclass
ParameterScanTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
future_cls: type[FutureType] = Future,
kernel: Method,
arguments: list[dict],
num_shots: int | list[int],
metadata: list[dict] | None = None
)
Bases: TaskABC[FutureType]
flowchart TD
bloqade.core.device.task.ParameterScanTask[ParameterScanTask]
bloqade.core.device.task.TaskABC[TaskABC]
bloqade.core.device.mixins.AuthMixin[AuthMixin]
bloqade.core.device.task.TaskABC --> bloqade.core.device.task.ParameterScanTask
bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
click bloqade.core.device.task.ParameterScanTask href "" "bloqade.core.device.task.ParameterScanTask"
click bloqade.core.device.task.TaskABC href "" "bloqade.core.device.task.TaskABC"
click bloqade.core.device.mixins.AuthMixin href "" "bloqade.core.device.mixins.AuthMixin"
Task that runs one kernel against multiple argument sets.
Each entry in arguments becomes a subtask. The same program is reused for every subtask.
Attributes:
| Name | Type | Description |
|---|---|---|
kernel | Method | Kernel executed for each parameter set. |
arguments | list[dict] | Argument dictionaries, one per subtask. |
num_shots | int | list[int] | Shot count per subtask, or one value broadcast to every subtask. |
metadata | list[dict] | None | Per-subtask metadata. Defaults to None. |
num_subtasks property
num_subtasks: int
Number of subtasks in this task's definition.
get_arguments
get_arguments() -> list[dict]
Return per-subtask argument dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One argument dictionary per subtask, or None when no arguments are set. |
Source code in src/bloqade/core/device/task.py
402 403 | |
get_kernels
get_kernels() -> list[ir.Method]
Return the kernels used to build the task's programs.
Returns:
| Type | Description |
|---|---|
list[Method] | list[ir.Method]: Kernels in program-index order. |
Source code in src/bloqade/core/device/task.py
399 400 | |
get_metadata
get_metadata() -> list[dict] | None
Return per-subtask metadata dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One metadata dictionary per subtask, or None when no metadata is set. |
Source code in src/bloqade/core/device/task.py
410 411 | |
get_num_shots
get_num_shots() -> list[int]
Return the per-subtask shot counts.
Returns:
| Type | Description |
|---|---|
list[int] | list[int]: Shot count for each subtask, in subtask order. |
Source code in src/bloqade/core/device/task.py
405 406 407 408 | |
program_index_for_subtask
program_index_for_subtask(i: int) -> int
Return the program index used by subtask i.
The default implementation maps each subtask to its own program. Parameter-scan tasks override this to reuse a single program.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i | int | Subtask index. | required |
Returns:
| Name | Type | Description |
|---|---|---|
int | int | Program index. |
Source code in src/bloqade/core/device/task.py
413 414 | |
summary
summary() -> str
Return a human-readable summary printed on dry-run.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Summary describing what would be submitted. |
Source code in src/bloqade/core/device/task.py
416 417 418 419 420 421 422 423 | |
SingleKernelTask dataclass
SingleKernelTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
future_cls: type[FutureType] = Future,
kernel: Method,
arguments: dict | None = None,
num_shots: int,
metadata: dict | None = None
)
Bases: TaskABC[FutureType]
flowchart TD
bloqade.core.device.task.SingleKernelTask[SingleKernelTask]
bloqade.core.device.task.TaskABC[TaskABC]
bloqade.core.device.mixins.AuthMixin[AuthMixin]
bloqade.core.device.task.TaskABC --> bloqade.core.device.task.SingleKernelTask
bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
click bloqade.core.device.task.SingleKernelTask href "" "bloqade.core.device.task.SingleKernelTask"
click bloqade.core.device.task.TaskABC href "" "bloqade.core.device.task.TaskABC"
click bloqade.core.device.mixins.AuthMixin href "" "bloqade.core.device.mixins.AuthMixin"
Task that runs a single kernel with one set of arguments.
Attributes:
| Name | Type | Description |
|---|---|---|
kernel | Method | Kernel to execute. |
arguments | dict | None | Arguments for the kernel. Defaults to None. |
num_shots | int | Shot count for the kernel. |
metadata | dict | None | Metadata for the single subtask. Defaults to None. |
num_subtasks property
num_subtasks: int
Number of subtasks in this task's definition.
get_arguments
get_arguments() -> list[dict] | None
Return per-subtask argument dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One argument dictionary per subtask, or None when no arguments are set. |
Source code in src/bloqade/core/device/task.py
451 452 453 | |
get_kernels
get_kernels() -> list[ir.Method]
Return the kernels used to build the task's programs.
Returns:
| Type | Description |
|---|---|
list[Method] | list[ir.Method]: Kernels in program-index order. |
Source code in src/bloqade/core/device/task.py
448 449 | |
get_metadata
get_metadata() -> list[dict] | None
Return per-subtask metadata dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One metadata dictionary per subtask, or None when no metadata is set. |
Source code in src/bloqade/core/device/task.py
458 459 460 | |
get_num_shots
get_num_shots() -> list[int]
Return the per-subtask shot counts.
Returns:
| Type | Description |
|---|---|
list[int] | list[int]: Shot count for each subtask, in subtask order. |
Source code in src/bloqade/core/device/task.py
455 456 | |
summary
summary() -> str
Return a human-readable summary printed on dry-run.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Summary describing what would be submitted. |
Source code in src/bloqade/core/device/task.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
TaskABC dataclass
TaskABC(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
future_cls: type[FutureType] = Future
)
Bases: Generic[FutureType], AuthMixin, ABC
flowchart TD
bloqade.core.device.task.TaskABC[TaskABC]
bloqade.core.device.mixins.AuthMixin[AuthMixin]
bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
click bloqade.core.device.task.TaskABC href "" "bloqade.core.device.task.TaskABC"
click bloqade.core.device.mixins.AuthMixin href "" "bloqade.core.device.mixins.AuthMixin"
Abstract base class for kernel tasks.
A task collects one or more kernels and per-subtask metadata into a TaskDefinition that can be dry-run or submitted to the backend.
Attributes:
| Name | Type | Description |
|---|---|---|
program_language | str | Program language identifier stored on the task definition and used when serializing kernels. |
language_version | str | Program language version stored on the task definition and used when serializing kernels. Must be a semantic version. Set this directly for a static version, or override the |
kernel_serializer | KernelSerializer | Serializer used by the default |
future_cls | type[FutureType] | Future class used to construct the return value of |
num_subtasks abstractmethod property
num_subtasks: int
Number of subtasks in this task's definition.
program_language_version property
program_language_version: str
Program language version recorded when serializing kernels.
Defaults to the language_version attribute. Override this property in a subclass if the version needs to be computed with additional logic. The value must be a semantic version.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Semantic version string. |
create_task_definition
create_task_definition() -> TaskDefinition
Build a TaskDefinition from this task's kernels and subtasks.
Override this method directly if your use-case doesn't fit the API contract.
Returns:
| Name | Type | Description |
|---|---|---|
TaskDefinition | TaskDefinition | Definition ready to be submitted. |
Source code in src/bloqade/core/device/task.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
get_arguments abstractmethod
get_arguments() -> list[dict] | None
Return per-subtask argument dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One argument dictionary per subtask, or None when no arguments are set. |
Source code in src/bloqade/core/device/task.py
159 160 161 162 163 164 165 166 167 | |
get_kernels abstractmethod
get_kernels() -> list[ir.Method]
Return the kernels used to build the task's programs.
Returns:
| Type | Description |
|---|---|
list[Method] | list[ir.Method]: Kernels in program-index order. |
Source code in src/bloqade/core/device/task.py
150 151 152 153 154 155 156 157 | |
get_metadata abstractmethod
get_metadata() -> list[dict] | None
Return per-subtask metadata dictionaries.
Returns:
| Type | Description |
|---|---|
list[dict] | None | list[dict] | None: One metadata dictionary per subtask, or None when no metadata is set. |
Source code in src/bloqade/core/device/task.py
169 170 171 172 173 174 175 176 177 | |
get_num_shots abstractmethod
get_num_shots() -> list[int]
Return the per-subtask shot counts.
Returns:
| Type | Description |
|---|---|
list[int] | list[int]: Shot count for each subtask, in subtask order. |
Source code in src/bloqade/core/device/task.py
179 180 181 182 183 184 185 186 | |
program_index_for_subtask
program_index_for_subtask(i: int) -> int
Return the program index used by subtask i.
The default implementation maps each subtask to its own program. Parameter-scan tasks override this to reuse a single program.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i | int | Subtask index. | required |
Returns:
| Name | Type | Description |
|---|---|---|
int | int | Program index. |
Source code in src/bloqade/core/device/task.py
201 202 203 204 205 206 207 208 209 210 211 212 213 | |
programs
programs() -> list[Program]
Build the program list for the task definition.
Returns:
| Type | Description |
|---|---|
list[Program] | list[Program]: One |
Source code in src/bloqade/core/device/task.py
188 189 190 191 192 193 194 195 196 197 198 199 | |
run_async
run_async(
*,
dry_run: Literal[True],
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = ApiFetchOptions()
) -> None
run_async(
*,
dry_run: Literal[False],
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = ApiFetchOptions()
) -> FutureType
run_async(
*,
dry_run: bool,
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = ApiFetchOptions()
) -> FutureType | None
Validate the task and either dry-run or submit it.
Other Parameters:
| Name | Type | Description |
|---|---|---|
dry_run | bool | When True, print a summary and return None. When False, submit the task and return a future. |
storage | StorageBackend | None | Storage backend that will receive the task definition and later fetched shots. When None, a fresh |
fetch_options | ApiFetchOptions | Pagination and polling options attached to the returned future. Defaults to |
Returns:
| Type | Description |
|---|---|
FutureType | None | FutureType | None: Future attached to the submitted task when |
Raises:
| Type | Description |
|---|---|
ValueError | If argument or metadata lengths do not match |
Source code in src/bloqade/core/device/task.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
serialize_kernel
serialize_kernel(kernel: Method) -> str
Serialize a kernel into content suitable for the backend.
The default implementation first converts the kernel to a Kirin serialization module using program_language_version, then passes that module to kernel_serializer.encode. Binary serializer output is base64-encoded so it can travel through the API's string-valued Program.content field. String serializer output is returned as produced by the serializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel | Method | Kernel to serialize. | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Serialized kernel content for the submitted |
Source code in src/bloqade/core/device/task.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
submit_task_definition
submit_task_definition(
*,
task_definition: TaskDefinition,
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = ApiFetchOptions()
) -> FutureType
Submit a prepared task definition and return a future.
Other Parameters:
| Name | Type | Description |
|---|---|---|
task_definition | TaskDefinition | Task definition to submit. |
storage | StorageBackend | None | Storage backend that will receive the task definition. When None, a fresh |
fetch_options | ApiFetchOptions | Pagination and polling options attached to the returned future. Defaults to |
Returns:
| Name | Type | Description |
|---|---|---|
FutureType | FutureType | Future attached to the created task ID. |
Raises:
| Type | Description |
|---|---|
ValueError | If the backend response is missing a task ID. |
Source code in src/bloqade/core/device/task.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
summary
summary() -> str
Return a human-readable summary printed on dry-run.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Summary describing what would be submitted. |
Source code in src/bloqade/core/device/task.py
117 118 119 120 121 122 123 | |
validate_arguments
validate_arguments() -> None
Validate that argument and metadata lengths match subtask count.
Raises:
| Type | Description |
|---|---|
ValueError | If arguments or metadata length differs from |
Source code in src/bloqade/core/device/task.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |