QAOA¶
The Quantum Approximate Optimization Algorithm (QAOA) is a one of the most promising combinatorial optimization algorithms for gate-based quantum computers. The input problem needs to be unconstrained and binary, typically even quadratic in interactions (QUBO). Such a problem can be represented as an Ising cost Hamiltonian, which can directly be implemented on gate-based quantum hardware. Starting with an equal superpositions, the QAOA works through the alternating application of the cost Hamiltonian and the mixer operator, essentially boosting the probability of measuring the sought-after solution at the end of the algorithm.
QAOA is parametrized by \(\beta\) and \(\gamma\) angles that need to be optimized in a
classical optimization loop in order achieve good sampling efficiency. The number of
variational parameters is determined by the number of QAOA layers \(p\) (or reps). A
higher number of layers generally leads to better optimization. However, the increased
parameter count makes optimization harder as a drawback.
Compatible Backends¶
The QAOA algorithm supports the following backends:
Initialization¶
The following section outlines the default configurations of QAOA. You can also specify
other compatible backends for the algorithm. When backend=None is specified, the default backend
will be initialized automatically. In this case, if the backend requires a token, it will be taken
from the environment variables.
from luna_quantum.algorithms import QAOA
from luna_quantum.solve.parameters.algorithms.base_params import (
LinearQAOAParams,
ScipyOptimizerParams
)
algorithm = QAOA(
backend=None,
reps=1,
shots=1024,
optimizer=ScipyOptimizerParams(
method='cobyla',
tol=None,
bounds=None,
jac=None,
hess=None,
maxiter=100,
options={}
),
initial_params=LinearQAOAParams(
delta_beta=0.5,
delta_gamma=0.5
)
)
Parameter Details
For a complete overview of available parameters and their usage, see the QAOA API Reference.
Usage¶
from luna_quantum import LunaSolve
LunaSolve.authenticate("<YOUR_LUNA_API_KEY>")
# Define your model and algorithm
model = ...
algorithm = ...
solve_job = algorithm.run(model, name="my-solve-job")
API Reference¶
Bases: LunaAlgorithm[AWS | IonQ | IQM | Rigetti | IBM | CudaqCpu | CudaqGpu]
Quantum Approximate Optimization Algorithm (QAOA).
QAOA is a hybrid quantum-classical algorithm for solving combinatorial optimization problems. It works by preparing a quantum state through alternating applications of problem-specific (cost) and mixing Hamiltonians, controlled by variational parameters that are optimized classically to maximize the probability of measuring the optimal solution.
QAOA is particularly suited for problems that can be encoded as quadratic unconstrained binary optimization (QUBO) or Ising models, such as MaxCut, TSP, and portfolio optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
reps |
int
|
Number of QAOA layers (p). Each layer consists of applying both the cost and mixing Hamiltonians with different variational parameters. Higher values generally lead to better solutions but increase circuit depth and quantum resources required. Default is 1. |
shots |
int
|
Number of measurement samples to collect per circuit execution. Higher values reduce statistical noise but increase runtime. Default is 1024. |
optimizer |
ScipyOptimizerParams
|
Configuration for the classical optimization routine that updates the variational parameters. Default is a ScipyOptimizer instance with default settings. See ScipyOptimizerParams class for details of contained parameters. |
initial_params |
LinearQAOAParams | BasicQAOAParams | RandomQAOAParams
|
Custom QAOA variational circuit parameters. By default linear
increasing/decreasing parameters for the selected |
backend
class-attribute
instance-attribute
¶
initial_params
class-attribute
instance-attribute
¶
initial_params: RandomQAOAParams | BasicQAOAParams | LinearQAOAParams = Field(
default_factory=lambda: LinearQAOAParams(delta_beta=0.5, delta_gamma=0.5)
)
model_config
class-attribute
instance-attribute
¶
optimizer
class-attribute
instance-attribute
¶
optimizer: ScipyOptimizerParams = Field(
default_factory=lambda: ScipyOptimizerParams()
)
get_compatible_backends
classmethod
¶
get_default_backend
classmethod
¶
Return the default backend implementation.
This property must be implemented by subclasses to provide the default backend instance to use when no specific backend is specified.
Returns:
| Type | Description |
|---|---|
IBackend
|
An instance of a class implementing the IBackend interface that serves as the default backend. |
run ¶
run(
model: Model | str,
name: str | None = None,
backend: BACKEND_TYPE | None = None,
client: LunaSolve | str | None = None,
*args: Any,
**kwargs: Any,
) -> SolveJob
Run the configured solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model or str
|
The model to be optimized or solved. It could be an Model instance or a string identifier representing the model id. |
required |
name
|
str | None
|
If provided, the name of the job. Defaults to None. |
None
|
backend
|
BACKEND_TYPE | None
|
Backend to use for the solver. If not provided, the default backend is used. |
None
|
client
|
LunaSolve or str
|
The client interface used to interact with the backend services. If not provided, a default client will be used. |
None
|
*args
|
Any
|
Additional arguments that will be passed to the solver or client. |
()
|
**kwargs
|
Any
|
Additional keyword parameters for configuration or customization. |
{}
|
Returns:
| Type | Description |
|---|---|
SolveJob
|
The job object containing the information about the solve process. |
Bases: BaseModel
Wrapper for scipy.optimize.minimize.
See SciPy minimize documentation for more information of the available methods and parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
ScipyOptimizerMethod
|
Type of solver. See SciPy minimize documentation for supported methods. |
tol |
float | None
|
Tolerance for termination. |
bounds |
None | list[tuple[float, float]]
|
Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,
trust-constr, COBYLA, and COBYQA methods. |
jac |
None | Literal['2-point', '3-point', 'cs']
|
Method for computing the gradient vector. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr. |
hess |
None | Literal['2-point', '3-point', 'cs']
|
Method for computing the Hessian matrix. Only for Newton-CG, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr. |
maxiter |
int
|
Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. Will be ignored for TNC optimizer. Default: 100 |
options |
dict[str, float]
|
A dictionary of solver options. |
bounds
class-attribute
instance-attribute
¶
bounds: None | list[tuple[float, float]] = Field(
default=None,
description="Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,trust-constr, COBYLA, and COBYQA methods. None is used to specify no bounds. A sequence of `(min, max)` can be used to specify bounds for each parameter individually.",
)
hess
class-attribute
instance-attribute
¶
hess: None | Literal["2-point", "3-point", "cs"] = Field(
default=None,
description="Method for computing the Hessian matrix. Only for Newton-CG, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr.",
)
jac
class-attribute
instance-attribute
¶
jac: None | Literal["2-point", "3-point", "cs"] = Field(
default=None,
description="Method for computing the gradient vector. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr.",
)
maxiter
class-attribute
instance-attribute
¶
maxiter: int = Field(
default=100,
ge=1,
le=10000,
description="Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. Will be ignored for TNC optimizer.",
)
method
class-attribute
instance-attribute
¶
method: ScipyOptimizerMethod = Field(
default="cobyla",
description="Type of solver. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.htmlfor supported methods.",
)
Bases: BaseModel
Linear QAOA Parameters.
Linearly decreasing beta parameters from delta_beta to zero. Linearly growing
paramters from zero to delta_gamma.
Attributes:
| Name | Type | Description |
|---|---|---|
delta_beta |
float
|
Parameter scaling for the beta paramters for the mixer layers in QAOA. |
delta_gamma |
float
|
Parameters scaling for the gamma parameters for the cost layers in QAOA. |