def _test_from_bqm_response(self, bqm): # sample with BrickedClient() as client: solver = client.get_solver(qpu=True) response = solver.sample_ising(*self.problem, **self.params) # induce sampleset production in response, to test serialization of # sampleset-provided data, like `num_occurrences` (an numpy.ndarray) # NOTE: `dwave.cloud.computation.Future.num_occurrences` et al. will # favorize returning data from a sampleset, if it's present, instead # of returning raw SAPI data _ = response.sampleset # convert data = from_bqm_response(bqm, self.embedding_context, response, params=self.params) # validate data encoding self.verify_data_encoding(problem=self.problem, response=response, solver=solver, params=self.params, data=data, embedding_context=self.embedding_context)
def show_bqm_response(bqm, embedding_context, response, warnings=None, params=None): """ Visualize a quantum machine instruction (QMI) response and binary quadratic model. """ data = from_bqm_response(bqm=bqm, embedding_context=embedding_context, response=response, warnings=warnings, params=params) id_ = push_inspector_data(data) return open_problem(id_)
def test_solver_graph_validation(self): """All data adapters should fail on non-Chimera/Pegasus solvers.""" # sample with BrickedClient() as client: solver = client.get_solver(qpu=True) response = solver.sample_ising(*self.problem, **self.params) # resolve it before we mangle with it response.result() # change solver topology to non-chimera/pegasus to test solver validation response.solver.properties['topology']['type'] = 'unknown' # ensure `from_qmi_response` adapter fails on unstructured solver with self.assertRaises(TypeError): from_qmi_response(self.problem, response, params=self.params) # ensure `from_bqm_response` adapter fails on unstructured solver with self.assertRaises(TypeError): from_bqm_response(self.bqm, self.embedding_context, response, params=self.params)
def test_solver_type_validation(self): """All data adapters should fail on non-StructuredSolvers.""" # sample with BrickedClient() as client: solver = client.get_solver(qpu=True) response = solver.sample_ising(*self.problem, **self.params) # resolve it before we mangle with it response.result() # change solver to unstructured to test solver validation response.solver = unstructured_solver_mock # ensure `from_qmi_response` adapter fails on unstructured solver with self.assertRaises(TypeError): from_qmi_response(self.problem, response, params=self.params) # ensure `from_bqm_response` adapter fails on unstructured solver with self.assertRaises(TypeError): from_bqm_response(self.bqm, self.embedding_context, response, params=self.params)
def test_problem_label_in_response(self): """All data adapters should propagate problem label.""" # sample ising -> response with BrickedClient() as client: solver = client.get_solver(qpu=True) response = solver.sample_ising(*self.problem, label=self.label, **self.params) # ensure `from_qmi_response` adapter propagates label data = from_qmi_response(self.problem, response, params=self.params) self.assertEqual(data['details']['label'], self.label) # ensure `from_bqm_response` adapter propagates label data = from_bqm_response(self.bqm, self.embedding_context, response, params=self.params) self.assertEqual(data['details']['label'], self.label)