Skip to content

Solver Customization

The Classiq platform algorithms are distinguishable by their flexibility and customization options. Both algorithms in the quantum algorithms section are determined by several key parameters, which you can modify with the additional qsolver_preferences and optimizer_preferences inputs to the CombinatorialOptimization class declaration, as shown.

{
    "qaoa_preferences":  {
        "qaoa_reps": 3,
        "qsolver": "QAOAMixer",
    },
    "optimizer_preferences" : {
        "name": "COBYLA"
        "num_shots": 1000,
        "max_iteration": 30,
        "alpha_cvar": 0.2
    }
}
import networkx as nx

from classiq.applications.combinatorial_optimization import (
    CombinatorialOptimization,
    QAOAPreferences,
    CombinatorialOptimizer,
    QSolver,
)
from classiq.applications.combinatorial_optimization.examples import mis
from classiq.execution import OptimizerType

graph = nx.star_graph(4)
mis_model = mis(graph)
qaoa_preferences = QAOAPreferences(qsolver=QSolver.QAOAMixer, qaoa_reps=3)
optimizer_preferences = CombinatorialOptimizer(
    name=OptimizerType.COBYLA, num_shots=1000, max_iteration=30, alpha_cvar=0.2
)
solver = CombinatorialOptimization(
    model=mis_model,
    qsolver_preferences=qaoa_preferences,
    optimizer_preferences=optimizer_preferences,
)

In the QAOAPreferences input, specify which quantum solver to implement (QSolver.QAOAPenalty or QSolver.QAOAMixer) and additional parameters of the QAOA ansatz:

  • qaoa_reps: PositiveInt – Number of layers in the QAOA ansatz.
  • penalty_energy: float – Penalty energy for invalid solutions. The value affects the converge rate. Small positive values are preferred.
  • initial_state: List[int] – Custom initial state in the QAOA ansatz. In QAOAPenalty, the default is set to |+> states, and in QAOAMixer it is an arbitrary feasible solution.

The optimizer_preferences input organizes the parameters of the VQE scheme execution. It includes these parameters:

  • name: OptimizerType – Classical optimization algorithms: 'COBYLA', 'SPSA', 'ADAM', 'L_BFGS_B', 'NELDER_MEAD'.
  • num_shots: PositiveInt – Number of measurements of the ansatz for each assignment of variational parameters.
  • cost_type: CostType – Summarizing method of the measured bit strings: 'AVERAGE', 'MIN', 'CVAR'.
  • alpha_cvar: PositiveFloat – Parameter describing the quantile considered in the CVAR expectation value [1] .
  • max_iteration: PositiveInt – Maximal number of optimizer iterations.
  • tolerance: PositiveFloat – Final accuracy of the optimization.
  • step_size: PositiveFloat – Step size for numerically calculating the gradient in L_BFGS_B and ADAM optimizers.
  • initial_point: List[float] – Initial values for the ansatz parameters.
  • skip_compute_variance: bool – If True, the optimizer does not compute the variance of the ansatz. If no value is provided, appropriate values are assigned: a random choice for QSolver.QAOAMixer and a linear schedule for QSolver.QAOAPenalty.

References

[1] P. K. Barkoutsos, et al., Improving Variational Quantum Optimization using CVaR, Quantum 4, 256, (2019).