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.qiskit

Qiskit engine for Qamomile.

Design intent: this package concretizes circuit’s abstract IR for Qiskit through QiskitMaterializer. QiskitTranspiler plugs the materializer into the shared compiler pipeline, while observable.py converts Hamiltonians to SparsePauliOp.

QiskitExecutor uses a local simulator by default and adapts IBM Runtime V2 primitives for named or preconfigured IBM backends, including account access checks, ISA compilation, and remote job lifecycles.

Constraints: depend only on qamomile.circuit public APIs plus the qiskit SDK — never on qamomile.optimization or other engines. Engine-specific lowering (decompositions, runtime control flow) belongs here at emit time, not in the IR; reuse circuit’s shared decomposition recipes as the fallback for gates without a native Qiskit equivalent.

Overview

FunctionDescription
hamiltonian_to_sparse_pauli_opConvert qamomile.observable.Hamiltonian to Qiskit SparsePauliOp.
ClassDescription
QiskitExecutionOptionsConfigure Runtime primitives without constructing Qiskit option objects.
QiskitExecutorExecute Qiskit circuits locally or on a selected IBM Quantum backend.
QiskitTranspilerQiskit engine transpiler.

Functions

hamiltonian_to_sparse_pauli_op [source]

def hamiltonian_to_sparse_pauli_op(hamiltonian: qm_o.Hamiltonian) -> 'SparsePauliOp'

Convert qamomile.observable.Hamiltonian to Qiskit SparsePauliOp.

Parameters:

NameTypeDescription
hamiltonianqm_o.HamiltonianThe qamomile.observable.Hamiltonian to convert

Returns:

'SparsePauliOp' — Qiskit SparsePauliOp representation

Example:

import qamomile.observable as qm_o
from qamomile.qiskit.observable import hamiltonian_to_sparse_pauli_op

# Build Hamiltonian
H = qm_o.Z(0) * qm_o.Z(1) + 0.5 * (qm_o.X(0) + qm_o.X(1))

# Convert to Qiskit
sparse_pauli_op = hamiltonian_to_sparse_pauli_op(H)

Classes

QiskitExecutionOptions [source]

class QiskitExecutionOptions

Configure Runtime primitives without constructing Qiskit option objects.

Per-request sampling shots and estimation precision remain arguments to the executable. Advanced mappings use Runtime’s option names; the SDK validates their supported fields when the executor is constructed.

Parameters:

NameTypeDescription
max_execution_timeint | NonePositive quantum execution time limit in seconds for both primitives, excluding queue time. Defaults to the SDK setting; does not set the local result-wait timeout.
resilience_levelint | NoneEstimator error mitigation level from zero through two. Defaults to the SDK setting.
sampler_optionsMapping[str, Any]Additional sampler settings. Defaults to an empty mapping. Nested values are copied.
estimator_optionsMapping[str, Any]Additional estimator settings. Defaults to an empty mapping. Nested values are copied.

Raises:

Example:

>>> options = QiskitExecutionOptions(
...     max_execution_time=300,
...     resilience_level=1,
...     sampler_options={"dynamical_decoupling": {"enable": True}},
... )

Constructor

def __init__(
    self,
    max_execution_time: int | None = None,
    resilience_level: int | None = None,
    sampler_options: Mapping[str, Any] = dict(),
    estimator_options: Mapping[str, Any] = dict(),
) -> None

Attributes

Methods

estimator_kwargs
def estimator_kwargs(self) -> dict[str, Any]

Build an independent Runtime estimator options dictionary.

Returns:

dict[str, Any] — dict[str, Any]: Estimator settings with execution and mitigation settings when supplied.

sampler_kwargs
def sampler_kwargs(self) -> dict[str, Any]

Build an independent Runtime sampler options dictionary.

Returns:

dict[str, Any] — dict[str, Any]: Sampler settings with the shared execution limit.


QiskitExecutor [source]

class QiskitExecutor(QuantumExecutor['QuantumCircuit'])

Execute Qiskit circuits locally or on a selected IBM Quantum backend.

With no backend, use AerSimulator or BasicSimulator. Named backends are resolved through QiskitRuntimeService using the supplied credentials or the SDK’s saved account. IBMBackend objects select Runtime automatically. Credentials are passed to the SDK without saving an account to disk.

Parameters:

