Esempio n. 1
0
    def test_bq_response_decoding(self):
        """Answer to simple problem properly decoded."""

        ss = dimod.SampleSet.from_samples(
            ([[0, 1], [1, 0]], 'ab'), vartype='BINARY', energy=0)

        msg = dict(answer=dict(format='bq', data=ss.to_serializable()))

        res = decode_bq(msg)

        self.assertEqual(res.get('problem_type'), 'bqm')
        self.assertEqual(res.get('sampleset'), ss)
Esempio n. 2
0
    def decode_response(self, msg):
        if msg['type'] not in self._handled_problem_types:
            raise ValueError('Unknown problem type received.')

        fmt = msg.get('answer', {}).get('format')
        if fmt not in self._handled_encoding_formats:
            raise ValueError('Unhandled answer encoding format received.')

        if fmt == 'qp':
            return self._decode_qp(msg)
        elif fmt == 'bq':
            return decode_bq(msg)
        else:
            raise ValueError("Don't know how to decode %r answer format" % fmt)
Esempio n. 3
0
 def verify_problem_answer(self, answer: models.ProblemAnswer):
     ans = decode_bq(
         msg=dict(answer=answer.dict(), type=self.problem_type.value))
     ss = ans['sampleset']
     self.assertEqual(ss.variables, self.bqm.variables)
     dimod.testing.assert_sampleset_energies(ss, self.bqm)