Amazon Braket engine for Qamomile.
Design intent: this package concretizes the engine-neutral circuit IR as
native Amazon Braket Circuit objects. The transpiler and executor depend
only on Qamomile’s public circuit and observable APIs plus the optional
amazon-braket-sdk dependency; the compiler core never depends on Braket.
Static terminal measurements are retained as Qamomile mapping metadata and performed by the executor. Engine-specific gate control, inversion, global phase, parameter binding, and Pauli-evolution lowering stay at this emit boundary rather than leaking into the shared IR.
Overview¶
| Function | Description |
|---|---|
hamiltonian_to_braket_observable | Convert a Qamomile Hamiltonian to a Braket observable. |
| Class | Description |
|---|---|
BraketExecutionOptions | Configure Braket task and batch submission without flat kwargs. |
BraketExecutor | Submit Braket circuits to a local simulator or injected AWS device. |
BraketTranspiler | Transpile Qamomile quantum kernels to Amazon Braket circuits. |
Functions¶
hamiltonian_to_braket_observable [source]¶
def hamiltonian_to_braket_observable(hamiltonian: qm_o.Hamiltonian) -> 'Observable'Convert a Qamomile Hamiltonian to a Braket observable.
A scalar-only Hamiltonian is represented on qubit zero because Braket observables always address at least one qubit. The executor evaluates such Hamiltonians locally and does not add that synthetic qubit to a task.
Parameters:
| Name | Type | Description |
|---|---|---|
hamiltonian | qm_o.Hamiltonian | Hamiltonian to convert. |
Returns:
'Observable' — Native Braket observable, including all coefficients.
Raises:
ValueError— If a coefficient has a non-negligible imaginary part.
Classes¶
BraketExecutionOptions [source]¶
class BraketExecutionOptionsConfigure Braket task and batch submission without flat kwargs.
Parameters:
| Name | Type | Description |
|---|---|---|
s3_destination_folder | tuple[str, str] | None | S3 bucket and prefix for AWS task results. Defaults to the SDK configuration. |
reservation_arn | str | None | Direct reservation ARN. Defaults to None. |
max_parallel | int | None | Maximum AWS batch concurrency. Defaults to the SDK configuration. |
poll_timeout_seconds | float | None | Provider result polling timeout and default local result-wait limit. Defaults to the SDK configuration with no local limit. |
poll_interval_seconds | float | None | Provider status polling interval. Defaults to the SDK configuration. |
batch_max_retries | int | Maximum explicit Braket batch resubmissions. Defaults to zero to prevent implicit additional QPU cost. |
task_options | Mapping[str, Any] | Additional device.run options. |
batch_options | Mapping[str, Any] | Additional device.run_batch options. |
Raises:
ValueError— If options contain executor-owned argument names or an invalid numeric value.
Constructor¶
def __init__(
self,
s3_destination_folder: tuple[str, str] | None = None,
reservation_arn: str | None = None,
max_parallel: int | None = None,
poll_timeout_seconds: float | None = None,
poll_interval_seconds: float | None = None,
batch_max_retries: int = 0,
task_options: Mapping[str, Any] = dict(),
batch_options: Mapping[str, Any] = dict(),
) -> NoneAttributes¶
batch_max_retries: intbatch_options: Mapping[str, Any]max_parallel: int | Nonepoll_interval_seconds: float | Nonepoll_timeout_seconds: float | Nonereservation_arn: str | Nones3_destination_folder: tuple[str, str] | Nonetask_options: Mapping[str, Any]
Methods¶
batch_kwargs¶
def batch_kwargs(self) -> dict[str, Any]Build keyword arguments for a Braket task batch.
Returns:
dict[str, Any] — dict[str, Any]: Validated device.run_batch keyword arguments.
task_kwargs¶
def task_kwargs(self) -> dict[str, Any]Build keyword arguments for one Braket task.
Returns:
dict[str, Any] — dict[str, Any]: Validated device.run keyword arguments.
BraketExecutor [source]¶
class BraketExecutor(QuantumExecutor['Circuit'])Submit Braket circuits to a local simulator or injected AWS device.
The default device is created lazily, so importing qamomile.braket
remains safe when the optional SDK dependency is absent.
Parameters:
| Name | Type | Description |
|---|---|---|
device | Any | Braket device exposing run and optionally run_batch. Defaults to LocalSimulator. |
estimation_shots | int | Shots used for expectation values. Zero uses exact state-vector expectation on compatible devices. Defaults to zero. |
options | BraketExecutionOptions | None | Structured task and batch submission policy. Defaults to SDK behavior with no batch retry. |
run_kwargs | Mapping[str, Any] | None | Extra keyword arguments passed to every device task. This compatibility argument is deprecated in favor of options. Defaults to none. |
Constructor¶
def __init__(
self,
device: Any = None,
*,
estimation_shots: int = 0,
options: BraketExecutionOptions | None = None,
run_kwargs: Mapping[str, Any] | None = None,
) -> NoneInitialize the Braket executor.
Parameters:
| Name | Type | Description |
|---|---|---|
device | Any | Braket device or compatible test double. Defaults to a lazily created local simulator. |
estimation_shots | int | Non-negative expectation task shots. Defaults to zero for exact local estimation. |
options | BraketExecutionOptions | None | Structured execution options. Defaults to SDK behavior with retry disabled. |
run_kwargs | Mapping[str, Any] | None | Extra task options copied for each run. Kept for compatibility; cannot be combined with options. Defaults to none. |
Raises:
ValueError— Ifestimation_shotsis negative or both option forms are supplied.
Attributes¶
capabilities: ExecutionCapabilities Describe lifecycle and estimation features for the target device.device: Any Return the configured device, creating a local simulator lazily.
Methods¶
bind_parameters¶
def bind_parameters(
self,
circuit: 'Circuit',
bindings: dict[str, Any],
parameter_metadata: ParameterMetadata,
) -> 'Circuit'Bind Qamomile runtime parameters into a Braket circuit.
Parameters:
| Name | Type | Description |
|---|---|---|
circuit | Circuit | Parameterized Braket circuit. |
bindings | dict[str, Any] | Values keyed by flattened Qamomile parameter name. |
parameter_metadata | ParameterMetadata | Compiled parameter ABI. |
Returns:
'Circuit' — New circuit with all required parameters bound.
Raises:
ValueError— If a required binding is absent.
estimate¶
def estimate(
self,
circuit: 'Circuit',
hamiltonian: 'qm_o.Hamiltonian',
params: Sequence[float] | None = None,
) -> floatEstimate a Qamomile Hamiltonian expectation value.
Exact estimation submits one Braket task containing one result type per Pauli term. Shot-based estimation submits one task per term so non-commuting terms remain valid on devices with sampled result types.
Parameters:
| Name | Type | Description |
|---|---|---|
circuit | Circuit | Bound Braket state-preparation circuit. |
hamiltonian | qm_o.Hamiltonian | Hamiltonian to evaluate. |
params | Sequence[float] | None | Positional parameter values for direct executor use. Qamomile normally binds before calling this method. Defaults to none. |
Returns:
float — Real expectation value including the constant term.
Raises:
ValueError— Ifparamsdo not match Braket’s parameter order or if the result has a non-negligible imaginary component.RuntimeError— If a Braket task omits an expectation result.
execute¶
def execute(self, circuit: 'Circuit', shots: int) -> dict[str, int]Sample a Braket circuit and return Qamomile-ordered counts.
Parameters:
| Name | Type | Description |
|---|---|---|
circuit | Circuit | Bound Braket state-preparation circuit. |
shots | int | Number of measurement shots. |
Returns:
dict[str, int] — dict[str, int]: Counts with the highest qubit index on the left.
A zero-qubit circuit returns {"": shots}.
Raises:
RuntimeError— If the Braket result omits measurement counts.
restore¶
def restore(self, reference: ExecutionReference) -> ExecutionHandle[Any]Restore AWS quantum tasks from their serializable references.
Parameters:
| Name | Type | Description |
|---|---|---|
reference | ExecutionReference | Reference returned by a prior Braket execution handle. |
Returns:
ExecutionHandle[Any] — ExecutionHandle[Any]: Restored sampling or expectation handle.
Raises:
ValueError— If the reference provider or decoding context is invalid.TypeError— If the configured device has no AWS session.
submit_estimate¶
def submit_estimate(self, request: EstimateRequest['Circuit']) -> ExecutionHandle[float]Submit Braket expectation tasks without retrieving their results.
Parameters:
| Name | Type | Description |
|---|---|---|
request | EstimateRequest[Circuit] | Circuit, observable, inputs, and accuracy policy. |
Returns:
ExecutionHandle[float] — ExecutionHandle[float]: Lazy exact or shot-based result handle.
Raises:
ValueError— If the Hamiltonian is non-Hermitian, target precision is unsupported, or exact execution targets a QPU.
submit_sample¶
def submit_sample(self, request: SampleRequest['Circuit']) -> ExecutionHandle[dict[str, int]]Submit a native Braket sampling task without waiting for results.
Parameters:
| Name | Type | Description |
|---|---|---|
request | SampleRequest[Circuit] | Circuit, native parameter inputs, and shot count. |
Returns:
ExecutionHandle[dict[str, int]] — ExecutionHandle[dict[str, int]]: Lazy Braket execution handle.
BraketTranspiler [source]¶
class BraketTranspiler(Transpiler['Circuit'])Transpile Qamomile quantum kernels to Amazon Braket circuits.
Methods¶
executor¶
def executor(
self,
device: Any = None,
*,
estimation_shots: int = 0,
options: BraketExecutionOptions | None = None,
run_kwargs: Mapping[str, Any] | None = None,
) -> BraketExecutorCreate a Braket executor.
Parameters:
| Name | Type | Description |
|---|---|---|
device | Any | Braket local simulator, AWS device, or compatible test double. Defaults to a local simulator. |
estimation_shots | int | Shots for expectation tasks. Defaults to zero for exact estimation. |
options | BraketExecutionOptions | None | Structured submission, polling, concurrency, and retry policy. Defaults to SDK behavior with retry disabled. |
run_kwargs | Mapping[str, Any] | None | Extra device task options. Compatibility form; cannot be combined with options. Defaults to none. |
Returns:
BraketExecutor — Configured task-backed executor.
Raises:
ValueError— If executor options are invalid.