Coverage for src/braket/tasks/quantum_task.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright 2019-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"). You
4# may not use this file except in compliance with the License. A copy of
5# the License is located at
6#
7# http://aws.amazon.com/apache2.0/
8#
9# or in the "license" file accompanying this file. This file is
10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11# ANY KIND, either express or implied. See the License for the specific
12# language governing permissions and limitations under the License.
14import asyncio
15from abc import ABC, abstractmethod
16from typing import Any, Dict, Union
18from braket.tasks.annealing_quantum_task_result import AnnealingQuantumTaskResult
19from braket.tasks.gate_model_quantum_task_result import GateModelQuantumTaskResult
22class QuantumTask(ABC):
23 """An abstraction over a quantum task on a quantum device."""
25 DEFAULT_SHOTS = 1_000
27 @property
28 @abstractmethod
29 def id(self) -> str:
30 """str: The task ID."""
32 @abstractmethod
33 def cancel(self) -> None:
34 """Cancel the quantum task."""
36 @abstractmethod
37 def state(self) -> str:
38 """str: State of the quantum task"""
40 @abstractmethod
41 def result(self) -> Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]:
42 """
43 Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]: Get the quantum task result.
44 Call async_result if you want the result in an asynchronous way.
45 """
47 @abstractmethod
48 def async_result(self) -> asyncio.Task:
49 """asyncio.Task: Get the quantum task result asynchronously."""
51 def metadata(self, use_cached_value: bool = False) -> Dict[str, Any]:
52 """
53 Get task metadata.
55 Args:
56 use_cached_value (bool, optional): If True, uses the value retrieved from the previous
57 request.
59 Returns:
60 Dict[str, Any]: The metadata regarding the task. If `use_cached_value` is True,
61 then the value retrieved from the most recent request is used.
62 """