Exemplo n.º 1
0
    def test_kwargs(self):
        bqm = dimod.BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN)
        with self.assertWarns(SamplerUnknownArgWarning):
            sampleset = dimod.ExactSolver().sample(bqm, a=1, b="abc")

        dqm = dimod.DiscreteQuadraticModel()
        with self.assertWarns(SamplerUnknownArgWarning):
            sampleset = dimod.ExactDQMSolver().sample_dqm(dqm, a=1, b="abc")
Exemplo n.º 2
0
    def test_arbitrary_labels(self):
        bqm = dimod.BQM.from_ising({}, {'ab': -1})
        sampleset = dimod.ExactSolver().sample(bqm)
        self.assertEqual(set(sampleset.variables), set(bqm.variables))

        dqm = dimod.DQM.from_numpy_vectors([0], [-1], ([], [], []),
                                           labels={'ab'})
        sampleset = dimod.ExactDQMSolver().sample_dqm(dqm)
        self.assertEqual(set(sampleset.variables), set(dqm.variables))
Exemplo n.º 3
0
    def test_sample_DISCRETE(self):
        dqm = dimod.DiscreteQuadraticModel.from_numpy_vectors(
            case_starts=[0, 3],
            linear_biases=[0, 1, 2, 0, 1, 2, 3, 4, 5],
            quadratic=([5, 5, 5, 7, 7, 7], [0, 1, 2, 0, 1,
                                            2], [0, 1, 2, 1, 2, 3]))
        response = dimod.ExactDQMSolver().sample_dqm(dqm)

        # every possible combination should be present
        self.assertEqual(len(response), 18)
        self.assertEqual(response.record.sample.shape,
                         (18, dqm.num_variables()))

        #confirm vartype
        self.assertIs(response.vartype, dimod.DISCRETE)

        dimod.testing.assert_sampleset_energies_dqm(response, dqm)
Exemplo n.º 4
0
    def test_sample_DISCRETE_empty(self):
        dqm = dimod.DiscreteQuadraticModel()
        response = dimod.ExactDQMSolver().sample_dqm(dqm)

        self.assertEqual(response.record.sample.shape, (0, 0))
        self.assertIs(response.vartype, dimod.DISCRETE)