Quantum Gate
QAOA
The Quantum Approximate Optimization Algorithm (QAOA) is 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 β and γ 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
| Backend | Default |
|---|---|
| AWS | |
| IonQ | |
| IQM | |
| Rigetti | |
| IBMQuantum | |
| AerSimulator | |
| IBMFakeBackend | |
| CudaqCpu | |
| CudaqGpu |
Initialization
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
)
)
Usage
from luna_quantum.algorithms import QAOA
algorithm = QAOA()
solve_job = algorithm.run(model, name="my-solve-job")
QAOA Fire Opal
QAOA_FO is Q-CTRL's implementation of the Quantum Approximate Optimization Algorithm (QAOA) through their Fire Opal framework. It is a hybrid quantum-classical algorithm for solving combinatorial optimization problems with enhanced performance through Q-CTRL's error mitigation and control techniques.
The algorithm 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_FO leverages Q-CTRL's expertise in quantum control to improve circuit fidelity and optimization performance. It 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.
Compatible Backends
| Backend | Default |
|---|---|
| Qctrl |
Initialization
Usage
from luna_quantum.algorithms import QAOA_FO
algorithm = QAOA_FO()
solve_job = algorithm.run(model, name="my-solve-job")
FlexQAOA
The FlexQAOA is a variant of QAOA developed by Aqarios, specifically focused on problems coming from the real world. The core issue with plain QAOA is that it requires a Quadratic Unconstrained Binary Optimization (QUBO) input format. However, real-world problems typically contain constraints, that can not be violated for a feasible solution. While constraints can be reformulated into penalty terms to form a QUBO. These penalty terms distort the energy spectrum of the optimization heavily, leading to impaired optimization performance. Additionally, in inequality-constrained cases, slack variables have to be introduced, effectively enlarging the search space.
To alleviate the issues arising with reformulation to QUBO, FlexQAOA integrates common constraints directly into the circuit architecture. Namely, it utilizes XY-mixers for the natural enforcement of one-hot constraints and Indicator Functions (IF) for effective penalization of inequality constraints.
Upon input of a constraint optimization problem, FlexQAOA identifies and handles the following constraint types:
- Equality Constraints: via Quadratic Penalties.
- Inequality Constraints:
- via Indicator Functions.
- via Transformation to Equality Constraints.
- One-Hot Constraints:
- via XY-Mixers.
- via Transformation to Equality Constraints.
- Setpacking Constraints:
- via Transformation to One-Hot Constraints.
- via slack-free Quadratic Penalty.
- via Transformation to Inequality Constraints.
The resolution path for each constraint is automatically determined by FlexQAOA. The user can freely configure which methods shall be applied in this automatic pipeline.
So far, FlexQAOA only supports an internal simulator for execution. This simulator, however, features advanced techniques, like cost caching, reduction of state vector size and efficient evaluation of indicator functions.
Note
FlexQAOA will be extended in the future to support more types of constraints and different hardware backends. Stay tuned for updates!
Compatible Backends
| Backend | Default |
|---|---|
| Aqarios | |
| AqariosGpu | |
| AerSimulator | |
| IBMFakeBackend | |
| IBMQuantum |
Initialization
from luna_quantum.algorithms import FlexQAOA
from luna_quantum.solve.parameters.algorithms.base_params import (
LinearQAOAParams,
ScipyOptimizerParams
)
from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa.config import CustomConfig
from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa.pipeline import (
IndicatorFunctionConfig,
InequalityToEqualityConfig,
PenaltySetting,
PipelineParams,
QuadraticPenaltyConfig,
SetpackingAsOnehotConfig,
XYMixerConfig
)
algorithm = FlexQAOA(
backend=None,
shots=1024,
reps=1,
pipeline=PipelineParams(
penalty=PenaltySetting(
override=None,
scaling=2.0
),
inequality_to_equality=InequalityToEqualityConfig(
enable=True,
max_slack=10
),
setpacking_as_onehot=SetpackingAsOnehotConfig(
enable=True
),
xy_mixer=XYMixerConfig(
enable=True,
trotter=1,
method='ring'
),
indicator_function=IndicatorFunctionConfig(
enable=True,
penalty=PenaltySetting(
override=None,
scaling=1.0
),
method='const'
),
sp_quadratic_penalty=QuadraticPenaltyConfig(
enable=True,
penalty=PenaltySetting(
override=None,
scaling=2.0
)
),
quadratic_penalty=QuadraticPenaltyConfig(
enable=True,
penalty=PenaltySetting(
override=None,
scaling=2.0
)
)
),
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
),
param_conversion='basic',
custom_config=CustomConfig(
max_qubits=None,
minimize_qubits=False,
wstate='log',
qft_synth='full'
)
)
Usage
from luna_quantum.algorithms import FlexQAOA
algorithm = FlexQAOA()
solve_job = algorithm.run(model, name="my-solve-job")
Iterative Warm Start
Iterative Warm Start (IWS) is a meta algorithm built on top of FlexQAOA. It keeps the FlexQAOA circuit, including its constraint handling via XY-mixers and indicator functions, but changes how the solution is improved.
Standard QAOA improves the solution by tuning the variational parameters of the circuit with a classical optimizer. IWS instead samples the same circuit several times and feeds the measurement outcomes back into the initial state of the next iteration:
- Sample
flexqaoa.shotsshots from the circuit. - Refine the samples with the configured
postprocessor. - Reweight the measured distribution in a Boltzmann-like fashion, which favors low-energy bitstrings.
- Use the reweighted distribution as the warm-start state of the next iteration.
Over the iterations, the probability mass concentrates on high-quality solutions without making the circuit deeper. Two parameters control the warm-start update:
betascales the inverse temperature of the reweighting. A higher value gives a sharper distribution.epsilonregularizes the probabilities of the warm-start state. After the reweighting, IWS computes a probability for each bit and clamps it to the range[epsilon, 1 - epsilon]. This keeps every bit from becoming fixed to 0 or 1 too early. A higher value gives stronger regularization.
IWS runs num_parallel independent warm-start chains at the same time. Each chain can
start from its own circuit parameters (many_initial_params). The run stops when the
chains have used up the shot budget total_shots.
Because the warm start drives the improvement, the classical optimizer of the inner FlexQAOA is disabled by default. If you configure one, it runs once before the loop to tune the initial parameters. These parameters then stay fixed for all iterations.
Backend Selection
IWS has no backend of its own. It runs on the backend of the inner FlexQAOA, so you
set the backend on flexqaoa. Passing backend to IterativeWarmStart or to
run() raises an error.
from luna_quantum.algorithms import FlexQAOA, IterativeWarmStart
from luna_quantum.solve.parameters.backends import AqariosGpu
algorithm = IterativeWarmStart(
flexqaoa=FlexQAOA(optimizer=None, backend=AqariosGpu()),
total_shots=20000,
)
Tip
For runs on quantum hardware, set flexqaoa.pipeline.xy_mixer.method = "line".
This lowers the qubit connectivity requirements of the circuit.
Compatible Backends
The compatible backends are the ones of FlexQAOA.
| Backend | Default |
|---|---|
| Aqarios | |
| AqariosGpu | |
| AerSimulator | |
| IBMFakeBackend | |
| IBMQuantum |
Initialization
total_shots has no default and must be set. It must be at least flexqaoa.shots.
For the full configuration of the inner flexqaoa, see
FlexQAOA.
from luna_quantum.algorithms import FlexQAOA, IterativeWarmStart
from luna_quantum.solve.parameters.algorithms.base_params import LinearQAOAParams
from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa import (
NoPostprocessor,
)
algorithm = IterativeWarmStart(
flexqaoa=FlexQAOA(optimizer=None),
total_shots=20000,
num_parallel=5,
beta=10.0,
epsilon=0.1,
postprocessor=NoPostprocessor(),
many_initial_params=[
LinearQAOAParams(
delta_beta=0.5,
delta_gamma=0.5
),
LinearQAOAParams(
delta_beta=1.5,
delta_gamma=1.5
)
]
)
Per-Chain Parameters
beta and epsilon accept either one value for all chains, or a list with
exactly one value per chain (num_parallel entries).
many_initial_params sets the initial circuit parameters of the chains. It accepts:
- one entry per chain (
num_parallelentries) ofLinearQAOAParams,BasicQAOAParamsorRandomQAOAParams. - exactly two
LinearQAOAParams. The chains then use parameters that are linearly interpolated between these two. None. All chains then useflexqaoa.initial_params.
Post-Processors
| Post-Processor | Description |
|---|---|
NoPostprocessor |
No post-processing (default). |
SteepestDescentPostprocessor |
Steepest-descent local search on each sample. |
GreedyPostprocessor |
Greedy local search with optional seed and num_sweeps. |
Usage
from luna_quantum.algorithms import IterativeWarmStart
algorithm = IterativeWarmStart(total_shots=20000)
solve_job = algorithm.run(model, name="my-solve-job")
VQE
The Variational Quantum Eigensolver (VQE) is a hybrid quantum-classical algorithm designed to find the ground state energy of a Hamiltonian by variationally optimizing a parameterized quantum circuit. It's widely used in quantum chemistry to compute molecular ground state energies and electronic structure properties. Nevertheless, it can also be used to find the ground state of combinatorial optimization problems, like this implementation is intends to do.
Compatible Backends
| Backend | Default |
|---|---|
| IBMQuantum | |
| IBMFakeBackend | |
| AerSimulator |
Initialization
from luna_quantum.algorithms import VQE
from luna_quantum.solve.parameters.algorithms.base_params import ScipyOptimizerParams
algorithm = VQE(
backend=None,
ansatz='efficient_su2',
ansatz_config={},
shots=1024,
optimizer=ScipyOptimizerParams(
method='cobyla',
tol=None,
bounds=None,
jac=None,
hess=None,
maxiter=100,
options={}
),
initial_params_seed=None,
initial_params_range=(0, 6.283185307179586)
)