EstimatorFromSampler#

class iqm.qaoa.backends.EstimatorFromSampler(sampler, shots, cvar=None)[source]#

Bases: EstimatorBackend

The estimator class for calculating the expectation value using counts obtained from a sampler.

Takes an instance of a subclass of SamplerBackend and uses it to generate samples from the QAOA. These energy of these samples is then calculated classically and averaged-out to produce an estimate of the expectation value of the Hamiltonian. If cvar is provided, the estimator returns not the average of the energies, but its CVaR at the cvar threshold.

Parameters:
  • sampler (SamplerBackend) – The sampler to produce the samples.

  • shots (int) – The number of shots that should be produced with the sampler.

  • cvar (float | None) – The threshold used to calculate CVaR (if provided).

Raises:

ValueError – If cvar is provided, but it’s not between 0 and 1.

Methods

estimate(qaoa_object)

Calculates the expectation value of the Hamiltonian by sampling from the QAOA circuit.

estimate(qaoa_object)[source]#

Calculates the expectation value of the Hamiltonian by sampling from the QAOA circuit.

Uses the sampler provided at initialization to sample from the QAOA circuit and then calculates the expectation value from the counts.

Parameters:

qaoa_object (QAOA) – The instance of QAOA whose expectation value is to be calculated.

Returns:

The average energy of the sampled docstrings (to serve as estimation of the expectation value).

Return type:

float