def test_qp_request_encoding_all_qubits(self):
        """Test biases and coupling strengths are properly encoded (base64 little-endian doubles)."""

        solver = get_structured_solver()
        linear, quadratic = generate_const_ising_problem(solver, h=1, j=-1)
        request = encode_problem_as_qp(solver, linear, quadratic)
        self.assertEqual(request['format'], 'qp')
        self.assertEqual(request['lin'],  self.encode_doubles([1, 1, 1, 1]))
        self.assertEqual(request['quad'], self.encode_doubles([-1, -1, -1, -1]))
Exemple #2
0
 def __init__(self, **kwargs):
     kwargs.setdefault(
         'solver',
         StructuredSolver(client=None, data=qpu_clique_solver_data(5)))
     kwargs.setdefault(
         'problem', generate_const_ising_problem(kwargs['solver'],
                                                 h=1,
                                                 j=-1))
     kwargs.setdefault('problem_type', 'ising')
     kwargs.setdefault('answer', self._problem_answer())
     super().__init__(**kwargs)
    def test_qp_request_encodes_offset(self):
        """Test `offset` is stored in problem data."""

        solver = get_structured_solver()
        linear, quadratic = generate_const_ising_problem(solver, h=1, j=-1)

        # default offset is zero
        request = encode_problem_as_qp(solver, linear, quadratic)
        self.assertEqual(request['offset'], 0)

        # test explicit offset
        offset = 2.0
        request = encode_problem_as_qp(solver, linear, quadratic, offset)
        self.assertEqual(request['offset'], offset)
Exemple #4
0
def test_problem(solver):
    """The problem answered by mocked replies below."""
    return generate_const_ising_problem(solver, h=1, j=-1)