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.hugr.executable

Expose typed jobs for direct HUGR program graphs.

Overview

FunctionDescription
resolve_runtime_bindingsRestore public argument values from whole or indexed runtime bindings.
ClassDescription
HugrExecutableExecute a HUGR artifact through a destination-independent typed API.
HugrExecutorExecute HUGR packages on local Selene or Nexus Helios.

Functions

resolve_runtime_bindings [source]

def resolve_runtime_bindings(
    compiled: CompiledProgram[Any],
    bindings: Mapping[str, Any] | None = None,
) -> dict[str, Any]

Restore public argument values from whole or indexed runtime bindings.

Whole and indexed forms may be used for different arguments. Specifying a container alongside any of its indexed descendants is ambiguous and rejected. Fixed dictionary entries follow the public ABI order; dictionaries whose keys remain runtime values require an explicit whole mapping.

Parameters:

NameTypeDescription
compiledCompiledProgram[Any]Artifact and public runtime input ABI.
bindingsMapping[str, Any] | NonePublic names or shared scalar keys, such as angles[1][2] and coeffs[(0, 1)].

Returns:

dict[str, Any] — dict[str, Any]: Independently owned whole arguments in native port order, dict[str, Any] — containing canonical bool, int, and finite float values. dict[str, Any] — Input mappings and their containers are never mutated.

Raises:

Classes

HugrExecutable [source]

class HugrExecutable

Execute a HUGR artifact through a destination-independent typed API.

HugrTranspiler.transpile also prepares shot-based expectation programs. Existing CompiledProgram[Package] values can be wrapped directly.

Parameters:

NameTypeDescription
compiledCompiledProgram[Any]HUGR artifact and public ABI.

Constructor

def __init__(self, compiled: CompiledProgram[Any]) -> None

Own a compiled artifact and its public ABI.

Parameters:

NameTypeDescription
compiledCompiledProgram[Any]Package, ABI and provenance.

Attributes

Methods

restore
def restore(
    self,
    executor: HugrExecutor,
    snapshot: JobSnapshot,
    bindings: Mapping[str, Any] | None = None,
) -> Job[Any]

Restore a typed local or remote job using the same compiled program.

Parameters:

NameTypeDescription
executorHugrExecutorDestination used to retrieve remote leaves.
snapshotJobSnapshotSaved operation and ordered execution tree.
bindingsMapping[str, Any] | NoneOriginal runtime parameter values.

Returns:

Job[Any] — Job[Any]: Restored sample, single-run, or expectation job.

Raises:

run
def run(
    self,
    executor: HugrExecutor,
    bindings: Mapping[str, Any] | None = None,
    *,
    shots: int | None = None,
    estimation: EstimationAccuracy | None = None,
) -> RunJob[Any] | ExpvalJob

Execute one ordinary shot or compute a program’s expectations.

For an expectation, ShotBased specifies measurements per nonidentity Pauli term; total device shots scale with that term count.

Parameters:

NameTypeDescription
executorHugrExecutorSelene or Helios destination.
bindingsMapping[str, Any] | NoneWhole or indexed runtime parameter values.
shotsint | NoneLegacy positive shots per expectation term. Mutually exclusive with estimation; both omitted uses 1024.
estimationEstimationAccuracy | NoneShared accuracy policy. Only ShotBased is supported for expectations. Ordinary programs ignore estimation and execute exactly one shot.

Returns:

RunJob[Any] | ExpvalJob — RunJob[Any] | ExpvalJob: Typed single return or estimated expectation.

Raises:

sample
def sample(
    self,
    executor: HugrExecutor,
    shots: int = 1024,
    bindings: Mapping[str, Any] | None = None,
) -> Job[SampleResult[Any]]

Sample the typed program with runtime parameter values.

Parameters:

NameTypeDescription
executorHugrExecutorSelene or Helios destination.
shotsintPositive number of repetitions, default 1024.
bindingsMapping[str, Any] | NoneRuntime values, keyed by whole argument names or shared indexed parameter names.

Returns:

Job[SampleResult[Any]] — Job[SampleResult[Any]]: Deferred structured sample counts.

Raises:


HugrExecutor [source]

class HugrExecutor

Execute HUGR packages on local Selene or Nexus Helios.

Parameters:

NameTypeDescription
targetstr | HugrExecutionTargetDestination, default selene.
optionsSeleneExecutionOptions | NexusExecutionOptions | NoneDestination-specific settings. Defaults to the destination defaults.

Raises:

Example:

>>> executor = HugrExecutor(options=SeleneExecutionOptions(seed=7))
>>> remote = HugrExecutor("helios", options=NexusExecutionOptions())

Constructor

def __init__(
    self,
    target: str | HugrExecutionTarget = HugrExecutionTarget.SELENE,
    *,
    options: SeleneExecutionOptions | NexusExecutionOptions | None = None,
) -> None

Initialize the destination and local compilation cache.

Parameters:

NameTypeDescription
targetstr | HugrExecutionTargetSelene or Helios destination.
optionsSeleneExecutionOptions | NexusExecutionOptions | NoneDestination-specific configuration.

Raises:

Attributes

Methods

retrieve
def retrieve(self, reference: ExecutionReference) -> ExecutionHandle[list[dict[str, Any]]]

Restore a remote tagged execution without resubmitting it.

Parameters:

NameTypeDescription
referenceExecutionReferenceSaved Nexus job reference.

Returns:

ExecutionHandle[list[dict[str, Any]]] — ExecutionHandle[list[dict[str, Any]]]: Restored remote handle.

Raises:

submit
def submit(self, package: Any, shots: int = 1024) -> ExecutionHandle[list[dict[str, Any]]]

Submit a zero-argument HUGR entrypoint with recorded outputs.

Use HugrExecutable for ABI-aware runtime arguments and typed jobs.

Parameters:

NameTypeDescription
packageAnyHUGR package with a zero-argument main function.
shotsintNumber of repetitions, default 1024.

Returns:

ExecutionHandle[list[dict[str, Any]]] — ExecutionHandle[list[dict[str, Any]]]: Tagged values for each shot.

Raises: