in src/braket/aws/aws_quantum_task.py [0:0]
def result(self) -> Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]:
"""
Get the quantum task result by polling Amazon Braket to see if the task is completed.
Once the task is completed, the result is retrieved from S3 and returned as a
`GateModelQuantumTaskResult` or `AnnealingQuantumTaskResult`
This method is a blocking thread call and synchronously returns a result.
Call `async_result()` if you require an asynchronous invocation.
Consecutive calls to this method return a cached result from the preceding request.
Returns:
Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]: The result of the task,
if the task completed successfully; returns `None` if the task did not complete
successfully or the future timed out.
"""
if self._result or (
self._metadata and self._status(True) in self.NO_RESULT_TERMINAL_STATES
):
return self._result
if self._metadata and self._status(True) in self.RESULTS_READY_STATES:
return self._download_result()
try:
async_result = self.async_result()
return async_result.get_loop().run_until_complete(async_result)
except asyncio.CancelledError:
# Future was cancelled, return whatever is in self._result if anything
self._logger.warning("Task future was cancelled")
return self._result