Backend

Backend selection and transpiling utilities.

Factory module for creating quantum backend samplers.

backend.backend_factory._get_ibm_quantum_sampler()

Get a sampler for IBM Quantum hardware with automatic transpilation.

Requires qiskit-ibm-runtime package and valid IBM Quantum credentials.

Return type:

tuple[BaseSamplerV2, BackendV2]

Returns:

Transpiling sampler wrapping IBM SamplerV2 and the backend object.

Return type:

tuple[BaseSamplerV2, BackendV2]

Raises:

InvalidBackendError – If either IBM runtime package is not installed, credentials are missing or backend is not operational.

backend.backend_factory._get_local_statevector_sampler()

Get a local statevector sampler for ideal simulation.

Return type:

BaseSamplerV2

Returns:

Local statevector sampler instance.

Return type:

BaseSamplerV2

backend.backend_factory.get_sampler()

Get the appropriate sampler based on the configured backend type.

Return type:

tuple[BaseSamplerV2, BackendV2 | None]

Returns:

Configured sampler instance and backend (None for local statevector).

Return type:

tuple[BaseSamplerV2, BackendV2 | None]

Raises:

InvalidBackendError – If the backend type is not supported or configuration is invalid.

Wrapper sampler that handles transpilation for IBM backends.

class backend.transpiling_sampler.TranspilingSampler(sampler, backend)

Bases: BaseSamplerV2

Sampler wrapper that transpiles circuits before execution.

This is required for IBM Quantum backends since March 2024, as they no longer accept non-ISA circuits. The wrapper intercepts circuit submissions, transpiles them to the backend’s instruction set, and passes ISA-compliant circuits to the underlying SamplerV2.

__init__(sampler, backend)

Initialize the transpiling sampler.

Parameters:
  • sampler (BaseSamplerV2) – The underlying sampler (e.g., IBM SamplerV2).

  • backend (Backend) – The backend to transpile circuits for.

_abc_impl = <_abc._abc_data object>
run(pubs, *, shots=None)

Run the sampler with automatic transpilation.

Return type:

BasePrimitiveJob[PrimitiveResult[SamplerPubResult], Any]

Parameters:
  • pubs (Iterable[SamplerPubLike]) – An iterable of pub-like objects containing circuits to execute.

  • shots (int | None) – Number of shots per circuit (optional).

Returns:

Results from the underlying sampler with transpiled circuits.

Return type:

PrimitiveResult[PubResult]

Raises:

TypeError – If an unsupported pub type is encountered.