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.

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 Helios.
HugrTargetPlan, lower, package, and validate a Guppy-compatible HUGR target.
HugrTranspilerBuild HUGR executables and Guppy-compatible compiled packages.
NexusExecutionOptionsConfigure HUGR execution on a Helios 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 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:


HugrExecutionTarget [source]

class HugrExecutionTarget(StrEnum)

Identify a supported HUGR execution destination.

Attributes


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:


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

Anyhugr.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 Helios.

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 HUGR execution on a Helios target through Nexus.

Parameters:

NameTypeDescription
projectAny | NoneNative qnexus project reference. None uses the active Nexus project.
backend_configAny | NoneNative qnexus.HeliosConfig with optional emulator or compiler settings. When supplied, its system_name takes precedence over system_name below.
system_namestrHelios device name, defaulting to Helios-1.
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. 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