Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

qamomile.braket.execution

Adapt Amazon Braket task lifecycles to Qamomile execution handles.

Overview

ClassDescription
BraketExecutionHandleWrap one Braket task or a task batch without blocking submission.
BraketExecutionOptionsConfigure Braket task and batch submission without flat kwargs.
ExecutionErrorError during program execution.
ExecutionHandleExpose an engine execution without forcing immediate result retrieval.
ExecutionReferenceStore secret-free identifiers needed to restore remote execution.
ExecutionSnapshotStore a remote leaf, a local value, or an ordered execution group.
ExecutionSnapshotKindIdentify the reconstruction contract of an execution snapshot node.
JobStatusDescribe 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:

NameTypeDescription
tasksSequence[Any]Provider quantum tasks when individually addressable.
result_loaderCallable[[], Sequence[Any]]Blocking raw-result loader that does not perform implicit retries unless configured.
decoderCallable[[Sequence[Any]], ResultT]Engine result decoder.
referenceExecutionReference | NoneSerializable AWS reference.
reference_factoryCallable[[], ExecutionReference | None] | NoneDynamic reference builder for batches that explicitly resubmit failed tasks. Defaults to none.
nativeobjectNative Braket task or batch object.
poll_interval_secondsfloatLocal status polling interval.
default_timeout_secondsfloat | NoneDefault local result timeout. Defaults to no timeout.
allow_unsuccessful_loaderboolWhether 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,
) -> None

Initialize a Braket-backed execution handle.

Parameters:

NameTypeDescription
tasksSequence[Any]Individually addressable Braket tasks.
result_loaderCallable[[], Sequence[Any]]Blocking loader.
decoderCallable[[Sequence[Any]], ResultT]Result decoder.
referenceExecutionReference | NoneSerializable AWS reference.
reference_factoryCallable[[], ExecutionReference | None] | NoneDynamic reference builder. Defaults to none.
nativeobjectNative task or batch.
poll_interval_secondsfloatPositive local polling interval.
default_timeout_secondsfloat | NonePositive default local result timeout. Defaults to no timeout.
allow_unsuccessful_loaderboolWhether failed children may be handled by the explicit result loader. Defaults to false.

Raises:

Attributes

Methods

cancel
def cancel(self) -> None

Request 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) -> object

Return 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) -> ResultT

Wait for and decode all Braket task results.

Parameters:

NameTypeDescription
timeoutfloat | NoneMaximum 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:

snapshot
def snapshot(self) -> ExecutionSnapshot

Capture 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:

status
def status(self) -> JobStatus

Return the aggregate Braket task status.

Returns:

JobStatus — Provider-independent aggregate status.


BraketExecutionOptions [source]

class BraketExecutionOptions

Configure Braket task and batch submission without flat kwargs.

Parameters:

NameTypeDescription
s3_destination_foldertuple[str, str] | NoneS3 bucket and prefix for AWS task results. Defaults to the SDK configuration.
reservation_arnstr | NoneDirect reservation ARN. Defaults to None.
max_parallelint | NoneMaximum AWS batch concurrency. Defaults to the SDK configuration.
poll_timeout_secondsfloat | NoneProvider result polling timeout and default local result-wait limit. Defaults to the SDK configuration with no local limit.
poll_interval_secondsfloat | NoneProvider status polling interval. Defaults to the SDK configuration.
batch_max_retriesintMaximum explicit Braket batch resubmissions. Defaults to zero to prevent implicit additional QPU cost.
task_optionsMapping[str, Any]Additional device.run options.
batch_optionsMapping[str, Any]Additional device.run_batch options.

Raises:

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(),
) -> None

Attributes

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

Methods

cancel
def cancel(self) -> None

Request 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) -> object

Return 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) -> ResultT

Wait for and return the engine-neutral raw result.

Parameters:

NameTypeDescription
timeoutfloat | NoneMaximum local wait in seconds. None delegates the wait policy to the provider.

Returns:

ResultT — Raw result normalized by the engine executor.

Raises:

result_async
def result_async(self, timeout: float | None = None) -> ResultT

Wait asynchronously for the engine-neutral raw result.

Parameters:

NameTypeDescription
timeoutfloat | NoneMaximum local wait in seconds. Defaults to provider behavior when None.

Returns:

ResultT — Raw result normalized by the engine executor.

Raises:

snapshot
def snapshot(self) -> ExecutionSnapshot

Capture 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:

status
def status(self) -> JobStatus

Return the current provider-independent execution status.

Returns:

JobStatus — Current normalized status.


ExecutionReference [source]

class ExecutionReference

Store secret-free identifiers needed to restore remote execution.

Parameters:

NameTypeDescription
providerstrStable provider or adapter name.
job_idstuple[str, ...]One or more provider job identifiers.
targetstr | NoneProvider target or device identifier. Defaults to None.
group_idstr | NoneSession, batch, program, or parent identifier. Defaults to None.
contextMapping[str, str]Additional non-secret identifiers needed to restore the job. Defaults to an empty mapping.

Raises:

Constructor

def __init__(
    self,
    provider: str,
    job_ids: tuple[str, ...],
    target: str | None = None,
    group_id: str | None = None,
    context: Mapping[str, str] = dict(),
) -> None

Attributes

Methods

from_dict
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> ExecutionReference

Reconstruct a provider reference from JSON-compatible data.

Parameters:

NameTypeDescription
dataMapping[str, Any]Mapping produced by :meth:to_dict.

Returns:

ExecutionReference — Validated provider execution reference.

Raises:

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 ExecutionSnapshot

Store 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:

NameTypeDescription
kindstr | ExecutionSnapshotKindOne of remote, local, or composite, normalized to an enum member.
referenceExecutionReference | NoneRequired only for remote leaves.
valueAnySupported native result for local leaves. Defaults to None.
childrentuple[ExecutionSnapshot, ...]Ordered composite children. Defaults to an empty tuple.

Raises:

Constructor

def __init__(
    self,
    kind: str | ExecutionSnapshotKind,
    reference: ExecutionReference | None = None,
    value: Any = None,
    children: tuple[ExecutionSnapshot, ...] = (),
) -> None

Attributes

Methods

from_dict
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> ExecutionSnapshot

Reconstruct an execution tree with strict node and value validation.

Parameters:

NameTypeDescription
dataMapping[str, Any]Mapping produced by :meth:to_dict.

Returns:

ExecutionSnapshot — Validated execution structure.

Raises:

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:

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:

NameTypeDescription
restore_referenceCallable[[ExecutionReference], ExecutionHandle[Any]]Provider-specific callback for one complete remote leaf.

Returns:

ExecutionHandle[Any] — ExecutionHandle[Any]: Reconstructed raw execution lifecycle.

Raises:

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:


ExecutionSnapshotKind [source]

class ExecutionSnapshotKind(StrEnum)

Identify the reconstruction contract of an execution snapshot node.

Attributes


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