Using a Classical Solver¶
You might use a classical solver while developing your code or on a small version of your problem to verify your code. To solve a problem classically on your local machine, you configure a classical solver, either one of those included in the Ocean tools or your own.
Examples¶
Among several samplers provided in the dimod
tool for testing your code locally, is the ExactSolver()
that calculates the energy of all
possible samples for a given problem. This example solves a two-variable Ising model
classically on your local machine.
>>> import dimod
>>> solver = dimod.ExactSolver()
>>> response = solver.sample_ising({'a': -0.5, 'b': 1.0}, {('a', 'b'): -1})
>>> response.data_vectors['energy']
array([-1.5, -0.5, -0.5, 2.5])
This example solves the previous problem using the dwave_neal simulated annealing sampler. The two samples requested and generated by this classical solver on your local machine vary by execution.
>>> import neal
>>> solver = neal.SimulatedAnnealingSampler()
>>> response = solver.sample_ising({'a': -0.5, 'b': 1.0}, {('a', 'b'): -1}, num_reads=2)
>>> response.data_vectors['energy']
array([-1.5, -0.5])