def test_workflow_runs(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': 1}, {}) sampler = HybridSampler(TabuProblemSampler()) ss = sampler.sample(bqm) self.assertEqual(list(ss.samples()), [{'a': -1}]) self.assertNotIn('state', ss.info)
def test_return_state(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': 1}, {}) sampler = HybridSampler(TabuProblemSampler()) ss = sampler.sample(bqm, return_state=True) self.assertEqual(list(ss.samples()), [{'a': -1}]) self.assertIn('state', ss.info) self.assertEqual(ss.info['state'].problem, bqm)
def test_simple(self): bqm = dimod.BinaryQuadraticModel({}, { 'ab': 1, 'bc': 1, 'ca': -1 }, 0, dimod.SPIN) sampler = HybridSampler(TabuProblemSampler()) response = sampler.sample(bqm) self.assertEqual(response.record[0].energy, -3.0)
def test_sampling_params(self): # a simple runnable that optionally resets the output samples class Workflow(Runnable): def next(self, state, reset=False): if reset: return state.updated(samples=hybrid.SampleSet.empty()) return state bqm = dimod.BinaryQuadraticModel.from_ising({'a': 1}, {}) sampler = HybridSampler(Workflow()) # control run ss = sampler.sample(bqm) self.assertEqual(len(list(ss.samples())), 1) # test runopts propagation ss = sampler.sample(bqm, reset=True) self.assertEqual(len(list(ss.samples())), 0)