Skip to content

Commit

Permalink
Add smoke tests for all reference sampler workflows (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomir authored Sep 20, 2021
1 parent 0ab0723 commit bfcc510
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_reference_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
# limitations under the License.

import unittest
from parameterized import parameterized

import dimod
from dwave.system.testing import MockDWaveSampler

import hybrid
from hybrid.samplers import QPUSubproblemAutoEmbeddingSampler
from hybrid.reference.kerberos import KerberosSampler
from hybrid.reference.pa import (
EnergyWeightedResampler, ProgressBetaAlongSchedule,
Expand Down Expand Up @@ -151,3 +153,27 @@ def test_custom_beta_schedule(self):
ss = pa.run(state).result().samples

self.assertDictEqual(ss.first.sample, ground)


@unittest.mock.patch(
'hybrid.QPUSubproblemAutoEmbeddingSampler',
lambda *a,**kw: QPUSubproblemAutoEmbeddingSampler(qpu_sampler=MockDWaveSampler())
)
class TestReferenceWorkflowsSmoke(unittest.TestCase):

@parameterized.expand([
(hybrid.ParallelTempering, dict(num_sweeps=10, num_replicas=2)),
(hybrid.HybridizedParallelTempering, dict(num_sweeps=10, num_replicas=2)),
(hybrid.PopulationAnnealing, dict(num_reads=10, num_iter=10, num_sweeps=10)),
(hybrid.HybridizedPopulationAnnealing, dict(num_reads=10, num_iter=10, num_sweeps=10)),
(hybrid.Kerberos, dict(sa_sweeps=10, tabu_timeout=10, qpu_sampler=MockDWaveSampler())),
(hybrid.SimplifiedQbsolv, dict(max_iter=2)),
])
def test_smoke(self, sampler_cls, sampler_params):
bqm = dimod.BinaryQuadraticModel.from_ising({}, {'ab': 1})
state = hybrid.State.from_problem(bqm)

w = sampler_cls(**sampler_params)
ss = w.run(state).result().samples

self.assertEqual(ss.first.energy, -1)

0 comments on commit bfcc510

Please sign in to comment.