Skip to content

Solver Customization

The Classiq combinatorial optimization application has two categories of configuration knobs: QAOA algorithm parameters and classical optimizer parameters.

import networkx as nx

from classiq.applications.combinatorial_optimization import (
from classiq.applications.combinatorial_optimization.examples import mis
from classiq.execution import OptimizerType
from classiq import construct_combinatorial_optimization_model

graph = nx.star_graph(4)
mis_problem = mis(graph)
qaoa_config = QAOAConfig(num_layers=3, penalty_energy=2)

optimizer_config = OptimizerConfig(
    opt_type=OptimizerType.COBYLA, max_iteration=30, alpha_cvar=0.2
mis_model = construct_combinatorial_optimization_model(

In the QAOAConfig input, specify parameters of the QAOA ansatz:

  • num_layers: int – 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.

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

  • opt_type: OptimizerType – Classical optimization algorithms: 'COBYLA', 'SPSA', 'ADAM', 'L_BFGS_B', 'NELDER_MEAD'.
  • max_iteration: Optional[int] – Maximal number of optimizer iterations.
  • tolerance: float – Final accuracy of the optimization.
  • step_size: float – Step size for numerically calculating the gradient in L_BFGS_B and ADAM optimizers.
  • skip_compute_variance: bool – If True, the optimizer does not compute the variance of the ansatz.
  • cost_type: CostType – Summarizing method of the measured bit strings: 'AVERAGE', 'MIN', 'CVAR'.
  • alpha_cvar: float – Parameter describing the quantile considered in the CVAR expectation value [1] .


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