qrunch.quantum.samplers.sampler_shot_counter

Module for implementing Sampler for counting shots of running on quantum hardware.

Classes

SamplerShotCounter

Sampler class for counting number of shots that would have been made through calls to a backend sampler.

class SamplerShotCounter

Bases: Sampler

Sampler class for counting number of shots that would have been made through calls to a backend sampler.

__init__(sampler: Sampler, error_mitigator: SamplerErrorMitigator | None = None, measurement_cache: MeasurementCache | None = None) None

Initialize the sampler shot counter.

Note: The cache if supplied is modified in place with dummy values when running the sampler shot counter.

Parameters:
  • sampler (Sampler) – Underlying sampler to use for sampling.

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

  • measurement_cache (MeasurementCache | None) – Measurement cache for used for counting the number of shots.

Return type:

None

clear_cache() None

Clear the measurement cache.

Return type:

None

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

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

Circuits with shots=None are forwarded directly to the underlying sampler. Circuits with a finite shot count are first run through the backend sampler (for counting), then through the underlying sampler.

Parameters:

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

Return type:

QuantumMeasurement | list[QuantumMeasurement]

property sampler_shots: list[int]

Get the list of shots to the sampler for every evaluated circuit.

total_braket_price(device: _IQM | _IonQ | _Rigetti | _Amazon) float

Return the total price of the calculation, if it had been run on the specified device.

Parameters:

device (_IQM | _IonQ | _Rigetti | _Amazon)

Return type:

float

property total_shots: int

Return the total number of shots, if it had been run on the specified device.

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]