Try to cancel the problem corresponding to this result. Non-blocking call to the remote resource in a best-effort attempt to prevent execution of a problem. Examples: This example creates a solver using the local system's default D-Wave Cloud Client
(self)
| 473 | return self._results_ready_event.is_set() |
| 474 | |
| 475 | def cancel(self): |
| 476 | """Try to cancel the problem corresponding to this result. |
| 477 | |
| 478 | Non-blocking call to the remote resource in a best-effort attempt to |
| 479 | prevent execution of a problem. |
| 480 | |
| 481 | Examples: |
| 482 | This example creates a solver using the local system's default |
| 483 | D-Wave Cloud Client configuration file, submits a simple QUBO |
| 484 | problem to a remote D-Wave resource for 100 samples, and tries |
| 485 | (and in this case succeeds) to cancel it. |
| 486 | |
| 487 | >>> from dwave.cloud import Client |
| 488 | >>> client = Client.from_config() # doctest: +SKIP |
| 489 | >>> solver = client.get_solver() # doctest: +SKIP |
| 490 | >>> u, v = next(iter(solver.edges)) # doctest: +SKIP |
| 491 | >>> Q = {(u, u): -1, (u, v): 0, (v, u): 2, (v, v): -1} # doctest: +SKIP |
| 492 | >>> computation = solver.sample_qubo(Q, num_reads=100) # doctest: +SKIP |
| 493 | >>> computation.cancel() # doctest: +SKIP |
| 494 | >>> computation.done() # doctest: +SKIP |
| 495 | True |
| 496 | >>> computation.remote_status # doctest: +SKIP |
| 497 | 'CANCELLED' |
| 498 | >>> client.close() # doctest: +SKIP |
| 499 | |
| 500 | """ |
| 501 | # Don't need to cancel something already finished |
| 502 | if self.done(): |
| 503 | return |
| 504 | |
| 505 | with self._single_cancel_lock: |
| 506 | # Already done |
| 507 | if self._cancel_requested: |
| 508 | return |
| 509 | |
| 510 | # Set the cancel flag |
| 511 | self._cancel_requested = True |
| 512 | |
| 513 | # The cancel request will be sent here, or by the solver when it |
| 514 | # gets a status update for this problem (in the case where the id hasn't been set yet) |
| 515 | if self.id is not None and not self._cancel_sent: |
| 516 | self._cancel_sent = True |
| 517 | self.solver.client._cancel(self.id, self) |
| 518 | |
| 519 | def wait_id(self, timeout=None): |
| 520 | """Blocking id getter. |