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()
orlinear_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
orgammas
.
Attributes
The angles in the QAOA, including
betas
andgammas
in onendarray
.The beta angles in the QAOA, controlling the mixer Hamiltonian terms.
The gamma angles in the QAOA, controlling the problem Hamiltonian terms.
The number of QAOA layers.
The number of qubits, equal to the number of problem variables if no special encoding is used.
The problem instance associated with the QAOA.
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 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.
- 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
anddelta_gamma
values around 0.5, but the best choice for these values depends on the problem Hamiltonian.