NameTypeDescription
backendAnyQiskit backend object, IBM backend name, or None for the default local simulator.
estimatorAnyOptional local expectation estimator. Defaults to None for StatevectorEstimator; unavailable with Runtime.
api_keystr | NoneIBM API key for a named backend. Must be supplied with instance_crn. Defaults to the SDK’s saved account.
instance_crnstr | NoneIBM instance CRN paired with api_key. Defaults to the SDK’s configured instance.
modeAnyCaller-owned Runtime Session or Batch paired with a backend object. A backend object can also select Runtime local testing mode. Defaults to None; unavailable with a backend name.
optionsQiskitExecutionOptions | NoneQamomile-owned Runtime settings. Defaults to None; cannot be combined with sampler_options or estimator_options.
sampler_optionsAnyRuntime sampler options. Defaults to None.
estimator_optionsAnyRuntime estimator options. Defaults to None.
pass_managerAnyRuntime target pass manager. Defaults to None.
serviceAnyExisting Runtime service for named backend lookup or job restoration. Cannot be combined with explicit credentials.

Raises:

Example:

executor = QiskitExecutor()  # Uses AerSimulator when available
counts = executor.execute(circuit, shots=1000)
executor = QiskitExecutor(
    backend="your_backend_name",
    api_key=api_key,
    instance_crn=instance_crn,
)
job = executable.sample(executor, shots=1024)

Constructor

def __init__(
    self,
    backend: Any = None,
    estimator: Any = None,
    *,
    api_key: str | None = None,
    instance_crn: str | None = None,
    mode: Any = None,
    options: QiskitExecutionOptions | None = None,
    sampler_options: Any = None,
    estimator_options: Any = None,
    pass_manager: Any = None,
    service: Any = None,
) -> None

Select local execution or authenticate a named IBM backend.

Parameters:

NameTypeDescription
backendAnyQiskit backend object or IBM device name. Defaults to a local simulator when None.
estimatorAnyLocal expectation estimator, or None for defaults.
api_keystr | NoneIBM API key, paired with instance_crn for a named backend. Defaults to None for the saved account.
instance_crnstr | NoneIBM instance CRN paired with api_key. Defaults to None for the SDK’s configured instance.
modeAnyRuntime Session, Batch, or local testing backend paired with a backend object. Defaults to None; not used with a name.
optionsQiskitExecutionOptions | NoneQamomile-owned Runtime settings. Defaults to None; cannot be combined with direct sampler or estimator options.
sampler_optionsAnyRuntime sampler options, or None.
estimator_optionsAnyRuntime estimator options, or None.
pass_managerAnyRuntime hardware compilation pass manager, or None for the preset at optimization level one.
serviceAnyExisting Runtime service for lookup or restoration, or None. Cannot be combined with explicit credentials.

Raises:

Attributes

Methods

bind_parameters
def bind_parameters(
    self,
    circuit: 'QuantumCircuit',
    bindings: dict[str, Any],
    parameter_metadata: ParameterMetadata,
) -> 'QuantumCircuit'

Bind parameter values to the Qiskit circuit.

Parameters:

NameTypeDescription
circuitQuantumCircuitParameterized circuit.
bindingsdict[str, Any]Flattened runtime parameter values.
parameter_metadataParameterMetadataBackend parameter mapping.

Returns:

'QuantumCircuit' — New circuit with parameters bound.

Raises:

estimate
def estimate(
    self,
    circuit: 'QuantumCircuit',
    hamiltonian: 'qm_o.Hamiltonian',
    params: Sequence[float] | None = None,
) -> float

Estimate the expectation value of a Hamiltonian.

Parameters:

NameTypeDescription
circuitQuantumCircuitState preparation ansatz.
hamiltonianqm_o.HamiltonianObservable to measure.
paramsSequence[float] | NoneOptional values in Qiskit parameter order. Defaults to None for an already bound circuit.

Returns:

float — Estimated expectation value.

Raises:

execute
def execute(self, circuit: 'QuantumCircuit', shots: int) -> dict[str, int]

Execute circuit and return bitstring counts.

Parameters:

NameTypeDescription
circuitQuantumCircuitQiskit circuit to execute.
shotsintNumber of measurement shots.

Returns:

dict[str, int] — dict[str, int]: Native dictionary mapping bitstrings to counts, without SDK-specific result metadata. A circuit without quantum or classical bits returns {"": shots}.

Raises:

restore
def restore(self, reference: ExecutionReference) -> ExecutionHandle[Any]

