qrmi.primitives package#

Subpackages#

Submodules#

qrmi.primitives.base_estimator module#

Estimator V2 base class for IBM QRMI

class qrmi.primitives.base_estimator.Options(default_precision: float = 0.015625, run_options: dict = <factory>)[source]#

Bases: object

Options for :class:~.QRMIBaseEstimatorV2.

default_precision: float = 0.015625#

The default precision to use if none are specified in :meth:~run. Default: 0.015625 (1 / sqrt(4096)).

run_options: dict#

Options passed to run.

Type:

run_options

class qrmi.primitives.base_estimator.QRMIBaseEstimatorV2(qrmi: QuantumResource, *, options: dict | None = None)[source]#

Bases: BaseEstimatorV2

Estimator V2 base class for IBM QRMI

run(pubs: Iterable[EstimatorPub | tuple[QuantumCircuit, str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | ArrayLike] | tuple[QuantumCircuit, str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | ArrayLike, Mapping[Parameter | str | tuple[Parameter | str, ...], ArrayLike]] | tuple[QuantumCircuit, str | Pauli | SparsePauliOp | SparseObservable | Mapping[str | Pauli, float] | ArrayLike, Mapping[Parameter | str | tuple[Parameter | str, ...], ArrayLike], Real]], *, precision: float | None = None)[source]#

Estimate expectation values for each provided pub (Primitive Unified Bloc).

Parameters:
  • pubs – An iterable of pub-like objects, such as tuples (circuit, observables) or (circuit, observables, parameter_values).

  • precision – The target precision for expectation value estimates of each run Estimator Pub that does not specify its own precision. If None the estimator’s default precision value will be used.

Returns:

A job object that contains results.

qrmi.primitives.base_sampler module#

Sampler V2 base class for IBM QRMI

class qrmi.primitives.base_sampler.Options(default_shots: int = 1024, run_options: dict = <factory>)[source]#

Bases: object

Options for :class:~.QRMIBaseSamplerV2

default_shots: int = 1024#

The default shots to use if none are specified in :meth:~.run. Default: 1024.

run_options: dict#

Options passed to run.

Type:

run_options

class qrmi.primitives.base_sampler.QRMIBaseSamplerV2(qrmi: QuantumResource, *, options: dict | None = None)[source]#

Bases: BaseSamplerV2

Sampler V2 base class for IBM QRMI

run(pubs: Iterable[SamplerPub | QuantumCircuit | tuple[QuantumCircuit] | tuple[QuantumCircuit, Mapping[Parameter | str | tuple[Parameter | str, ...], ArrayLike]] | tuple[QuantumCircuit, Mapping[Parameter | str | tuple[Parameter | str, ...], ArrayLike], Integral | None]], *, shots: int | None = None)[source]#

Run and collect samples from each pub.

Parameters:
  • pubs – An iterable of pub-like objects. For example, a list of circuits or tuples (circuit, parameter_values).

  • shots – The total number of shots to sample for each sampler pub that does not specify its own shots. If None, the primitive’s default shots value will be used, which can vary by implementation.

Returns:

The job object of Sampler’s result.

qrmi.primitives.runtime_job_v2 module#

Runtime job

class qrmi.primitives.runtime_job_v2.RuntimeJobV2(qrmi: QuantumResource, job_id: str, *, delete_job: bool = False)[source]#

Bases: BasePrimitiveJob[PrimitiveResult, TaskStatus]

Representation of a runtime V2 primitive exeuction.

cancel() → None[source]#

Cancel the job.

cancelled() → bool[source]#

Return whether the job has been cancelled.

done() → bool[source]#

Return whether the job has successfully run.

errored() → bool[source]#

Return whether the job has failed.

in_final_state() → bool[source]#

Return whether the job is in a final job state such as DONE or ERROR.

logs() → str[source]#

Return job logs.

result() → PrimitiveResult[source]#

Return the results of the job.

running() → bool[source]#

Return whether the job is actively running.

status() → JobStatus[source]#

Return the status of the job.

Returns:

Status of this job.

qrmi.primitives.service module#

QRMI Service

QRMIService is now implemented in Rust and exposed here via the qrmi._core extension module (re-exported from the top-level qrmi package), rather than being implemented in pure Python in this file.

This module is kept as a thin re-export so that from qrmi.primitives.service import QRMIService – the import path used by earlier releases, when this module contained the actual implementation – keeps working unchanged. New code should prefer importing from the package instead: from qrmi.primitives import QRMIService or from qrmi import QRMIService.

class qrmi.primitives.service.QRMIService#

Bases: object

Python wrapper for QRMIService.

Discovers the QPU resources assigned to the current job – read from the QRMI_JOB_QPU_RESOURCES / QRMI_JOB_QPU_TYPES environment variables, or their legacy SLURM_JOB_QPU_RESOURCES / SLURM_JOB_QPU_TYPES equivalents – and exposes the ones that are currently accessible as QuantumResource instances.

This is a thin wrapper around the plain-Rust [crate::QRMIService], which does the actual discovery/filtering and is usable on its own from Rust (see its docs for a Rust example). This wrapper’s job is only to bridge that to Python: it drives QRMIService::new()’s Future to completion on a private tokio Runtime (mirroring PyResourceProvider and PyQuantumResource elsewhere in this module, since pyo3 classes can’t themselves be async), then moves each resource returned by QRMIService::into_resource_map() into its own, independently owned PyQuantumResource – exactly as PyResourceProvider::resources() does for each Box<dyn QuantumResource> returned by ResourceProvider::resources().

# Example (Python)

from qrmi import QRMIService

service = QRMIService()
for resource in service.resources():
    print(resource.resource_id())

resource = service.resource("ibm_torino")
resource(resource_id)#

Returns a single resource matching the specified resource identifier.

# Arguments

  • resource_id - A resource identifier, i.e. backend name for IBM Quantum.

Returns None if not found.

resources()#

Returns all accessible QRMI resources.

Module contents#

QRMI primitives