Internal method for `sample_ising`, `sample_qubo` and `sample_bqm`. Args: linear (list/dict): Linear terms of the model. quadratic (dict[(int, int), float]): Quadratic terms of the model. offset (number):
(self, type_, linear, quadratic, offset, params,
label=None, undirected_biases=False)
| 1403 | |
| 1404 | @dispatches_events('sample') |
| 1405 | def _sample(self, type_, linear, quadratic, offset, params, |
| 1406 | label=None, undirected_biases=False): |
| 1407 | """Internal method for `sample_ising`, `sample_qubo` and `sample_bqm`. |
| 1408 | |
| 1409 | Args: |
| 1410 | linear (list/dict): |
| 1411 | Linear terms of the model. |
| 1412 | |
| 1413 | quadratic (dict[(int, int), float]): |
| 1414 | Quadratic terms of the model. |
| 1415 | |
| 1416 | offset (number): |
| 1417 | Constant offset applied to the model. |
| 1418 | |
| 1419 | params (dict): |
| 1420 | Parameters for the sampling method, solver-specific. |
| 1421 | |
| 1422 | label (str, optional): |
| 1423 | Problem label. |
| 1424 | |
| 1425 | undirected_biases (boolean, default=False): |
| 1426 | Are (quadratic) biases specified on undirected edges? For |
| 1427 | triangular or symmetric matrix of quadratic biases set it to |
| 1428 | ``True``. |
| 1429 | |
| 1430 | Returns: |
| 1431 | :class:`~dwave.cloud.computation.Future` |
| 1432 | """ |
| 1433 | |
| 1434 | # Check the problem |
| 1435 | if not self.check_problem(linear, quadratic): |
| 1436 | raise ProblemStructureError( |
| 1437 | f"Problem graph incompatible with {self!r}") |
| 1438 | |
| 1439 | # Mix the new parameters with the default parameters |
| 1440 | combined_params = dict(self._params) |
| 1441 | combined_params.update(params) |
| 1442 | |
| 1443 | # Check the parameters before submitting |
| 1444 | for key in combined_params: |
| 1445 | if key not in self.parameters and not key.startswith('x_'): |
| 1446 | raise KeyError("{} is not a parameter of this solver.".format(key)) |
| 1447 | |
| 1448 | # transform some of the parameters in-place |
| 1449 | self._format_params(type_, combined_params) |
| 1450 | |
| 1451 | body_dict = { |
| 1452 | 'solver': self.identity.dict(), |
| 1453 | 'data': encode_problem_as_qp(self, linear, quadratic, offset, |
| 1454 | undirected_biases=undirected_biases), |
| 1455 | 'type': type_, |
| 1456 | 'params': combined_params |
| 1457 | } |
| 1458 | if label is not None: |
| 1459 | body_dict['label'] = label |
| 1460 | body_data = orjson.dumps(body_dict, option=orjson.OPT_SERIALIZE_NUMPY) |
| 1461 | logger.trace("Encoded sample request: %r", body_data) |
| 1462 |
no test coverage detected