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.qiskit.runtime_execution

Adapt Qiskit Runtime primitive jobs to Qamomile execution handles.

Overview

ClassDescription
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.
RuntimeExecutionHandleExpose one Runtime primitive job without blocking its submission.

Classes

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


RuntimeExecutionHandle [source]

class RuntimeExecutionHandle(ExecutionHandle[ResultT], Generic[ResultT])

Expose one Runtime primitive job without blocking its submission.

Result retrieval runs once in a daemon thread so local wait limits also work with injected Qiskit primitive jobs whose result() method has no timeout argument. Expiring a wait neither cancels nor resubmits the job.

Parameters:

NameTypeDescription
jobAnyNative Runtime or compatible local primitive job.
decoderCallable[[Any], ResultT]Convert the primitive result into a backend-neutral value.
referenceExecutionReference | NoneSecret-free restoration reference. Defaults to none without a restoration service.

Constructor

def __init__(
    self,
    job: Any,
    decoder: Callable[[Any], ResultT],
    reference: ExecutionReference | None = None,
) -> None

Initialize lazy retrieval and provider lifecycle delegation.

Parameters:

NameTypeDescription
jobAnyNative primitive job.
decoderCallable[[Any], ResultT]Result conversion function.
referenceExecutionReference | NoneSerializable restoration reference. Defaults to none.

Attributes

Methods

cancel
def cancel(self) -> None

Request cancellation when the primitive job is unfinished.

Raises:

metadata
def metadata(self) -> Mapping[str, Any]

Return native Runtime job metrics when supported.

Returns:

Mapping[str, Any] — Mapping[str, Any]: Provider metrics or an empty mapping when the local job does not expose metrics.

Raises:

raw_status
def raw_status(self) -> object

Read the native string or Qiskit status enum.

Returns:

object — Unmodified provider status.

Raises:

references
def references(self) -> tuple[ExecutionReference, ...]

Return the job’s secret-free restoration reference when available.

Returns:

tuple[ExecutionReference, ...] — tuple[ExecutionReference, ...]: One remote reference or an empty tuple when no restoration service was configured.

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

Wait for the decoded primitive result with a local wait limit.

Successful results and execution failures are cached. A provider-side result-wait timeout permits another retrieval attempt, while an expired local wait leaves the existing retrieval running.

Parameters:

NameTypeDescription
timeoutfloat | NoneMaximum local wait in seconds, including zero for an immediate check. None waits indefinitely.

Returns:

ResultT — Cached or newly decoded primitive result.

Raises:

snapshot
def snapshot(self) -> ExecutionSnapshot

Capture a Runtime reference or an already decoded result.

Restorable jobs retain their provider reference after result retrieval. Without a reference, result retrieval must have completed successfully before capturing its cached value. This method never starts retrieval, queries the provider, or waits for another result caller.

Returns:

ExecutionSnapshot — One remote reference or a detached local value.

Raises:

status
def status(self) -> JobStatus

Return the normalized provider or cached result status.

Returns:

JobStatus — Current provider-independent execution state.

Raises: