コード例 #1
0
    def test_ising_sample(self):
        h = {'a': 1, 'b': -2}
        J = {('a', 'b'): -3}
        sampler = LazyEmbeddingComposite(MockDWaveSampler())
        response = sampler.sample_ising(h, J)

        # Check that at least one response was found
        self.assertGreaterEqual(len(response), 1)
コード例 #2
0
    def test_same_embedding(self):
        sampler = LazyEmbeddingComposite(MockSampler())

        # Set up Ising and sample
        h = {'a': 1, 'b': 1, 'c': 1}
        J = {('a', 'b'): 3, ('b', 'c'): -2, ('a', 'c'): 1}
        sampler.sample_ising(h, J)

        # Store embedding
        prev_embedding = sampler.embedding

        # Check that the same embedding is used
        csp2 = dbc.ConstraintSatisfactionProblem(dbc.BINARY)
        csp2.add_constraint(or_gate(['a', 'b', 'c']))
        bqm2 = dbc.stitch(csp2)
        sampler.sample(bqm2)

        self.assertEqual(sampler.embedding, prev_embedding)
コード例 #3
0
    def test_ising(self):
        h = {0: 11, 5: 2}
        J = {(0, 5): -8}
        sampler = LazyEmbeddingComposite(MockSampler())
        response = sampler.sample_ising(h, J)

        # Check embedding
        self.assertIsNotNone(sampler.embedding)
        self.assertEqual(sampler.nodelist, [0, 5])
        self.assertEqual(sampler.edgelist, [(0, 5)])
        self.assertEqual(sampler.adjacency, {0: {5}, 5: {0}})

        # Check that at least one response was found
        self.assertGreaterEqual(len(response), 1)