Decode answer for problem submitted in the `bq` data format.
(msg)
| 396 | |
| 397 | |
| 398 | def decode_bq(msg): |
| 399 | """Decode answer for problem submitted in the `bq` data format.""" |
| 400 | try: |
| 401 | import dimod |
| 402 | except ImportError: # pragma: no cover |
| 403 | raise RuntimeError("Can't decode BQMs without dimod. " |
| 404 | "Re-install the library with 'bqm' support.") |
| 405 | |
| 406 | answer = msg['answer'] |
| 407 | if answer['format'] != 'bq': |
| 408 | raise ValueError(f"Unsupported answer format: {answer['format']}") |
| 409 | if 'data' not in answer: |
| 410 | raise ValueError("Incomplete answer") |
| 411 | |
| 412 | result = {} |
| 413 | |
| 414 | # sampleset is encoded in data field |
| 415 | result['sampleset'] = dimod.SampleSet.from_serializable(answer['data']) |
| 416 | |
| 417 | # include problem type |
| 418 | result['problem_type'] = msg['type'] |
| 419 | |
| 420 | return result |
| 421 | |
| 422 | |
| 423 | def decode_binary_ref(msg: dict, ref_resolver: abc.Callable) -> dict: |
no outgoing calls