Esempio n. 1
0
    def test_quadratic(self):

        sampler = HigherOrderComposite(self.tracker)

        Q = {(0, 0): 1, (0, 1): 2}

        sampleset = sampler.sample_hubo(Q, initial_state={0: 1, 1: 1})

        # nothing should change
        self.assertEqual(self.tracker.input['initial_state'], {0: 1, 1: 1})
Esempio n. 2
0
    def test_higherorder_binary(self):
        sampler = HigherOrderComposite(self.tracker)

        Q = {'abc': -1, 'ab': 1}

        sampleset = sampler.sample_hubo(Q,
                                        initial_state={
                                            'a': 1,
                                            'b': 1,
                                            'c': 0
                                        })

        initial_state = self.tracker.input['initial_state']

        self.assertIn(initial_state, [
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'a*b': 1
            },
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'a*c': 0
            },
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'b*c': 0
            },
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'b*a': 1
            },
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'c*a': 0
            },
            {
                'a': 1,
                'b': 1,
                'c': 0,
                'c*b': 0
            },
        ])