Adapt Amazon Braket task lifecycles to Qamomile execution handles.
Overview¶
| Class | Description |
|---|---|
BraketExecutionHandle | Wrap one Braket task or a task batch without blocking submission. |
BraketExecutionOptions | Configure Braket task and batch submission without flat kwargs. |
ExecutionError | Error during program execution. |
ExecutionHandle | Expose an engine execution without forcing immediate result retrieval. |
ExecutionReference | Store secret-free identifiers needed to restore remote execution. |
ExecutionSnapshot | Store a remote leaf, a local value, or an ordered execution group. |
ExecutionSnapshotKind | Identify the reconstruction contract of an execution snapshot node. |
JobStatus | Describe a provider-independent execution state. |
Classes¶
BraketExecutionHandle [source]¶
class BraketExecutionHandle(ExecutionHandle[ResultT], Generic[ResultT])Wrap one Braket task or a task batch without blocking submission.
Parameters:
| Name | Type | Description |
|---|---|---|
tasks | Sequence[Any] | Provider quantum tasks when individually addressable. |
result_loader | Callable[[], Sequence[Any]] | Blocking raw-result loader that does not perform implicit retries unless configured. |
decoder | Callable[[Sequence[Any]], ResultT] | Engine result decoder. |
reference | ExecutionReference | None | Serializable AWS reference. |
reference_factory | Callable[[], ExecutionReference | None] | None | Dynamic reference builder for batches that explicitly resubmit failed tasks. Defaults to none. |
native | object | Native Braket task or batch object. |
poll_interval_seconds | float | Local status polling interval. |
default_timeout_seconds | float | None | Default local result timeout. Defaults to no timeout. |
allow_unsuccessful_loader | bool | Whether the result loader owns explicit recovery from failed child tasks. Defaults to false. |
Constructor¶
def __init__(
self,
*,
tasks: Sequence[Any],
result_loader: Callable[[], Sequence[Any]],
decoder: Callable[[Sequence[Any]], ResultT],
reference: ExecutionReference | None,
reference_factory: Callable[[], ExecutionReference | None] | None = None,
native: object,
poll_interval_seconds: float = 1.0,
default_timeout_seconds: float | None = None,
allow_unsuccessful_loader: bool = False,
) -> NoneInitialize a Braket-backed execution handle.
Parameters:
| Name | Type | Description |
|---|---|---|
tasks | Sequence[Any] | Individually addressable Braket tasks. |
result_loader | Callable[[], Sequence[Any]] | Blocking loader. |
decoder | Callable[[Sequence[Any]], ResultT] | Result decoder. |
reference | ExecutionReference | None | Serializable AWS reference. |
reference_factory | Callable[[], ExecutionReference | None] | None | Dynamic reference builder. Defaults to none. |
native | object | Native task or batch. |
poll_interval_seconds | float | Positive local polling interval. |
default_timeout_seconds | float | None | Positive default local result timeout. Defaults to no timeout. |
allow_unsuccessful_loader | bool | Whether failed children may be handled by the explicit result loader. Defaults to false. |
Raises:
ValueError— If the polling interval or default timeout is invalid.
Attributes¶
native: object | None Return the native Braket task or batch.
Methods¶
cancel¶
def cancel(self) -> NoneRequest best-effort cancellation of every unfinished task.
metadata¶
def metadata(self) -> Mapping[str, Any]Return cached-or-provider metadata for every task.
Returns:
Mapping[str, Any] — Mapping[str, Any]: Child task metadata in submission order.
raw_status¶
def raw_status(self) -> objectReturn raw task states in stable order.
Returns:
object — One state string or a tuple of state strings.
references¶
def references(self) -> tuple[ExecutionReference, ...]Return the logical Braket execution reference.
Returns:
tuple[ExecutionReference, ...] — tuple[ExecutionReference, ...]: Empty for local tasks, otherwise
one reference containing every task ARN.
result¶
def result(self, timeout: float | None = None) -> ResultTWait for and decode all Braket task results.
Parameters:
| Name | Type | Description |
|---|---|---|
timeout | float | None | Maximum local status-wait time in seconds. None uses the configured Braket polling timeout when one exists, otherwise waits indefinitely. Expiration does not cancel remote tasks. |
Returns:
ResultT — Decoded engine-neutral result.
Raises:
TimeoutError— Iftimeoutexpires before terminal state.ValueError— Iftimeoutis negative or not finite.ExecutionError— If a task fails, is cancelled, or omits a result.
snapshot¶
def snapshot(self) -> ExecutionSnapshotCapture an AWS reference or an already retrieved local result.
AWS tasks retain their provider references after result retrieval.
Local tasks require a successful result() call first; this method
never retrieves results or waits for another result caller.
Returns:
ExecutionSnapshot — One remote reference or a detached local value.
Raises:
TypeError— If a cached local result contains unsupported objects.ValueError— If no reference or cached result exists, or the cached value is nonfinite, cyclic, or nested too deeply.
status¶
def status(self) -> JobStatusReturn the aggregate Braket task status.
Returns:
JobStatus — Provider-independent aggregate status.
BraketExecutionOptions [source]¶
class BraketExecutionOptionsConfigure Braket task and batch submission without flat kwargs.
Parameters:
| Name | Type | Description |
|---|---|---|
s3_destination_folder | tuple[str, str] | None | S3 bucket and prefix for AWS task results. Defaults to the SDK configuration. |
reservation_arn | str | None | Direct reservation ARN. Defaults to None. |
max_parallel | int | None | Maximum AWS batch concurrency. Defaults to the SDK configuration. |
poll_timeout_seconds | float | None | Provider result polling timeout and default local result-wait limit. Defaults to the SDK configuration with no local limit. |
poll_interval_seconds | float | None | Provider status polling interval. Defaults to the SDK configuration. |
batch_max_retries | int | Maximum explicit Braket batch resubmissions. Defaults to zero to prevent implicit additional QPU cost. |
task_options | Mapping[str, Any] | Additional device.run options. |
batch_options | Mapping[str, Any] | Additional device.run_batch options. |
Raises:
ValueError— If options contain executor-owned argument names or an invalid numeric value.
Constructor¶
def __init__(
self,
s3_destination_folder: tuple[str, str] | None = None,
reservation_arn: str | None = None,
max_parallel: int | None = None,
poll_timeout_seconds: float | None = None,
poll_interval_seconds: float | None = None,
batch_max_retries: int = 0,
task_options: Mapping[str, Any] = dict(),
batch_options: Mapping[str, Any] = dict(),
) -> NoneAttributes¶
batch_max_retries: intbatch_options: Mapping[str, Any]max_parallel: int | Nonepoll_interval_seconds: float | Nonepoll_timeout_seconds: float | Nonereservation_arn: str | Nones3_destination_folder: tuple[str, str] | Nonetask_options: Mapping[str, Any]
Methods¶
batch_kwargs¶
def batch_kwargs(self) -> dict[str, Any]Build keyword arguments for a Braket task batch.
Returns:
dict[str, Any] — dict[str, Any]: Validated device.run_batch keyword arguments.
task_kwargs¶
def task_kwargs(self) -> dict[str, Any]Build keyword arguments for one Braket task.
Returns:
dict[str, Any] — dict[str, Any]: Validated device.run keyword arguments.
ExecutionError [source]¶
class ExecutionError(QamomileCompileError)Error during program execution.
ExecutionHandle [source]¶
class ExecutionHandle(ABC, Generic[ResultT])Expose an engine execution without forcing immediate result retrieval.
Attributes¶
native: object | None Return the wrapped provider-native task when available.
Methods¶
cancel¶
def cancel(self) -> NoneRequest best-effort cancellation.
Cancellation is intentionally not reported as a boolean because
providers may accept a request after execution has already started.
Call :meth:status to observe the eventual state.
metadata¶
def metadata(self) -> Mapping[str, Any]Return optional provider execution metadata.
Returns:
Mapping[str, Any] — Mapping[str, Any]: Provider metadata such as timestamps or usage.
raw_status¶
def raw_status(self) -> objectReturn provider-specific status information.
Returns:
object — Provider status value, or the normalized status when no
richer value exists.
references¶
def references(self) -> tuple[ExecutionReference, ...]Return serializable remote execution references.
Returns:
tuple[ExecutionReference, ...] — tuple[ExecutionReference, ...]: Secret-free provider references.
result¶
def result(self, timeout: float | None = None) -> ResultTWait for and return the engine-neutral raw result.
Parameters:
| Name | Type | Description |
|---|---|---|
timeout | float | None | Maximum local wait in seconds. None delegates the wait policy to the provider. |
Returns:
ResultT — Raw result normalized by the engine executor.
Raises:
TimeoutError— If the local wait expires before completion.
result_async¶
def result_async(self, timeout: float | None = None) -> ResultTWait asynchronously for the engine-neutral raw result.
Parameters:
| Name | Type | Description |
|---|---|---|
timeout | float | None | Maximum local wait in seconds. Defaults to provider behavior when None. |
Returns:
ResultT — Raw result normalized by the engine executor.
Raises:
TimeoutError— If the local wait expires before completion.
snapshot¶
def snapshot(self) -> ExecutionSnapshotCapture one remote execution without fetching its result.
Adapters exposing several logical references must override this method with an explicit reconstruction structure. A provider reference may itself contain multiple physical job IDs.
Returns:
ExecutionSnapshot — One opaque provider execution.
Raises:
ValueError— If references are absent or their grouping is unknown.
status¶
def status(self) -> JobStatusReturn the current provider-independent execution status.
Returns:
JobStatus — Current normalized status.
ExecutionReference [source]¶
class ExecutionReferenceStore secret-free identifiers needed to restore remote execution.
Parameters:
| Name | Type | Description |
|---|---|---|
provider | str | Stable provider or adapter name. |
job_ids | tuple[str, ...] | One or more provider job identifiers. |
target | str | None | Provider target or device identifier. Defaults to None. |
group_id | str | None | Session, batch, program, or parent identifier. Defaults to None. |
context | Mapping[str, str] | Additional non-secret identifiers needed to restore the job. Defaults to an empty mapping. |
Raises:
ValueError— If the provider name or any job identifier is empty.TypeError— If identifiers or context have incompatible types.
Constructor¶
def __init__(
self,
provider: str,
job_ids: tuple[str, ...],
target: str | None = None,
group_id: str | None = None,
context: Mapping[str, str] = dict(),
) -> NoneAttributes¶
context: Mapping[str, str]group_id: str | Nonejob_ids: tuple[str, ...]provider: strtarget: str | None
Methods¶
from_dict¶
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> ExecutionReferenceReconstruct a provider reference from JSON-compatible data.
Parameters:
| Name | Type | Description |
|---|---|---|
data | Mapping[str, Any] | Mapping produced by :meth:to_dict. |
Returns:
ExecutionReference — Validated provider execution reference.
Raises:
KeyError— If a required provider or job identifier field is absent.TypeError— If a field has an incompatible type.ValueError— If provider or job identifiers are empty.
to_dict¶
def to_dict(self) -> dict[str, Any]Convert the provider reference to JSON-compatible data.
Returns:
dict[str, Any] — dict[str, Any]: Provider identifiers and decoding context without
credentials or SDK objects.
ExecutionSnapshot [source]¶
class ExecutionSnapshotStore a remote leaf, a local value, or an ordered execution group.
Provider leaves may identify several physical jobs or produce native batch results. Composite children retain their result boundaries independently of the number of provider identifiers. Local values contain raw engine-neutral results, before the executable applies its public result conversion. Trees and local values support at most 100 levels of nesting.
Parameters:
| Name | Type | Description |
|---|---|---|
kind | str | ExecutionSnapshotKind | One of remote, local, or composite, normalized to an enum member. |
reference | ExecutionReference | None | Required only for remote leaves. |
value | Any | Supported native result for local leaves. Defaults to None. |
children | tuple[ExecutionSnapshot, ...] | Ordered composite children. Defaults to an empty tuple. |
Raises:
TypeError— If fields or local result types are unsupported.ValueError— If fields conflict with the node kind or values are invalid.
Constructor¶
def __init__(
self,
kind: str | ExecutionSnapshotKind,
reference: ExecutionReference | None = None,
value: Any = None,
children: tuple[ExecutionSnapshot, ...] = (),
) -> NoneAttributes¶
children: tuple[ExecutionSnapshot, ...]kind: str | ExecutionSnapshotKindreference: ExecutionReference | Nonevalue: Any
Methods¶
from_dict¶
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> ExecutionSnapshotReconstruct an execution tree with strict node and value validation.
Parameters:
| Name | Type | Description |
|---|---|---|
data | Mapping[str, Any] | Mapping produced by :meth:to_dict. |
Returns:
ExecutionSnapshot — Validated execution structure.
Raises:
TypeError— If node fields have incompatible types.ValueError— If kinds, fields, references, or local values are invalid.
references¶
def references(self) -> tuple[ExecutionReference, ...]Collect provider leaves in order without discarding tree structure.
This list supports diagnostics; restoration uses the complete tree.
Returns:
tuple[ExecutionReference, ...] — tuple[ExecutionReference, ...]: Detached remote references in order.
Raises:
TypeError— If mutable reference fields became incompatible.ValueError— If mutable reference fields became invalid.
restore¶
def restore(
self,
restore_reference: Callable[[ExecutionReference], ExecutionHandle[Any]],
) -> ExecutionHandle[Any]Reattach remote leaves and rebuild local values and ordered groups.
The callback must reattach an existing provider execution. This method neither retrieves remote results nor submits any execution.
Parameters:
| Name | Type | Description |
|---|---|---|
restore_reference | Callable[[ExecutionReference], ExecutionHandle[Any]] | Provider-specific callback for one complete remote leaf. |
Returns:
ExecutionHandle[Any] — ExecutionHandle[Any]: Reconstructed raw execution lifecycle.
Raises:
TypeError— If local data is unsupported or the callback returns an incompatible handle.ValueError— If local values or references became invalid.Exception— If the provider restoration callback fails.
to_dict¶
def to_dict(self) -> dict[str, Any]Serialize the execution tree and type-preserving local values.
Returns:
dict[str, Any] — dict[str, Any]: JSON-compatible execution tree.
Raises:
TypeError— If mutable local data was changed to unsupported types.ValueError— If mutable local data or references became invalid.
ExecutionSnapshotKind [source]¶
class ExecutionSnapshotKind(StrEnum)Identify the reconstruction contract of an execution snapshot node.
Attributes¶
COMPOSITELOCALREMOTE
JobStatus [source]¶
class JobStatus(Enum)Describe a provider-independent execution state.
The numeric values of the original four states remain stable for serialization compatibility.
Attributes¶
CANCELLEDCANCELLINGCOMPLETEDFAILEDPARTIALPENDINGQUEUEDRUNNINGUNKNOWN