Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_instantiation_smoketest(self):
sampler = PolyFixedVariableComposite(ExactPolySolver())
dtest.assert_composite_api(sampler)
def test_energies(self):
bqm = dimod.BinaryQuadraticModel({0: 0.0, 1: 0.0, 2: 0.0},
{(0, 1): -1.0, (1, 2): 1.0, (0, 2): 1.0},
1.0,
dimod.SPIN)
sampler = dimod.RandomSampler()
response = sampler.sample(bqm, num_reads=10)
dtest.assert_response_energies(response, bqm)
def test_empty(self):
bqm0 = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
bqm1 = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
dimod.testing.assert_bqm_almost_equal(bqm0, bqm1)
def test_instantiation(self):
for factory in [dimod.ExactSolver, dimod.RandomSampler, dimod.SimulatedAnnealingSampler]:
sampler = dimod.SpinReversalTransformComposite(factory())
dit.assert_sampler_api(sampler)
dit.assert_composite_api(sampler)
def test_10(self):
sampler = TruncateComposite(ExactSolver(), 10)
dtest.assert_sampler_api(sampler)
dtest.assert_composite_api(sampler)
self.assertEqual(sampler.parameters, {})
def test_construction(self):
sampler = dimod.TrackingComposite(dimod.ExactSolver())
dimod.testing.assert_sampler_api(sampler)
dimod.testing.assert_composite_api(sampler)
self.assertEqual(sampler.inputs, [])
self.assertEqual(sampler.outputs, [])
def test_ignore_zero_interactions(self):
h = {'a': 0, 'b': 0, 'c': 0, 'd': 0}
J0 = {'ab': 0, 'bc': -1}
J1 = {'cb': -1, 'cd': 0}
bqm0 = dimod.BinaryQuadraticModel.from_ising(h, J0)
bqm1 = dimod.BinaryQuadraticModel.from_ising(h, J1)
with self.assertRaises(AssertionError):
dimod.testing.assert_bqm_almost_equal(bqm0, bqm1)
dimod.testing.assert_bqm_almost_equal(bqm0, bqm1, ignore_zero_interactions=True)
with self.assertRaises(AssertionError):
dimod.testing.assert_bqm_almost_equal(bqm1, bqm0)
dimod.testing.assert_bqm_almost_equal(bqm1, bqm0, ignore_zero_interactions=True)