Solver Customization¶
Classiq platform's algorithms are distinguished by their flexibility and various customization options.
Both algorithms in the quantum algorithms section are determined by several key parameters,
which may be modified using the additional qsolver_preferences
and optimizer_preferences
inputs to the
CombinatorialOptimization
class declaration, as seen in the example below.
{
"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, the user specifies which quantum solver to implement (QSolver.QAOAPenalty
or
QSolver.QAOAMixer
)
and additional parameters of the QAOA ansatz:
- qaoa_reps – (positive int) Number of layers in QAOA ansatz.
- penalty_energy - (float) Penalty energy for invalid solutions. The value affects the converges rate. Small positive values are preferred.
- initial_state - (List[int]) Custom initial state in 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 consists from the following parameters:
- name - (OptimizerType) Classical optimization algorithms: COBYLA, SPSA, ADAM, L-BFGS-B, NELDER MEAD.
- num_shots – (positive int) 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 - (positive float) Parameter describing the quantile considered in the CVAR expectation value [1] .
- max_iteration – (positive int) Maximal number of optimizer iterations.
- tolerance – (positive float) Final accuracy of the optimization.
- step_size - (positive float) Step size for numerically calculating the gradient in L_BFGS_B and ADAM optimizers.
- initial_point - (List of floats) Initial values for the ansatz parameters.
- skip_compute_variance - (bool) If True, the optimizer will not compute the variance of the ansatz. If no value was provided, appropriate values would be 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)