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¶
| Class | Description |
|---|---|
HugrCompilationPlan | Describe the callable symbols emitted into one HUGR module. |
HugrExecutable | Execute a HUGR artifact through a destination-independent typed API. |
HugrExecutionTarget | Identify a supported HUGR execution destination. |
HugrExecutor | Execute HUGR packages on local Selene or Nexus Helios. |
HugrTarget | Plan, lower, package, and validate a Guppy-compatible HUGR target. |
HugrTranspiler | Build HUGR executables and Guppy-compatible compiled packages. |
NexusExecutionOptions | Configure HUGR execution on a Helios target through Nexus. |
NexusRegion | Select a supported Nexus execution region. |
SeleneExecutionOptions | Configure local Selene execution. |
Classes¶
HugrCompilationPlan [source]¶
class HugrCompilationPlanDescribe the callable symbols emitted into one HUGR module.
Parameters:
| Name | Type | Description |
|---|---|---|
definitions | tuple[CallableRef, ...] | Reachable body-backed callable definitions emitted as HUGR functions. |
Constructor¶
def __init__(self, definitions: tuple[CallableRef, ...]) -> NoneAttributes¶
definitions: tuple[CallableRef, ...]
HugrExecutable [source]¶
class HugrExecutableExecute 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:
| Name | Type | Description |
|---|---|---|
compiled | CompiledProgram[Any] | HUGR artifact and public ABI. |
Constructor¶
def __init__(self, compiled: CompiledProgram[Any]) -> NoneOwn a compiled artifact and its public ABI.
Parameters:
| Name | Type | Description |
|---|---|---|
compiled | CompiledProgram[Any] | Package, ABI and provenance. |
Attributes¶
abi: ProgramABI Return a defensive copy of the public input and output contract.artifact: Any Return the native package retained by the executable.has_parameters: bool Report whether execution requires runtime arguments.metadata: CompilationMetadata Return target compilation provenance.parameter_names: list[str] Return runtime argument names in native input-port order.
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:
| Name | Type | Description |
|---|---|---|
executor | HugrExecutor | Destination used to retrieve remote leaves. |
snapshot | JobSnapshot | Saved operation and ordered execution tree. |
bindings | Mapping[str, Any] | None | Original runtime parameter values. |
Returns:
Job[Any] — Job[Any]: Restored sample, single-run, or expectation job.
Raises:
ValueError— If the execution layout, identity, or operation is invalid.Exception— If runtime validation or provider retrieval fails.
run¶
def run(
self,
executor: HugrExecutor,
bindings: Mapping[str, Any] | None = None,
*,
shots: int | None = None,
estimation: EstimationAccuracy | None = None,
) -> RunJob[Any] | ExpvalJobExecute 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:
| Name | Type | Description |
|---|---|---|
executor | HugrExecutor | Selene or Helios destination. |
bindings | Mapping[str, Any] | None | Whole or indexed runtime parameter values. |
shots | int | None | Legacy positive shots per expectation term. Mutually exclusive with estimation; both omitted uses 1024. |
estimation | EstimationAccuracy | None | Shared 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:
ValueError— If runtime values or shots are invalid.TypeError— If an expectation accuracy policy is unrecognized.NotImplementedError— If exact or target-precision estimation is requested.Exception— If target compilation or provider submission fails.
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:
| Name | Type | Description |
|---|---|---|
executor | HugrExecutor | Selene or Helios destination. |
shots | int | Positive number of repetitions, default 1024. |
bindings | Mapping[str, Any] | None | Runtime values, keyed by whole argument names or shared indexed parameter names. |
Returns:
Job[SampleResult[Any]] — Job[SampleResult[Any]]: Deferred structured sample counts.
Raises:
ValueError— If shots, bindings, or operation are invalid.Exception— If compilation or provider submission fails.
HugrExecutionTarget [source]¶
class HugrExecutionTarget(StrEnum)Identify a supported HUGR execution destination.
Attributes¶
HELIOSSELENE
HugrExecutor [source]¶
class HugrExecutorExecute HUGR packages on local Selene or Nexus Helios.
Parameters:
| Name | Type | Description |
|---|---|---|
target | str | HugrExecutionTarget | Destination, default selene. |
options | SeleneExecutionOptions | NexusExecutionOptions | None | Destination-specific settings. Defaults to the destination defaults. |
Raises:
ValueError— If the destination is unknown.TypeError— If options belong to another destination.
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,
) -> NoneInitialize the destination and local compilation cache.
Parameters:
| Name | Type | Description |
|---|---|---|
target | str | HugrExecutionTarget | Selene or Helios destination. |
options | SeleneExecutionOptions | NexusExecutionOptions | None | Destination-specific configuration. |
Raises:
ValueError— If the destination is unknown.TypeError— If options are incompatible with the destination.
Attributes¶
capabilities: ExecutionCapabilities Describe this destination’s actual execution features.optionstarget
Methods¶
retrieve¶
def retrieve(self, reference: ExecutionReference) -> ExecutionHandle[list[dict[str, Any]]]Restore a remote tagged execution without resubmitting it.
Parameters:
| Name | Type | Description |
|---|---|---|
reference | ExecutionReference | Saved Nexus job reference. |
Returns:
ExecutionHandle[list[dict[str, Any]]] — ExecutionHandle[list[dict[str, Any]]]: Restored remote handle.
Raises:
ValueError— If the destination is local or reference is invalid.Exception— If the provider cannot retrieve the referenced job.
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:
| Name | Type | Description |
|---|---|---|
package | Any | HUGR package with a zero-argument main function. |
shots | int | Number of repetitions, default 1024. |
Returns:
ExecutionHandle[list[dict[str, Any]]] — ExecutionHandle[list[dict[str, Any]]]: Tagged values for each shot.
Raises:
ValueError— If shots is invalid or output tags repeat.ImportError— If destination dependencies are missing.RuntimeError— If the simulator returns an incorrect shot count.Exception— If provider compilation or submission fails.
HugrTarget [source]¶
class HugrTargetPlan, lower, package, and validate a Guppy-compatible HUGR target.
Attributes¶
name: str Return the stable compilation target name.
Methods¶
compile¶
def compile(
self,
program: PreparedModule,
plan: HugrCompilationPlan,
) -> CompiledProgram[Any]Lower a prepared semantic module directly to a HUGR package.
Parameters:
| Name | Type | Description |
|---|---|---|
program | PreparedModule | Prepared hierarchical semantic program. |
plan | HugrCompilationPlan | Callable emission plan. |
Returns:
CompiledProgram[Any] — CompiledProgram[Any]: HUGR package and target metadata.
Raises:
ImportError— If HUGR or TKET extension packages are unavailable.EmitError— If a semantic operation has no HUGR lowering yet.
plan¶
def plan(self, program: PreparedModule) -> HugrCompilationPlanSelect reachable body-backed callables for HUGR functions.
Parameters:
| Name | Type | Description |
|---|---|---|
program | PreparedModule | Prepared hierarchical semantic program. |
Returns:
HugrCompilationPlan — Stable callable-definition order.
Raises:
CallableDefinitionConflictError— If one source callable produced multiple specialized bodies that cannot share one HUGR symbol.
validate¶
def validate(self, artifact: Any) -> NoneValidate a HUGR package with the native Rust-backed validator.
Parameters:
| Name | Type | Description |
|---|---|---|
artifact | Any | hugr.package.Package to validate. |
Raises:
ImportError— If the HUGR package is unavailable.HugrCliError— If HUGR validation rejects the package.
HugrTranspiler [source]¶
class HugrTranspilerBuild 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:
| Name | Type | Description |
|---|---|---|
config | CompilerConfig | None | Shared semantic preparation configuration. Defaults to :class:CompilerConfig. |
Constructor¶
def __init__(self, config: CompilerConfig | None = None) -> NoneInitialize the direct program-graph transpiler.
Parameters:
| Name | Type | Description |
|---|---|---|
config | CompilerConfig | None | Semantic preparation configuration. Defaults to :class:CompilerConfig. |
Attributes¶
compilertarget
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:
| Name | Type | Description |
|---|---|---|
kernel | QKernelLike | Top-level qkernel-like entrypoint. |
bindings | dict[str, Any] | None | Compile-time bindings. Defaults to None. |
parameters | list[str] | None | Runtime parameter names retained as HUGR function inputs. Defaults to None. |
Returns:
CompiledProgram[Any] — CompiledProgram[Any]: Validated hugr.package.Package artifact.
Raises:
ImportError— If HUGR dependencies are unavailable.ValueError— If compile-time bindings overlap runtime parameters.QamomileCompileError— If semantic preparation or HUGR lowering rejects the program.HugrCliError— If target-native validation rejects the package.
executor¶
def executor(
self,
target: str | HugrExecutionTarget = HugrExecutionTarget.SELENE,
*,
options: SeleneExecutionOptions | NexusExecutionOptions | None = None,
) -> HugrExecutorCreate an executor for a selected HUGR destination.
Parameters:
| Name | Type | Description |
|---|---|---|
target | str | HugrExecutionTarget | Selene or Helios destination. |
options | SeleneExecutionOptions | NexusExecutionOptions | None | Destination-specific execution options. |
Returns:
HugrExecutor — Destination-independent public executor.
Raises:
ValueError— If target is unknown.TypeError— If options do not match the destination.
to_hugr¶
def to_hugr(
self,
kernel: QKernelLike,
bindings: dict[str, Any] | None = None,
parameters: list[str] | None = None,
) -> AnyReturn only the validated HUGR package artifact.
Parameters:
| Name | Type | Description |
|---|---|---|
kernel | QKernelLike | Top-level qkernel-like entrypoint. |
bindings | dict[str, Any] | None | Compile-time bindings. Defaults to None. |
parameters | list[str] | None | Runtime parameter names. Defaults to None. |
Returns:
Any — hugr.package.Package artifact.
Raises:
ImportError— If HUGR dependencies are unavailable.ValueError— If compile-time bindings overlap runtime parameters.QamomileCompileError— If semantic preparation or HUGR lowering rejects the program.HugrCliError— If target-native validation rejects the package.
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,
) -> HugrExecutableTranspile a qkernel into an executable for Selene and Nexus Helios.
Parameters:
| Name | Type | Description |
|---|---|---|
kernel | QKernelLike | Public qkernel entrypoint. |
bindings | dict[str, Any] | None | Compile-time structural values. Defaults to None. |
parameters | list[str] | None | Names retained as runtime arguments. Defaults to None. |
parameter_shapes | dict[str, tuple[int, ...]] | None | Static 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:
ValueError— If compile-time bindings overlap runtime parameters.QamomileCompileError— If semantics or target capabilities are invalid.Exception— If native HUGR validation fails.
NexusExecutionOptions [source]¶
class NexusExecutionOptionsConfigure HUGR execution on a Helios target through Nexus.
Parameters:
| Name | Type | Description |
|---|---|---|
project | Any | None | Native qnexus project reference. None uses the active Nexus project. |
backend_config | Any | None | Native qnexus.HeliosConfig with optional emulator or compiler settings. When supplied, its system_name takes precedence over system_name below. |
system_name | str | Helios device name, defaulting to Helios-1. |
name | str | Program and job name prefix. Each submission receives a unique suffix, including separate expectation measurement jobs. |
max_cost | float | None | Optional maximum HQC cost for each submitted program. This is not an aggregate expectation-estimation budget. |
n_qubits | int | None | Optional maximum qubit count passed to Nexus. |
credential_name | str | None | Name of a credential already in Nexus. |
user_group | str | None | Nexus user group for scheduling. |
target_region | str | NexusRegion | None | Execution region, us or sg. |
poll_interval_seconds | float | Positive local status polling interval. |
timeout_seconds | float | None | Default local status-wait deadline. None waits indefinitely. Timing out never cancels a job. |
Raises:
ValueError— If a numeric option, name, region, or config is invalid.
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,
) -> NoneAttributes¶
backend_config: Any | Nonecredential_name: str | Nonemax_cost: float | Nonen_qubits: int | Nonename: strpoll_interval_seconds: floatproject: Any | Nonesystem_name: strtarget_region: str | NexusRegion | Nonetimeout_seconds: float | Noneuser_group: str | None
NexusRegion [source]¶
class NexusRegion(StrEnum)Select a supported Nexus execution region.
Attributes¶
SGUS
SeleneExecutionOptions [source]¶
class SeleneExecutionOptionsConfigure local Selene execution.
Parameters:
| Name | Type | Description |
|---|---|---|
seed | int | None | Reproducible simulator seed, or provider default. |
n_qubits | int | None | Simulator capacity override. By default use an allocation bound expanded through the submitted call graph. |
timeout_seconds | float | None | Maximum simulator execution duration. |
build_dir | Path | None | Root for persistent isolated compilation directories. If omitted, the executor owns a temporary directory that is removed when the executor is released. |
Raises:
ValueError— If a numeric option is invalid.TypeError— If the seed or capacity is not an integer.
Constructor¶
def __init__(
self,
seed: int | None = None,
n_qubits: int | None = None,
timeout_seconds: float | None = None,
build_dir: Path | None = None,
) -> NoneAttributes¶
build_dir: Path | Nonen_qubits: int | Noneseed: int | Nonetimeout_seconds: float | None