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

HUGR program-graph target for Qamomile.

The engine lowers prepared hierarchical Qamomile semantics directly to a HUGR package. It deliberately bypasses circuit segmentation and CircuitProgram so function boundaries, typed dataflow, and hybrid control can be preserved. Generated quantum operations use the same tket.* extensions as Guppy, making the result interoperable with the Guppy/HUGR ecosystem.

Destructive measurements consume qubits with MeasureFree. Projections retain their measured state with Measure. Direct measurement/reset pairs use MeasureReset when their quantum wire and ordering permit fusion. Opaque measurement bits are converted to the existing native Boolean carrier.

HugrExecutable.qir and qir_info expose the latest complete H2 payloads and detached restoration metadata from ordinary sample and run calls. These records are ready before authentication or upload and survive a lost submission response. Compatible consecutive H2 calls reuse the exact bytes. Existing typed jobs, snapshots, and restoration keep their usual contracts.

Overview

ClassDescription
HugrCompilationPlanDescribe the callable symbols emitted into one HUGR module.
HugrExecutableExecute a HUGR artifact through a destination-independent typed API.
HugrExecutionTargetIdentify a supported HUGR execution destination.
HugrExecutorExecute HUGR packages on local Selene or Nexus devices.
HugrTargetPlan, lower, package, and validate a Guppy-compatible HUGR target.
HugrTranspilerBuild HUGR executables and Guppy-compatible compiled packages.
NexusExecutionOptionsConfigure execution on a Helios or H2 target through Nexus.
NexusRegionSelect a supported Nexus execution region.
SeleneExecutionOptionsConfigure local Selene execution.

Classes

HugrCompilationPlan [source]

class HugrCompilationPlan

Describe the callable symbols emitted into one HUGR module.

Parameters:

NameTypeDescription
definitionstuple[CallableRef, ...]Reachable body-backed callable definitions emitted as HUGR functions.

Constructor

def __init__(self, definitions: tuple[CallableRef, ...]) -> None

Attributes


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


HugrExecutionTarget [source]

class HugrExecutionTarget(StrEnum)

Identify a supported HUGR execution destination.

Attributes


HugrExecutor [source]

class HugrExecutor

Execute HUGR packages on local Selene or Nexus devices.

The nexus destination selects HUGR or QIR submission from the device configured in :class:NexusExecutionOptions. The existing helios destination remains an alias for Nexus execution. Nexus authentication starts on the first submission or restoration, and project names are resolved internally when submitting a job.

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())
>>> h2 = HugrExecutor(
...     "nexus", options=NexusExecutionOptions(system_name="H2-1E")
... )

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 Nexus destination. helios is retained as a Nexus alias.
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: Package,
    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
packagePackageHUGR 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:


HugrTarget [source]

class HugrTarget

Plan, lower, package, and validate a Guppy-compatible HUGR target.

Attributes

Methods

compile
def compile(
    self,
    program: PreparedModule,
    plan: HugrCompilationPlan,
) -> CompiledProgram[Any]

Lower a prepared semantic module directly to a HUGR package.

Parameters:

NameTypeDescription
programPreparedModulePrepared hierarchical semantic program.
planHugrCompilationPlanCallable emission plan.

Returns:

CompiledProgram[Any] — CompiledProgram[Any]: HUGR package and target metadata.

Raises:

plan
def plan(self, program: PreparedModule) -> HugrCompilationPlan

Select reachable body-backed callables for HUGR functions.

Parameters:

NameTypeDescription
programPreparedModulePrepared hierarchical semantic program.

Returns:

HugrCompilationPlan — Stable callable-definition order.

Raises:

validate
def validate(self, artifact: Any) -> None

Validate a HUGR package with the native Rust-backed validator.

Parameters:

NameTypeDescription
artifactAnyhugr.package.Package to validate.

Raises:


HugrTranspiler [source]

class HugrTranspiler

Build HUGR executables and Guppy-compatible compiled packages.

Use transpile() for a program with run() and sample() methods, or compile() for a compiled package with its ABI and metadata.

Parameters:

NameTypeDescription
configCompilerConfig | NoneShared semantic preparation configuration. Defaults to :class:CompilerConfig.

Constructor

def __init__(self, config: CompilerConfig | None = None) -> None

Initialize the direct program-graph transpiler.

Parameters:

NameTypeDescription
configCompilerConfig | NoneSemantic preparation configuration. Defaults to :class:CompilerConfig.

Attributes

Methods

compile
def compile(
    self,
    kernel: QKernelLike,
    bindings: dict[str, Any] | None = None,
    parameters: list[str] | None = None,
) -> CompiledProgram[Any]

Compile a qkernel directly to a validated HUGR package.

Return the compilation result without execution methods. Use transpile() to prepare an executable, including runtime array shapes and expectation-value measurement programs.

Parameters:

NameTypeDescription
kernelQKernelLikeTop-level qkernel-like entrypoint.
bindingsdict[str, Any] | NoneCompile-time bindings. Defaults to None.
parameterslist[str] | NoneRuntime parameter names retained as HUGR function inputs. Defaults to None.

