qrunch.quantum.estimators.estimator_shot_counter

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

Classes

EstimatorShotCounter

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

HasGrouper

Protocol for objects that have a grouper.

class EstimatorShotCounter

Bases: Estimator

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

__init__(estimator: Estimator, grouper: MeasurementGrouper | None = None, error_mitigator: EstimatorErrorMitigator | None = None, measurement_cache: MeasurementCache | None = None) None

Initialize the estimator shot counter.

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

Parameters:
  • estimator (Estimator) – Underlying estimator to use for estimating.

  • grouper (MeasurementGrouper | None) – How to group the terms in the observable when counting the number of shots.

  • error_mitigator (EstimatorErrorMitigator | None) – Error mitigator to be used for encoding the observable or circuit 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

get_sampler() Sampler

Get the underlying sampler used by the estimator.

Return type:

Sampler

has_spin_particle_conservation() bool

Return True, if the estimator is set to use spin particle conservation.

Return type:

bool

has_total_particle_conservation() bool

Return True, if the estimator is set to use total particle conservation.

Return type:

bool

run(observables: Sequence[int | float | complex | Expression[PauliOperators]] | int | float | complex | Expression[PauliOperators] | Sequence[HermitianPauliSum] | HermitianPauliSum, circuits: Sequence[Circuit], shots: int | None) EstimatorResults
run(observables: int | float | complex | Expression[PauliOperators] | HermitianPauliSum, circuits: Circuit, shots: int | None) ExpectationValue
run(observables: Sequence[int | float | complex | Expression[PauliOperators]] | Sequence[HermitianPauliSum], circuits: Circuit, shots: int | None) list[ExpectationValue]

Estimate the value of the observables using the circuit state.

For each observable the following will be calculated: <circuit|observable|circuit>.

Parameters:
  • observables – Observable(s) to be estimated.

  • circuits – States to make estimation from.

  • shots – Number of shots. Must be a positive integer to count number of shots.

property sampler_shots: list[int]

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

supports_shots_equals_none() bool

Return whether the estimator supports shots = None.

The EstimatorShotCounter estimator support shots=None if the underlying estimator supports it.

Return type:

bool

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.

class HasGrouper

Bases: Protocol

Protocol for objects that have a grouper.

__init__(*args, **kwargs)