QAOA#

class iqm.qaoa.generic_qaoa.QAOA(problem, num_layers, *, betas=None, gammas=None, initial_angles=None)[source]#

Bases: ABC

The most generic QAOA abstract base class.

This abstract base class contains methods such as _internal_angle_logic() or linear_ramp_schedule() that can be used by any type / flavor of QAOA.

Parameters:
  • problem (ProblemInstance) – The ProblemInstance to be solved by the QAOA.

  • num_layers (int) – The number of QAOA layers.

  • betas (Sequence[float] | ndarray | None) – An optional list of the initial beta angles of QAOA. Has to be provided together with gammas.

  • gammas (Sequence[float] | ndarray | None) – An optional list of the initial gamma angles of QAOA. Has to be provided together with betas.

  • initial_angles (Sequence[float] | ndarray | None) – An optional list of the initial QAOA angles as one variable. Shouldn’t be provided together with either betas or gammas.

Attributes

angles

The angles in the QAOA, including betas and gammas in one ndarray.

betas

The beta angles in the QAOA, controlling the mixer Hamiltonian terms.

gammas

The gamma angles in the QAOA, controlling the problem Hamiltonian terms.

num_layers

The number of QAOA layers.

num_qubits

The number of qubits, equal to the number of problem variables if no special encoding is used.

problem

The problem instance associated with the QAOA.

trained

A boolean flag indicating whether the QAOA has been trained at all or not.

Methods

_internal_angle_logic([betas, gammas, ...])

Internal method to guarantee that angles are assigned correctly.

linear_ramp_schedule(delta_beta, delta_gamma)

The "linear ramp schedule" for setting the QAOA angles.

train()

The function that performs the training of the angles.

property trained: bool#

A boolean flag indicating whether the QAOA has been trained at all or not.

property num_layers: int#

The number of QAOA layers.

At first this is set to the value given at initialization, but it may be modified later (which has an effect on angles).

property problem: ProblemInstance#

The problem instance associated with the QAOA.

property num_qubits: int#

The number of qubits, equal to the number of problem variables if no special encoding is used.

property betas: ndarray#

The beta angles in the QAOA, controlling the mixer Hamiltonian terms.

property gammas: ndarray#

The gamma angles in the QAOA, controlling the problem Hamiltonian terms.

property angles: ndarray#

The angles in the QAOA, including betas and gammas in one ndarray.

linear_ramp_schedule(delta_beta, delta_gamma)[source]#

The “linear ramp schedule” for setting the QAOA angles.

Formulas adapted from [3]. It can be used either instead of training the QAOA or as a starting set of angles. The above work uses delta_beta and delta_gamma values around 0.5, but the best choice for these values depends on the problem Hamiltonian.

Parameters:
  • delta_beta (float) – The maximum beta angle.

  • delta_gamma (float) – The maximum gamma angle.

Return type:

None

abstract train()[source]#

The function that performs the training of the angles.

Return type:

None