MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _handle_problem_status

Method _handle_problem_status

dwave/cloud/client/base.py:1413–1530  ·  view source on GitHub ↗

Handle the results of a problem submission or results request. This method checks the status of the problem and puts it in the correct queue. Args: message (dict): Update message from the SAPI server wrt. this problem. future (:class:

(self, message, future)

Source from the content-addressed store, hash-verified

1411 session.close()
1412
1413 def _handle_problem_status(self, message, future):
1414 """Handle the results of a problem submission or results request.
1415
1416 This method checks the status of the problem and puts it in the correct
1417 queue.
1418
1419 Args:
1420 message (dict):
1421 Update message from the SAPI server wrt. this problem.
1422 future (:class:`dwave.cloud.computation.Future`:
1423 future corresponding to the problem
1424
1425 Note:
1426 This method is always run inside of a daemon thread.
1427 """
1428 try:
1429 logger.trace("Handling response: %r", message)
1430 if not isinstance(message, dict):
1431 raise InvalidAPIResponseError("Unexpected format of problem description response")
1432 logger.debug("Handling response for %s with status %s",
1433 message.get('id'), message.get('status'))
1434
1435 # Handle errors in batch mode
1436 if 'error_code' in message and 'error_msg' in message:
1437 logger.debug("Error response received: %r", message)
1438 raise SolverFailureError(message['error_msg'])
1439
1440 if 'status' not in message:
1441 raise InvalidAPIResponseError("'status' missing in problem description response")
1442 if 'id' not in message:
1443 raise InvalidAPIResponseError("'id' missing in problem description response")
1444
1445 future.id = message['id']
1446 future.label = message.get('label')
1447 future.remote_status = status = message['status']
1448
1449 # The future may not have the ID set yet
1450 with future._single_cancel_lock:
1451 # This handles the case where cancel has been called on a future
1452 # before that future received the problem id
1453 if future._cancel_requested:
1454 if not future._cancel_sent and status == self.STATUS_PENDING:
1455 # The problem has been canceled but the status says its still in queue
1456 # try to cancel it
1457 self._cancel(message['id'], future)
1458 # If a cancel request could meaningfully be sent it has been now
1459 future._cancel_sent = True
1460
1461 if not future.time_received and message.get('submitted_on'):
1462 future.time_received = parse_datetime(message['submitted_on'])
1463
1464 if not future.time_solved and message.get('solved_on'):
1465 future.time_solved = parse_datetime(message['solved_on'])
1466
1467 if status == self.STATUS_COMPLETE:
1468 # TODO: find a better way to differentiate between
1469 # `completed-on-submit` and `completed-on-poll`.
1470 # Loading should happen only once, not every time when response

Callers 3

_do_submit_problemsMethod · 0.95
_do_poll_problemsMethod · 0.95
_do_load_resultsMethod · 0.95

Calls 13

_cancelMethod · 0.95
get_solverMethod · 0.95
_loadMethod · 0.95
_pollMethod · 0.95
SolverFailureErrorClass · 0.85
CanceledFutureErrorClass · 0.85
SolverOfflineErrorClass · 0.85
_set_messageMethod · 0.80
resultMethod · 0.80
decMethod · 0.80
_set_exceptionMethod · 0.80

Tested by

no test coverage detected