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¶
The FlexQAOA algorithm supports the following backends:
AqariosAqariosGpuBy default,FlexQAOAuses theAqariosbackend.
Initialization¶
The following section outlines the default configurations of FlexQAOA. 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.base_params import (
LinearQAOAParams,
ScipyOptimizerParams
)
from luna_quantum.solve.parameters.algorithms.quantum_gate.flex_qaoa import (
CustomConfig,
FlexQAOA,
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,
types=['even', 'odd', 'last']
),
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'
)
)
Parameter Details
For a complete overview of available parameters and their usage, see the FlexQAOA 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[Aqarios | AqariosGpu], BaseModel
The FlexQAOA algorithm for constrained quantum optimization.
The FlexQAOA is an extension to the default QAOA with the capabilities to encode inequality constriants with indicator functions as well as one-hot constraints through XY-mixers. This algorithm will dynamically extract all constraints from the given constraint input optimization model, and construct an accoring QAOA circuit. Currently only simulation of the circuit is supported. But due to the constrained nature, the subspace of the Hilbertspace required for simulation is smaller, depending on the problem instance. This allows for simulation of problems with more qubits than ordinary state vector simulation allows. For now, the simulation size is limited to Hilbertspaces with less <= 2**18 dimensions.
The FlexQAOA allows for a dynamic circuit construction depending on input paramters. Central to this is the pipeline parameter which allows for different configurations.
For instance, if one likes to explore ordinary QUBO simulation with all constraints
represented as quadratic penalties, the xy_mixers and indicator_function options
need to be manually disabled
Following the standard protocol for QAOA, a classical optimizer is required that
tunes the variational parameters of the circuit. Besides the classical
ScipyOptimizer other optimizers are also featured, allowing for optimizing only a
linear schedule, starting with optimizing for a linear schedule followed by
individual parameter fine tuning, and interpolating between different QAOA circuit
depts.
Attributes:
| Name | Type | Description |
|---|---|---|
shots |
int
|
Number of sampled shots. |
reps |
int
|
Number of QAOA layer repetitions |
pipeline |
PipelineParams
|
The pipeline defines the selected features for QAOA circuit generation. By default, all supported features are enabled (one-hot constraints, inequality constraints and quadratic penalties). |
optimizer |
ScipyOptimizerParams | CombinedOptimizerParams | InterpolateOptimizerParams | None
|
The classical optimizer for parameter tuning. Setting
to |
initial_params |
LinearQAOAParams | BasicQAOAParams | RandomQAOAParams | Dict
|
Custom QAOA variational circuit parameters. By default linear
increasing/decreasing parameters for the selected |
param_conversion |
None | Literal["basic"] = "basic"
|
Parameter conversion after initialization. This option set to |
custom_config |
CustomConfig
|
Additional options for the FlexQAOA circuit. |
backend
class-attribute
instance-attribute
¶
custom_config
class-attribute
instance-attribute
¶
custom_config: CustomConfig = Field(
default_factory=lambda: CustomConfig(),
description="Additional configuration options for the FlexQAOA circuit.",
)
initial_params
class-attribute
instance-attribute
¶
initial_params: LinearQAOAParams | BasicQAOAParams | RandomQAOAParams = Field(
default_factory=lambda: LinearQAOAParams(delta_beta=0.5, delta_gamma=0.5),
description="Custom QAOA circuit parameters. By default linear increasing/decreasing parameters for the selected `reps` are generated.",
)
model_config
class-attribute
instance-attribute
¶
optimizer
class-attribute
instance-attribute
¶
optimizer: (
ScipyOptimizerParams
| CombinedOptimizerParams
| InterpolateOptimizerParams
| None
) = Field(
default_factory=lambda: ScipyOptimizerParams(),
description="The classical optimizer. Default: ScipyOptimizer",
)
param_conversion
class-attribute
instance-attribute
¶
param_conversion: None | Literal['basic'] = 'basic'
pipeline
class-attribute
instance-attribute
¶
pipeline: PipelineParams = Field(
default_factory=lambda: PipelineParams(),
description="The pipeline defines the selected features for QAOA circuit generation. By default, all supported features are enabled (one-hot constraints, inequality constraints and quadratic penalties).",
)
reps
class-attribute
instance-attribute
¶
reps: int = Field(
default=1, ge=1, lt=1000, description="Number of QAOA layer repetitions"
)
shots
class-attribute
instance-attribute
¶
shots: int = Field(
default=1024, ge=1, lt=1 << 16, description="Number of sampled shots."
)
get_compatible_backends
classmethod
¶
get_compatible_backends() -> tuple[type[Aqarios], type[AqariosGpu]]
get_default_backend
classmethod
¶
get_default_backend() -> Aqarios
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
Define the modular FlexQAOA Pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
penalty |
PenaltySetting
|
General penalty factor settings. |
inequality_to_equality |
InequalityToEqualityConfig
|
Configuration of the "inequality to equality" transformation. |
setpacking_as_onehot |
SetpackingAsOnehotConfig
|
Configuration of the "setpacking to onehot" transformation. |
xy_mixer |
XYMixerConfig
|
Configuration of the XY-mixers. |
indicator_function |
IndicatorFunctionConfig
|
Configuration of the indicator functions. |
sp_quadratic_penalty |
QuadraticPenaltyConfig
|
Configuration of the setpacking quadratic penalty function. |
quadratic_penalty |
QuadraticPenaltyConfig
|
Configuration of the general quadratic penalty function. |
indicator_function
class-attribute
instance-attribute
¶
indicator_function: IndicatorFunctionConfig = Field(
default_factory=IndicatorFunctionConfig
)
inequality_to_equality
class-attribute
instance-attribute
¶
inequality_to_equality: InequalityToEqualityConfig = Field(
default_factory=InequalityToEqualityConfig
)
penalty
class-attribute
instance-attribute
¶
penalty: PenaltySetting = Field(
default_factory=lambda: PenaltySetting(scaling=2.0)
)
quadratic_penalty
class-attribute
instance-attribute
¶
quadratic_penalty: QuadraticPenaltyConfig = Field(
default_factory=QuadraticPenaltyConfig
)
setpacking_as_onehot
class-attribute
instance-attribute
¶
setpacking_as_onehot: SetpackingAsOnehotConfig = Field(
default_factory=SetpackingAsOnehotConfig
)
sp_quadratic_penalty
class-attribute
instance-attribute
¶
sp_quadratic_penalty: QuadraticPenaltyConfig = Field(
default_factory=QuadraticPenaltyConfig
)
xy_mixer
class-attribute
instance-attribute
¶
xy_mixer: XYMixerConfig = Field(default_factory=XYMixerConfig)
Bases: LunaAlgorithm[Aqarios | AqariosGpu], BaseModel
The FlexQAOA algorithm for constrained quantum optimization.
The FlexQAOA is an extension to the default QAOA with the capabilities to encode inequality constriants with indicator functions as well as one-hot constraints through XY-mixers. This algorithm will dynamically extract all constraints from the given constraint input optimization model, and construct an accoring QAOA circuit. Currently only simulation of the circuit is supported. But due to the constrained nature, the subspace of the Hilbertspace required for simulation is smaller, depending on the problem instance. This allows for simulation of problems with more qubits than ordinary state vector simulation allows. For now, the simulation size is limited to Hilbertspaces with less <= 2**18 dimensions.
The FlexQAOA allows for a dynamic circuit construction depending on input paramters. Central to this is the pipeline parameter which allows for different configurations.
For instance, if one likes to explore ordinary QUBO simulation with all constraints
represented as quadratic penalties, the xy_mixers and indicator_function options
need to be manually disabled
Following the standard protocol for QAOA, a classical optimizer is required that
tunes the variational parameters of the circuit. Besides the classical
ScipyOptimizer other optimizers are also featured, allowing for optimizing only a
linear schedule, starting with optimizing for a linear schedule followed by
individual parameter fine tuning, and interpolating between different QAOA circuit
depts.
Attributes:
| Name | Type | Description |
|---|---|---|
shots |
int
|
Number of sampled shots. |
reps |
int
|
Number of QAOA layer repetitions |
pipeline |
PipelineParams
|
The pipeline defines the selected features for QAOA circuit generation. By default, all supported features are enabled (one-hot constraints, inequality constraints and quadratic penalties). |
optimizer |
ScipyOptimizerParams | CombinedOptimizerParams | InterpolateOptimizerParams | None
|
The classical optimizer for parameter tuning. Setting
to |
initial_params |
LinearQAOAParams | BasicQAOAParams | RandomQAOAParams | Dict
|
Custom QAOA variational circuit parameters. By default linear
increasing/decreasing parameters for the selected |
param_conversion |
None | Literal["basic"] = "basic"
|
Parameter conversion after initialization. This option set to |
custom_config |
CustomConfig
|
Additional options for the FlexQAOA circuit. |
backend
class-attribute
instance-attribute
¶
custom_config
class-attribute
instance-attribute
¶
custom_config: CustomConfig = Field(
default_factory=lambda: CustomConfig(),
description="Additional configuration options for the FlexQAOA circuit.",
)
initial_params
class-attribute
instance-attribute
¶
initial_params: LinearQAOAParams | BasicQAOAParams | RandomQAOAParams = Field(
default_factory=lambda: LinearQAOAParams(delta_beta=0.5, delta_gamma=0.5),
description="Custom QAOA circuit parameters. By default linear increasing/decreasing parameters for the selected `reps` are generated.",
)
model_config
class-attribute
instance-attribute
¶
optimizer
class-attribute
instance-attribute
¶
optimizer: (
ScipyOptimizerParams
| CombinedOptimizerParams
| InterpolateOptimizerParams
| None
) = Field(
default_factory=lambda: ScipyOptimizerParams(),
description="The classical optimizer. Default: ScipyOptimizer",
)
param_conversion
class-attribute
instance-attribute
¶
param_conversion: None | Literal['basic'] = 'basic'
pipeline
class-attribute
instance-attribute
¶
pipeline: PipelineParams = Field(
default_factory=lambda: PipelineParams(),
description="The pipeline defines the selected features for QAOA circuit generation. By default, all supported features are enabled (one-hot constraints, inequality constraints and quadratic penalties).",
)
reps
class-attribute
instance-attribute
¶
reps: int = Field(
default=1, ge=1, lt=1000, description="Number of QAOA layer repetitions"
)
shots
class-attribute
instance-attribute
¶
shots: int = Field(
default=1024, ge=1, lt=1 << 16, description="Number of sampled shots."
)
get_compatible_backends
classmethod
¶
get_compatible_backends() -> tuple[type[Aqarios], type[AqariosGpu]]
get_default_backend
classmethod
¶
get_default_backend() -> Aqarios
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, _EnableMixin
Configuration for XY-mixers to implement one-hot constraints.
Attributes:
| Name | Type | Description |
|---|---|---|
trotter |
int
|
Number of trotter steps for XY-mixer implementation. Default: 1. |
types |
list[Literal['even', 'odd', 'last']]
|
Mixer types in XY-ring-mixer. Default: |
enable |
bool
|
Toggle to enable or disable this method. Default: True. |
Bases: BaseModel, _EnableMixin
Configuration for indicator functions to implement inequality constraints.
Attributes:
| Name | Type | Description |
|---|---|---|
penalty |
PenaltySetting
|
Custom penalty setting for indicator functions. |
method |
Literal['const', 'str']
|
Indicator function implementation method. Default:
|
enable |
bool
|
Toggle to enable or disable this method. Default: True. |
method
class-attribute
instance-attribute
¶
method: Literal["if", "const"] = Field(
default="const",
description="Method of indicator function implementation. Constant Penalty (const) or conditional application of cost function (if).",
)
penalty
class-attribute
instance-attribute
¶
penalty: PenaltySetting = Field(
default_factory=lambda: PenaltySetting(scaling=1),
description="Penalty setting for indicator functions.",
)
Bases: BaseModel, _EnableMixin
Configuration for quadratic penalties.
Adds penalty terms to the objective. Adds slack variables for inequality constraints if neccessaray.
Attributes:
| Name | Type | Description |
|---|---|---|
penalty |
PenaltySetting
|
Custom penalty setting for quadratic penalty terms. |
enable |
bool
|
Toggle to enable or disable this method. Default: True. |
penalty
class-attribute
instance-attribute
¶
penalty: PenaltySetting = Field(
default_factory=lambda: PenaltySetting(scaling=2.0),
description="Penalty setting for quadratic penalties.",
)
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. |
Bases: BaseModel
Additional FlexQAOA circuit configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
max_qubits |
PositiveInt | None
|
Maximum number of qubits allowed for the circuit. If |
minimize_qubits |
bool
|
Minimize the number of used qubits in the circuit if set to |
wstate |
Literal['log', 'bilinear', 'linear']
|
WState generation cricuit. Choice between:
Default: |
qft_synth |
Literal['line', 'full']
|
QFT synthesis method. Choice between:
Default: |
max_qubits
class-attribute
instance-attribute
¶
max_qubits: PositiveInt | None = Field(
default=None,
description="Maximum number of qubits allowed for the circuit. If `None`, no limit is applied.",
)
minimize_qubits
class-attribute
instance-attribute
¶
minimize_qubits: bool = Field(
default=False,
description="Minimize the number of used qubits in the circuit if set to `True`. Otherwise, minimize circuit depth.",
)
qft_synth
class-attribute
instance-attribute
¶
qft_synth: Literal["line", "full"] = Field(
default="full",
description="QFT synthesis method. Shorter depth (full) implementation requires all-to-all connectivity. Longer (line) implementation requires only linear connectivity.",
)
wstate
class-attribute
instance-attribute
¶
wstate: Literal["log", "bilinear", "linear"] = Field(
default="log",
description="WState generation cricuit. Choice between: Logarithmic-depth (log) binary tree circuit and linear or bilinear construction. bilinear places the start in the middle and linearly constructs the circuit outwards.",
)