EstimatorSingleLayer#

Module: iqm.qaoa.backends

class iqm.qaoa.backends.EstimatorSingleLayer[source]#

Bases: EstimatorBackend

The estimator class for calculating the expectation value analytically (for \(p=1\) QAOA).

Methods

estimate

Calculates the expectation value of the Hamiltonian for \(p=1\) QAOA.

estimate_correlations_z

The method for estimating the exp.

estimate(qaoa_object)[source]#

Calculates the expectation value of the Hamiltonian for \(p=1\) QAOA.

The function calculates the energy (exp. val. of the Hamiltonian) by adding the expectation values of its individual terms expressed through equation (12) in [2]. The calculation includes a constant term (coming from the translation of a QUBO problem to a Hamiltonian).

Parameters:

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

Returns:

The expectation value of the energy of the QAOA state using angles.

Raises:
  • ValueError – If the provided QUBOQAOA object has more than 1 layer.

  • TypeError – If the variables in the qaoa_object.hamiltonian_bqm are not labelled by integers. Using QUBOQAOA correctly should automatically lead to its attribute hamiltonian_bqm having its variables labelled by integers.

Return type:

float

estimate_correlations_z(qaoa_object, target_qubits)[source]#

The method for estimating the exp. value of products of Z operators on target_qubits.

This works only if the set(s) in target_qubits are of size at most 2. In case of a set of two qubits, it adds an interaction of strength 0 between them, so that they are neighboring in the BQM.

Parameters:
  • qaoa_object (QUBOQAOA) – The QAOA object whose correlations are to be estimated.

  • target_qubits (set[LogQubit] | list[set[LogQubit]]) – The set of qubits on which the operators act, or a list thereof.

Returns:

The estimated expected value of product of Z operators on given target_qubits. Or a list of those, if target_qubits was given as a list.

Raises:
  • ValueError – If the number of layers of the QAOA is not 1.

  • ValueError – If the weight of the operator whose exp. value we are interested in (i.e., the number of qubits it affects) is more than 2.

Return type:

float | list[float]

Inheritance

Inheritance diagram of iqm.qaoa.backends.EstimatorSingleLayer