Task
KernelBatchTask dataclass
KernelBatchTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
group: str | None = None,
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
552 553 | |
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
549 550 | |
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
560 561 | |
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
555 556 557 558 | |
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
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
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
29 30 31 | |
ParameterScanTask dataclass
ParameterScanTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
group: str | None = None,
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
448 449 | |
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
445 446 | |
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
456 457 | |
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
451 452 453 454 | |
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
459 460 | |
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 | |
SingleKernelTask dataclass
SingleKernelTask(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
group: str | None = None,
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
497 498 499 | |
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
494 495 | |
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
504 505 506 | |
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
501 502 | |
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
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
TaskABC dataclass
TaskABC(
*,
context_name: str,
program_language: str,
language_version: str = "0.1.0",
kernel_serializer: KernelSerializer = JSONSerializer(),
group: str | None = None,
future_cls: type[FutureType] = Future
)
Bases: AuthMixin, ABC, Generic[FutureType]
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 |
group | str | None | Name of the QLAM group for the task definition. When None, the |
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
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 258 259 260 261 262 263 264 265 | |
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
167 168 169 170 171 172 173 174 175 | |
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
158 159 160 161 162 163 164 165 | |
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
177 178 179 180 181 182 183 184 185 | |
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
187 188 189 190 191 192 193 194 | |
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
209 210 211 212 213 214 215 216 217 218 219 220 221 | |
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
196 197 198 199 200 201 202 203 204 205 206 207 | |
run_async
run_async(
*,
dry_run: Literal[True],
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = DEFAULT_FETCH_OPTIONS
) -> None
run_async(
*,
dry_run: Literal[False],
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = DEFAULT_FETCH_OPTIONS
) -> FutureType
run_async(
*,
dry_run: bool,
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = DEFAULT_FETCH_OPTIONS
) -> 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
310 311 312 313 314 315 316 317 318 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 | |
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
86 87 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 115 116 117 | |
submit_task_definition
submit_task_definition(
*,
task_definition: TaskDefinition,
storage: StorageBackend | None = None,
fetch_options: ApiFetchOptions = DEFAULT_FETCH_OPTIONS
) -> FutureType
Submit a prepared task definition and return a future.
When the definition does not set a group ID, a task-level group name takes precedence over the ~/.qsh config group (plugins.tasks.group, then defaults.group). The selected name is resolved before submission. When neither is set, the group is omitted and QLAM selects the backend default group.
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
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
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
125 126 127 128 129 130 131 | |
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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |