How to use the dimod.testing function in dimod

To help you get started, we’ve selected a few dimod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dwavesystems / dimod / tests / test_fixedpolyvariablecomposite.py View on Github external
def test_instantiation_smoketest(self):
        sampler = PolyFixedVariableComposite(ExactPolySolver())

        dtest.assert_composite_api(sampler)
github dwavesystems / dimod / tests / test_random_sampler.py View on Github external
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)
github dwavesystems / dimod / tests / test_testing.py View on Github external
def test_empty(self):
        bqm0 = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
        bqm1 = dimod.BinaryQuadraticModel.empty(dimod.SPIN)
        dimod.testing.assert_bqm_almost_equal(bqm0, bqm1)
github dwavesystems / dimod / tests / test_spin_transform.py View on Github external
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)
github dwavesystems / dimod / tests / test_truncatecomposite.py View on Github external
def test_10(self):
        sampler = TruncateComposite(ExactSolver(), 10)
        dtest.assert_sampler_api(sampler)
        dtest.assert_composite_api(sampler)

        self.assertEqual(sampler.parameters, {})
github dwavesystems / dimod / tests / test_trackingcomposite.py View on Github external
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, [])
github dwavesystems / dimod / tests / test_testing.py View on Github external
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)