def test_sampling_mode(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': 0}, {}) init = State.from_samples([{'a': -1}, {'a': 1}], bqm) # variable not fixed new = RoofDualityDecomposer(sampling_mode=True).run(init).result() self.assertEqual(new.problem, bqm) self.assertEqual(new.subproblem, bqm) self.assertEqual(new.samples, init.samples) # variable fixed new = RoofDualityDecomposer(sampling_mode=False).run(init).result() self.assertEqual(new.problem, bqm) self.assertEqual(new.subproblem, dimod.BinaryQuadraticModel.from_ising({}, {})) self.assertTrue(len(set(new.samples.record.sample.flatten())), 1)
def test_energy_correctness(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': -1}, {}) init = State.from_sample({'a': -1}, bqm) # should be flipped new = RoofDualityDecomposer().run(init).result() self.assertEqual( new.samples.record.energy, bqm.energies((new.samples.record.sample, new.samples.variables)))
def test_allfixed(self): bqm = dimod.BinaryQuadraticModel.from_ising({'a': -1}, {}) init = State.from_sample({'a': -1}, bqm) # should be flipped new = RoofDualityDecomposer().run(init).result() self.assertEqual(new.problem, bqm) self.assertEqual(new.subproblem, dimod.BinaryQuadraticModel.from_ising({}, {}, -1)) self.assertEqual(new.samples.record.sample, [1])