コード例 #1
0
    def test_bq_encodes_empty_bqm(self):
        """Empty BQM has to be trivially encoded."""

        bqm = dimod.BQM.from_qubo({})
        req = encode_problem_as_bq(bqm)

        self.assertEqual(req.get('format'), 'bq')
        self.assertEqual(pluck(req, 'data.version.bqm_schema'), '3.0.0')
        self.assertEqual(pluck(req, 'data.num_variables'), 0)
        self.assertEqual(pluck(req, 'data.num_interactions'), 0)
コード例 #2
0
    def test_bq_request_encoding_ising_bqm(self):
        """Simple Ising BQM properly encoded."""

        bqm = dimod.BQM.from_ising({0: 1}, {(0, 1): 1})
        req = encode_problem_as_bq(bqm)

        self.assertEqual(req.get('format'), 'bq')
        self.assertEqual(pluck(req, 'data.version.bqm_schema'), '3.0.0')
        self.assertEqual(pluck(req, 'data.variable_type'), 'SPIN')
        self.assertEqual(pluck(req, 'data.num_variables'), 2)
        self.assertEqual(pluck(req, 'data.num_interactions'), 1)
コード例 #3
0
    def test_bq_encodes_qubo_bqm(self):
        """Simple Qubo BQM properly encoded."""

        bqm = dimod.BQM.from_qubo({(0, 1): 1})
        req = encode_problem_as_bq(bqm)

        self.assertEqual(req.get('format'), 'bq')
        self.assertEqual(pluck(req, 'data.version.bqm_schema'), '3.0.0')
        self.assertEqual(pluck(req, 'data.variable_type'), 'BINARY')
        self.assertEqual(pluck(req, 'data.num_variables'), 2)
        self.assertEqual(pluck(req, 'data.num_interactions'), 1)
コード例 #4
0
    def test_bq_encodes_bqm_with_named_vars(self):
        """BQM with named variable properly encoded."""

        bqm = dimod.BQM.from_ising({}, {'ab': 1, 'bc': 1, 'ca': 1})
        req = encode_problem_as_bq(bqm)

        self.assertEqual(req.get('format'), 'bq')
        self.assertEqual(pluck(req, 'data.version.bqm_schema'), '3.0.0')
        self.assertEqual(pluck(req, 'data.variable_type'), 'SPIN')
        self.assertEqual(pluck(req, 'data.num_variables'), 3)
        self.assertEqual(pluck(req, 'data.num_interactions'), 3)
        self.assertEqual(pluck(req, 'data.variable_labels'), list('abc'))
コード例 #5
0
    def test_bimodal_cluster_sampling_statistics(self):
        bqm = dimod.BQM.from_qubo({'ab': 1, 'bd': 1, 'dc': 1, 'ca': 1})
        nodes = sorted(bqm.variables)

        s1 = State.from_samples(dict(zip(nodes, [0, 1, 0, 0])), bqm)
        s2 = State.from_samples(dict(zip(nodes, [0, 0, 1, 0])), bqm)

        exp1 = SampleSet.from_samples_bqm(dict(zip(nodes, [0, 0, 0, 0])), bqm)
        exp2 = SampleSet.from_samples_bqm(dict(zip(nodes, [0, 1, 1, 0])), bqm)

        icm = IsoenergeticClusterMove(seed=None)
        inp = States(s1, s2)
        exp = [exp1, exp2]

        # split between [exp1, exp2] and [exp2, exp1] as output samples
        # should be ~50%
        cnt = 0
        n = 100
        for _ in range(n):
            res = icm.run(inp).result()
            r1, r2 = pluck(res, 'samples')

            # test responses are valid
            self.assertIn(r1, exp)
            self.assertIn(r2, exp)

            # verify total samples energy doesn't change after ICM
            self.assertEqual(self.total_energy(inp), self.total_energy(res))

            # count responses
            if r1 == exp1 and r2 == exp2:
                cnt += 1

        self.assertLess(cnt, 0.75 * n)
        self.assertGreater(cnt, 0.25 * n)
コード例 #6
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_key2_from_dict(self):
     self.assertEqual(pluck({1: 1, "1": "1"}, "['1']"), "1")
コード例 #7
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_null_obj_with_default(self):
     self.assertEqual(pluck(None, "x", default=1), 1)
コード例 #8
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_null_obj(self):
     self.assertEqual(pluck(None, "x"), None)
コード例 #9
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_attrgetter_list_two(self):
     self.assertEqual(pluck([{"a": "a"}, {"a": "b"}], "a"), ["a", "b"])
コード例 #10
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_idx_from_str(self):
     self.assertEqual(pluck("str", "[0]"), "s")
コード例 #11
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_slice_all_from_dict(self):
     self.assertEqual(pluck({1: 1, "1": "1"}, "[:]"), [1])
コード例 #12
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_attrgetter_dict(self):
     self.assertEqual(pluck({1: 1, "a": "a"}, "a"), "a")
コード例 #13
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_keys1_from_dict(self):
     self.assertEqual(pluck({1: 1, "1": "1"}, '[1, "2"]'), [1])
コード例 #14
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_empty_selector(self):
     self.assertEqual(pluck(1, ''), 1)
コード例 #15
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_key_from_dict(self):
     self.assertEqual(pluck({1: 1, "1": "1"}, '["1"]'), "1")
コード例 #16
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_idx_from_dict(self):
     self.assertEqual(pluck({1: 1}, "[1]"), 1)
コード例 #17
0
ファイル: test_pluck.py プロジェクト: orenshk/plucky
 def test_itemgetter_idx_from_list(self):
     self.assertEqual(pluck(range(3), "[1]"), 1)