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:
By default, QAOA
uses the IBM
backend.
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.solve.parameters.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]
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 | Dict
|
Configuration for the classical optimization routine that updates the variational parameters. Default is a ScipyOptimizer instance with default settings. See ScipyOptimizer class or https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html for details of contained parameters. |
initial_params |
LinearQAOAParams | BasicQAOAParams | RandomQAOAParams | Dict
|
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
¶
Check at runtime if the used backend is compatible with the solver.
Returns:
Type | Description |
---|---|
tuple[type[IBackend], ...]
|
True if the backend is compatible with the solver, False otherwise. |
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. |