Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.36 KB

cpu.rst

File metadata and controls

39 lines (30 loc) · 1.36 KB

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 :stddimod <dimod:index> 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 :stddwave_neal <neal:index> 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']       # doctest: +SKIP
array([-1.5, -0.5])