qrunch.quantum.samplers.backend_sampler

Module for backend sampler.

Classes

BackendSampler

Sampler class for sampling from a quantum circuit.

class BackendSampler

Bases: Sampler

Sampler class for sampling from a quantum circuit.

__init__(backend: Backend, error_mitigator: SamplerErrorMitigator | None = None, measurement_cache: MeasurementCache | None = None) → None

Initiate an instance of sampler.

Parameters:
  • backend (Backend) – Backend for handling the sampling.

  • error_mitigator (SamplerErrorMitigator | None) – Error mitigator to be used for encoding the measurement more error resistantly.

  • measurement_cache (MeasurementCache | None) – Cache to use for storing and reusing measurements.

  • verify_hardware_backend_works – Whether to verify that the hardware backend works. This is done by running a simple circuit on the backend and checking the result.

Return type:

None

clear_cache() → None

Clear the measurement cache.

Return type:

None

run(circuits: MeasurementCircuit | Sequence[MeasurementCircuit]) → QuantumMeasurement | list[QuantumMeasurement]

Start job for sampling on the given circuits a given number of times.

Parameters:

circuits (MeasurementCircuit | Sequence[MeasurementCircuit]) – Measurement circuit or sequence of circuits to be sampled.

Return type:

QuantumMeasurement | list[QuantumMeasurement]

validate_shots_type(shots_type: type[int | None]) → list[str]

Validate that the sampler supports the given shots type. Return a list of error messages if not supported.

Parameters:

shots_type (type[int | None])

Return type:

list[str]

verify_backend_works() → None

Verify that the backend works by running a simple circuit.

The circuit is run on the actual hardware, so this requires a valid token and may take some time and cost a small number of credits.

Return type:

None