qilisdk.utils.classical_solvers.simulated_annealing_solver
Classes
Classical solver that uses simulated annealing, implemented in C++. |
Module Contents
- class SimulatedAnnealingSolver(num_reads: int = 10, num_sweeps: int = 1000, beta_range: tuple[float, float] | None = None, seed: int = 0, num_threads: int = 0)[source]
Bases:
qilisdk.utils.classical_solvers.base_solver.ClassicalSolverClassical solver that uses simulated annealing, implemented in C++. This solves a
QUBOmodel and rejects others.Example
from qilisdk.core import Model from qilisdk.utils.classical_solvers import SimulatedAnnealingSolver model = Model.knapsack(values=[5, 4], weights=[3, 2], max_weight=3) result = SimulatedAnnealingSolver(num_reads=100).solve(model.to_qubo())Create a new simulated annealing based classical solver instance.
- Parameters:
num_reads (
int, optional) – The number of independent anneals to run, the best of which is returned. Defaults to 10.num_sweeps (
int, optional) – The number of sweeps over all variables in each anneal. Defaults to 1000.beta_range (
tuple[float,float] | None, optional) – The (initial, final) inverse temperature to anneal over. If not given, a range is derived from the magnitudes of the cost function’s coefficients. Defaults to None.seed (
int, optional) – The seed of the random number generators, each read deriving its own from it. Defaults to 0.num_threads (
int, optional) – The number of threads to distribute the reads over, or zero to let OpenMP decide. Defaults to 0.
- num_reads = 10[source]
- num_sweeps = 1000[source]
- beta_range = None[source]
- seed = 0[source]
- num_threads = 0[source]
- solve(model: qilisdk.core.Model) qilisdk.utils.classical_solvers.base_solver.ClassicalSolverResult[source]
Solve the given QUBO by annealing it in C++.
- Parameters:
model – The
QUBOinstance to solve. Typed asModelto keep theClassicalSolverinterface, but anything other than aQUBOis rejected, so a generalModelmust be converted withto_qubo()first.- Returns:
the results of the optimization, including the objective value and best solution.
- Return type:
- Raises:
ValueError – if the given model is not a QUBO, or if the annealing settings are invalid.