Reconnect to an IBM job using the selected backend’s service.

Parameters:

NameTypeDescription
referenceExecutionReferencePreviously saved execution reference.

Returns:

ExecutionHandle[Any] — ExecutionHandle[Any]: Restored IBM sample or expectation handle.

Raises:

submit_estimate
def submit_estimate(self, request: EstimateRequest[QuantumCircuit]) -> ExecutionHandle[float]

Submit an expectation through the selected execution adapter.

Parameters:

NameTypeDescription
requestEstimateRequest[QuantumCircuit]Circuit, observable, and optional accuracy policy.

Returns:

ExecutionHandle[float] — ExecutionHandle[float]: Immediate local result or lazy IBM job.

Raises:

submit_sample
def submit_sample(
    self,
    request: SampleRequest[QuantumCircuit],
) -> ExecutionHandle[dict[str, int]]

Submit samples through the selected execution adapter.

Parameters:

NameTypeDescription
requestSampleRequest[QuantumCircuit]Circuit, bindings, and shots.

Returns:

ExecutionHandle[dict[str, int]] — ExecutionHandle[dict[str, int]]: Immediate local result or lazy IBM job handle.

Raises:


QiskitTranspiler [source]

class QiskitTranspiler(Transpiler['QuantumCircuit'])

Qiskit engine transpiler.

Converts Qamomile QKernels into Qiskit QuantumCircuits.

Parameters:

NameTypeDescription
use_native_compositeboolWhether to prefer native Qiskit library realizations for semantic composites such as QFT/IQFT. Defaults to True.
use_native_pauli_evolutionboolWhether to prefer PauliEvolutionGate over gate gadgets. Defaults to True.

Example:

from qamomile.qiskit import QiskitTranspiler
import qamomile as qm

@qm.qkernel
def bell_state(q0: qm.Qubit, q1: qm.Qubit) -> tuple[qm.Bit, qm.Bit]:
    q0 = qm.h(q0)
    q0, q1 = qm.cx(q0, q1)
    return qm.measure(q0), qm.measure(q1)

transpiler = QiskitTranspiler()
circuit = transpiler.to_circuit(bell_state)
print(circuit.draw())

Constructor

def __init__(
    self,
    use_native_composite: bool = True,
    use_native_pauli_evolution: bool = True,
) -> None

Initialize the Qiskit transpiler.

Parameters:

NameTypeDescription
use_native_compositeboolWhether to prefer engine-native realizations of semantic composites such as QFT, state preparation, arithmetic, and multi-controlled X. Defaults to True.
use_native_pauli_evolutionboolWhether to prefer native Pauli evolution over gate gadgets. Defaults to True.

Methods

executor
def executor(
    self,
    backend: Any = None,
    *,
    estimator: Any = None,
    api_key: str | None = None,
    instance_crn: str | None = None,
    mode: Any = None,
    options: QiskitExecutionOptions | None = None,
    sampler_options: Any = None,
    estimator_options: Any = None,
    pass_manager: Any = None,
    service: Any = None,
) -> QiskitExecutor

Create a local or IBM Quantum executor with the same execution API.

Parameters:

NameTypeDescription
backendAnyQiskit backend object or IBM backend name. Defaults to a local simulator when None.
estimatorAnyOptional local expectation estimator.
api_keystr | NoneIBM API key for a named backend. Must be paired with instance_crn; defaults to saved credentials.
instance_crnstr | NoneInstance CRN paired with api_key. Defaults to the SDK’s configured instance.
modeAnyCaller-owned Runtime Session, Batch, or local testing backend paired with a backend object. Defaults to None; unavailable with a backend name.
optionsQiskitExecutionOptions | NoneQamomile-owned Runtime settings. Defaults to None; cannot be combined with direct sampler or estimator options.
sampler_optionsAnyRuntime sampler options, or None.
estimator_optionsAnyRuntime estimator options, or None.
pass_managerAnyRuntime hardware compilation pass manager, or None for the backend preset.
serviceAnyExisting Runtime service for lookup or restoration, or None. Cannot be combined with explicit credentials.

Returns:

QiskitExecutor — Executor configured for the selected execution target.

Raises:

Example:

executor = transpiler.executor(
    backend="your_backend_name",
    api_key=api_key,
    instance_crn=instance_crn,
)
job = executable.sample(executor, shots=1024)

Submodules