Skip to content

Task

KernelBatchTask dataclass

KernelBatchTask(
    *,
    context_name: str,
    qpu_mode: str | None = None,
    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.mixins.ConfigMixin[ConfigMixin]

                              bloqade.core.device.task.TaskABC --> bloqade.core.device.task.KernelBatchTask
                                bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
                                bloqade.core.device.mixins.ConfigMixin --> bloqade.core.device.mixins.AuthMixin
                




              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"
              click bloqade.core.device.mixins.ConfigMixin href "" "bloqade.core.device.mixins.ConfigMixin"
            

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
558
559
def get_arguments(self) -> list[dict] | None:
    return self.arguments

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
555
556
def get_kernels(self) -> list[ir.Method]:
    return self.kernels

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
566
567
def get_metadata(self) -> list[dict] | None:
    return self.metadata

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
561
562
563
564
def get_num_shots(self) -> list[int]:
    if isinstance(self.num_shots, int):
        return [self.num_shots] * self.num_subtasks
    return self.num_shots

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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
def summary(self) -> str:
    msg = "=" * 60 + "\n"
    msg += "DRY RUN -- NO PROGRAM WAS ACTUALLY SUBMITTED FOR EXECUTION\n"
    msg += f"Would now submit a task containing {len(self.kernels)} programs:\n"
    for i, kernel in enumerate(self.kernels):
        kernel_print = f"{kernel.sym_name}("
        if self.arguments is not None:
            for arg in self.arguments[i]:
                kernel_print += f"{arg}, "
        kernel_print += ")"
        shots = (
            self.num_shots if isinstance(self.num_shots, int) else self.num_shots[i]
        )
        msg += f"  * {kernel_print} - {shots} shots\n"
    msg += "Set dry_run=False to actually execute the programs.\n"
    msg += "=" * 60 + "\n"
    return msg

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
def encode(self, encoded_module: Any, /) -> str | bytes:
    """Encode a Kirin serialization module for `Program.content`."""
    ...

ParameterScanTask dataclass

ParameterScanTask(
    *,
    context_name: str,
    qpu_mode: str | None = None,
    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.mixins.ConfigMixin[ConfigMixin]

                              bloqade.core.device.task.TaskABC --> bloqade.core.device.task.ParameterScanTask
                                bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
                                bloqade.core.device.mixins.ConfigMixin --> bloqade.core.device.mixins.AuthMixin
                




              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"
              click bloqade.core.device.mixins.ConfigMixin href "" "bloqade.core.device.mixins.ConfigMixin"
            

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
454
455
def get_arguments(self) -> list[dict]:
    return self.arguments

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
451
452
def get_kernels(self) -> list[ir.Method]:
    return [self.kernel]

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
462
463
def get_metadata(self) -> list[dict] | None:
    return self.metadata

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
457
458
459
460
def get_num_shots(self) -> list[int]:
    if isinstance(self.num_shots, int):
        return [self.num_shots] * self.num_subtasks
    return self.num_shots

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
465
466
def program_index_for_subtask(self, i: int) -> int:
    return 0

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
468
469
470
471
472
473
474
475
def summary(self) -> str:
    msg = "=" * 60 + "\n"
    msg += "DRY RUN -- NO PROGRAM WAS ACTUALLY SUBMITTED FOR EXECUTION\n"
    msg += f"Would now submit a task containing {self.num_subtasks} subtasks.\n"
    msg += f"These subtasks correspond to parameter sets of the kernel {self.kernel.sym_name}.\n"
    msg += "Set dry_run=False to actually execute the parameter scan.\n"
    msg += "=" * 60
    return msg

SingleKernelTask dataclass

SingleKernelTask(
    *,
    context_name: str,
    qpu_mode: str | None = None,
    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.mixins.ConfigMixin[ConfigMixin]

                              bloqade.core.device.task.TaskABC --> bloqade.core.device.task.SingleKernelTask
                                bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
                                bloqade.core.device.mixins.ConfigMixin --> bloqade.core.device.mixins.AuthMixin
                




              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"
              click bloqade.core.device.mixins.ConfigMixin href "" "bloqade.core.device.mixins.ConfigMixin"
            

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
503
504
505
def get_arguments(self) -> list[dict] | None:
    if self.arguments is not None:
        return [self.arguments]

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
500
501
def get_kernels(self) -> list[ir.Method]:
    return [self.kernel]

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
510
511
512
def get_metadata(self) -> list[dict] | None:
    if self.metadata is not None:
        return [self.metadata]

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
507
508
def get_num_shots(self) -> list[int]:
    return [self.num_shots]

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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
def summary(self) -> str:
    msg = "=" * 60 + "\n"
    msg += "DRY RUN -- NO PROGRAM WAS ACTUALLY SUBMITTED FOR EXECUTION\n"
    msg += "Would now submit a task containing a single subtask for the kernel:\n"
    if self.arguments is not None:
        formatted_arguments = ", ".join(
            f"{key}={value}" for key, value in self.arguments.items()
        )
    else:
        formatted_arguments = ""
    kernel_print = f"{self.kernel.sym_name}({formatted_arguments})"
    shots = self.num_shots if isinstance(self.num_shots, int) else self.num_shots[0]
    msg += f"  * {kernel_print} - {shots} shots\n"
    msg += "Set dry_run=False to actually execute this kernel.\n"
    msg += "=" * 60
    return msg

TaskABC dataclass

TaskABC(
    *,
    context_name: str,
    qpu_mode: str | None = None,
    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.ConfigMixin[ConfigMixin]

                              bloqade.core.device.mixins.AuthMixin --> bloqade.core.device.task.TaskABC
                                bloqade.core.device.mixins.ConfigMixin --> bloqade.core.device.mixins.AuthMixin
                



              click bloqade.core.device.task.TaskABC href "" "bloqade.core.device.task.TaskABC"
              click bloqade.core.device.mixins.AuthMixin href "" "bloqade.core.device.mixins.AuthMixin"
              click bloqade.core.device.mixins.ConfigMixin href "" "bloqade.core.device.mixins.ConfigMixin"
            

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
qpu_mode str | None

Explicit qlam QPU mode used for task submission. When None, qlam-core resolves it from configuration.

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 program_language_version property if the version needs additional logic. Defaults to "0.1.0".

kernel_serializer KernelSerializer

Serializer used by the default serialize_kernel implementation. It must provide an encode method compatible with the value returned by kernel.dialects.encode(...). If encode returns bytes, the bytes are base64-encoded before being stored in Program.content; if it returns str, the value is used unchanged. Defaults to kirin.serialization.JSONSerializer.

future_cls type[FutureType]

Future class used to construct the return value of submit_task_definition. Defaults to Future.

group str | None

Name of the QLAM group for the task definition. When None, the ~/.qsh config group (plugins.tasks.group, then defaults.group) is applied at submission time; when that is also unset, QLAM selects the backend default group. Defaults to None.

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
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
266
267
def create_task_definition(self) -> 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:
        TaskDefinition: Definition ready to be submitted.
    """
    programs = self.programs()

    num_shots = self.get_num_shots()

    subtasks = []
    arguments = self.get_arguments()
    metadata = self.get_metadata()
    for i in range(self.num_subtasks):
        if arguments is not None:
            args = arguments[i]
        else:
            args = None

        if metadata is not None:
            subtask_metadata = TaskMetadata(user_metadata=json.dumps(metadata[i]))
        else:
            subtask_metadata = None

        subtasks.append(
            Subtask(
                program_index=self.program_index_for_subtask(i),
                num_shots=num_shots[i],
                arguments=args,
                subtask_metadata=subtask_metadata,
            )
        )

    program_language_with_version = f"{self.program_language}.v{self.program_language_version.removeprefix('v')}"
    return TaskDefinition(
        program_language=program_language_with_version,
        programs=programs,
        subtasks=subtasks,
        group_id=None,
    )

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
169
170
171
172
173
174
175
176
177
@abstractmethod
def get_arguments(self) -> list[dict] | None:
    """Return per-subtask argument dictionaries.

    Returns:
        list[dict] | None: One argument dictionary per subtask, or None
            when no arguments are set.
    """
    ...

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
160
161
162
163
164
165
166
167
@abstractmethod
def get_kernels(self) -> list[ir.Method]:
    """Return the kernels used to build the task's programs.

    Returns:
        list[ir.Method]: Kernels in program-index order.
    """
    ...

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
179
180
181
182
183
184
185
186
187
@abstractmethod
def get_metadata(self) -> list[dict] | None:
    """Return per-subtask metadata dictionaries.

    Returns:
        list[dict] | None: One metadata dictionary per subtask, or None
            when no metadata is set.
    """
    ...

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
189
190
191
192
193
194
195
196
@abstractmethod
def get_num_shots(self) -> list[int]:
    """Return the per-subtask shot counts.

    Returns:
        list[int]: Shot count for each subtask, in subtask order.
    """
    ...

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
211
212
213
214
215
216
217
218
219
220
221
222
223
def program_index_for_subtask(self, 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.

    Args:
        i (int): Subtask index.

    Returns:
        int: Program index.
    """
    return i

programs

programs() -> list[Program]

Build the program list for the task definition.

Returns:

Type Description
list[Program]

list[Program]: One Program per kernel returned by get_kernels, serialized via serialize_kernel.

Source code in src/bloqade/core/device/task.py
198
199
200
201
202
203
204
205
206
207
208
209
def programs(self) -> list[Program]:
    """Build the program list for the task definition.

    Returns:
        list[Program]: One `Program` per kernel returned by
            `get_kernels`, serialized via `serialize_kernel`.
    """
    kernels = self.get_kernels()
    programs = []
    for kernel in kernels:
        programs.append(Program(content=self.serialize_kernel(kernel)))
    return programs

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 DictStorage is used (in-memory; not persisted across processes). Defaults to None.

fetch_options ApiFetchOptions

Pagination and polling options attached to the returned future. Defaults to ApiFetchOptions().

Returns:

Type Description
FutureType | None

FutureType | None: Future attached to the submitted task when dry_run is False; otherwise None.

Raises:

Type Description
ValueError

If argument or metadata lengths do not match num_subtasks.

Source code in src/bloqade/core/device/task.py
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
351
352
def run_async(
    self,
    *,
    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.

    Keyword Args:
        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
            `DictStorage` is used (in-memory; not persisted across
            processes). Defaults to None.
        fetch_options (ApiFetchOptions): Pagination and polling options
            attached to the returned future. Defaults to
            `ApiFetchOptions()`.

    Returns:
        FutureType | None: Future attached to the submitted task when
            `dry_run` is False; otherwise None.

    Raises:
        ValueError: If argument or metadata lengths do not match
            `num_subtasks`.
    """
    self.validate_arguments()

    task_def = self.create_task_definition()

    if dry_run:
        print(self.summary())
        return

    return self.submit_task_definition(
        task_definition=task_def,
        storage=storage,
        fetch_options=fetch_options,
    )

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 Program.

Source code in src/bloqade/core/device/task.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
115
116
117
118
119
def serialize_kernel(self, kernel: ir.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.

    Args:
        kernel (ir.Method): Kernel to serialize.

    Returns:
        str: Serialized kernel content for the submitted `Program`.
    """

    encoded_module = kernel.dialects.encode(
        kernel, version=self.program_language_version
    )
    payload = self.kernel_serializer.encode(encoded_module)

    if isinstance(payload, bytes):
        return base64.b64encode(payload).decode("ascii")

    if isinstance(payload, str):
        return payload

    raise TypeError(
        "kernel_serializer.encode must return str or bytes, "
        f"got {type(payload).__name__}"
    )

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 DictStorage is used (in-memory; not persisted across processes). Defaults to None.

fetch_options ApiFetchOptions

Pagination and polling options attached to the returned future. Defaults to ApiFetchOptions().

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
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
417
418
419
420
421
422
def submit_task_definition(
    self,
    *,
    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.

    Keyword Args:
        task_definition (TaskDefinition): Task definition to submit.
        storage (StorageBackend | None): Storage backend that will receive
            the task definition. When None, a fresh `DictStorage` is used
            (in-memory; not persisted across processes). Defaults to None.
        fetch_options (ApiFetchOptions): Pagination and polling options
            attached to the returned future. Defaults to
            `ApiFetchOptions()`.

    Returns:
        FutureType: Future attached to the created task ID.

    Raises:
        ValueError: If the backend response is missing a task ID.
    """
    if storage is None:
        storage = DictStorage()

    self.authenticate()

    if task_definition.group_id is None:
        group = self._configured_group()
        if group is not None:
            task_definition = task_definition.model_copy(
                update={"group_id": self._resolve_group_id(group)}
            )

    task_request = TaskCreationRequest(root=task_definition)
    with TasksClient(self.app_context) as tasks_client:
        created_task = self.call_with_auth_refresh(
            lambda: tasks_client.create(  # type: ignore
                qpu_mode=self.qpu_mode,
                body=task_request,
            )
        )

    task_id = created_task.id

    if not task_id:
        raise ValueError(
            f"Couldn't get id of created task {created_task}. Please report this issue!"
        )

    logger.info(f"Submitted task with ID: {task_id}")

    storage.add_task_definition(task_id, task_definition, created_task.created_date)

    return self.future_cls(
        task_id=task_id,
        fetch_options=fetch_options,
        storage=storage,
        context_name=self.context_name,
        qpu_mode=self.qpu_mode,
    )

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
127
128
129
130
131
132
133
def summary(self) -> str:
    """Return a human-readable summary printed on dry-run.

    Returns:
        str: Summary describing what would be submitted.
    """
    return f"Would now submit {self.num_subtasks} subtasks"

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 num_subtasks.

Source code in src/bloqade/core/device/task.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def validate_arguments(self) -> None:
    """Validate that argument and metadata lengths match subtask count.

    Raises:
        ValueError: If arguments or metadata length differs from
            `num_subtasks`.
    """
    arguments = self.get_arguments()
    if arguments is not None and len(arguments) != self.num_subtasks:
        raise ValueError(
            f"Length mismatch: got {len(arguments)} sets of arguments for {self.num_subtasks} subtasks!"
        )

    metadata = self.get_metadata()
    if metadata is not None and len(metadata) != self.num_subtasks:
        raise ValueError(
            f"Length mismatch: got {len(metadata)} sets of metadata for {self.num_subtasks} subtasks!"
        )

    num_shots = self.get_num_shots()
    if len(num_shots) != self.num_subtasks:
        raise ValueError(
            f"Length mismatch: got {len(num_shots)} shot counts for {self.num_subtasks} subtasks!"
        )