Returns:

CompiledProgram[Any] — CompiledProgram[Any]: Validated hugr.package.Package artifact.

Raises:

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

Create an executor for a selected HUGR destination.

Parameters:

NameTypeDescription
targetstr | HugrExecutionTargetSelene or Nexus destination.
optionsSeleneExecutionOptions | NexusExecutionOptions | NoneDestination-specific execution options.

Returns:

HugrExecutor — Destination-independent public executor.

Raises:

to_hugr
def to_hugr(
    self,
    kernel: QKernelLike,
    bindings: dict[str, Any] | None = None,
    parameters: list[str] | None = None,
) -> Any

Return only the validated HUGR package artifact.

Parameters:

NameTypeDescription
kernelQKernelLikeTop-level qkernel-like entrypoint.
bindingsdict[str, Any] | NoneCompile-time bindings. Defaults to None.
parameterslist[str] | NoneRuntime parameter names. Defaults to None.

Returns:

Any — hugr.package.Package artifact.

Raises:

transpile
def transpile(
    self,
    kernel: QKernelLike,
    bindings: dict[str, Any] | None = None,
    parameters: list[str] | None = None,
    *,
    parameter_shapes: dict[str, tuple[int, ...]] | None = None,
) -> HugrExecutable

Transpile a qkernel into an executable for Selene and Nexus devices.

Parameters:

NameTypeDescription
kernelQKernelLikePublic qkernel entrypoint.
bindingsdict[str, Any] | NoneCompile-time structural values. Defaults to None.
parameterslist[str] | NoneNames retained as runtime arguments. Defaults to None.
parameter_shapesdict[str, tuple[int, ...]] | NoneStatic shapes of runtime arrays. Shape values define structure; array contents remain function arguments and are supplied to run or sample. Defaults to None.

Returns:

HugrExecutable — Native packages with run() and sample() methods accepting a HUGR executor and runtime bindings.

Raises:


NexusExecutionOptions [source]

class NexusExecutionOptions

Configure execution on a Helios or H2 target through Nexus.

Parameters:

NameTypeDescription
projectAny | NoneNexus project name or native qnexus project reference. A name is looked up or created when submitting a job. None uses the active Nexus project, or looks up or creates qamomile if no project is active. Authentication is automatic on the first submission or restoration; an initial login may require browser approval.
backend_configAny | NoneNative qnexus.HeliosConfig or H2 qnexus.QuantinuumConfig with optional device settings. Its system_name or device_name overrides system_name below.
system_namestrDevice name, defaulting to Helios-1. Helios receives HUGR; H2 receives automatically converted QIR. H2 requires Python 3.11 or 3.12 with the hugr extra and Bit public outputs. Every H2 shot read uses a zero-based logical index, normalized from the internal device origin before QIR conversion. Helios uses an internal zero-based origin policy and preserves shot reads without rewriting the upload; its device origin remains unverified.
namestrProgram and job name prefix. Each submission receives a unique suffix, including separate expectation measurement jobs.
max_costfloat | NoneOptional maximum HQC cost for each submitted program. Required when submitting to Helios; saved jobs can be restored without it. A deprecated native config limit is used when omitted, and conflicting limits are rejected. This is not an aggregate expectation-estimation budget.
n_qubitsint | NoneOptional maximum qubit count passed to Nexus.
credential_namestr | NoneName of a credential already in Nexus.
user_groupstr | NoneNexus user group for scheduling.
target_regionstr | NexusRegion | NoneExecution region, us or sg.
poll_interval_secondsfloatPositive local status polling interval.
timeout_secondsfloat | NoneDefault local status-wait deadline. None waits indefinitely. Timing out never cancels a job.

Raises:

Constructor

def __init__(
    self,
    project: Any | None = None,
    backend_config: Any | None = None,
    system_name: str = 'Helios-1',
    name: str = 'qamomile-hugr',
    max_cost: float | None = None,
    n_qubits: int | None = None,
    credential_name: str | None = None,
    user_group: str | None = None,
    target_region: str | NexusRegion | None = None,
    poll_interval_seconds: float = 1.0,
    timeout_seconds: float | None = None,
) -> None

Attributes


NexusRegion [source]

class NexusRegion(StrEnum)

Select a supported Nexus execution region.

Attributes


SeleneExecutionOptions [source]

class SeleneExecutionOptions

Configure local Selene execution.

Parameters:

NameTypeDescription
seedint | NoneReproducible simulator seed, or provider default.
n_qubitsint | NoneSimulator capacity override. By default use an allocation bound expanded through the submitted call graph.
timeout_secondsfloat | NoneMaximum simulator execution duration.
build_dirPath | NoneRoot for persistent isolated compilation directories. If omitted, the executor owns a temporary directory that is removed when the executor is released.

Raises:

Constructor

def __init__(
    self,
    seed: int | None = None,
    n_qubits: int | None = None,
    timeout_seconds: float | None = None,
    build_dir: Path | None = None,
) -> None

Attributes

Submodules