Hide keyboard shortcuts

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. 

13 

14import asyncio 

15from abc import ABC, abstractmethod 

16from typing import Any, Dict, Union 

17 

18from braket.tasks.annealing_quantum_task_result import AnnealingQuantumTaskResult 

19from braket.tasks.gate_model_quantum_task_result import GateModelQuantumTaskResult 

20 

21 

22class QuantumTask(ABC): 

23 """An abstraction over a quantum task on a quantum device.""" 

24 

25 @property 

26 @abstractmethod 

27 def id(self) -> str: 

28 """str: The task ID.""" 

29 

30 @abstractmethod 

31 def cancel(self) -> None: 

32 """Cancel the quantum task.""" 

33 

34 @abstractmethod 

35 def state(self) -> str: 

36 """str: State of the quantum task""" 

37 

38 @abstractmethod 

39 def result(self) -> Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]: 

40 """ 

41 Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]: Get the quantum task result. 

42 Call async_result if you want the result in an asynchronous way. 

43 """ 

44 

45 @abstractmethod 

46 def async_result(self) -> asyncio.Task: 

47 """asyncio.Task: Get the quantum task result asynchronously.""" 

48 

49 def metadata(self, use_cached_value: bool = False) -> Dict[str, Any]: 

50 """ 

51 Get task metadata. 

52 

53 Args: 

54 use_cached_value (bool, optional): If True, uses the value retrieved from the previous 

55 request. 

56 

57 Returns: 

58 Dict[str, Any]: The metadata regarding the task. If `use_cached_value` is True, 

59 then the value retrieved from the most recent request is used. 

60 """