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 typing import Union 

16 

17from braket.tasks import AnnealingQuantumTaskResult, GateModelQuantumTaskResult, QuantumTask 

18 

19 

20class LocalQuantumTask(QuantumTask): 

21 """ A task containing the results of a local simulation. 

22 

23 Since this class is instantiated with the results, cancel() and run_async() are unsupported. 

24 """ 

25 

26 def __init__(self, result: Union[GateModelQuantumTaskResult, AnnealingQuantumTaskResult]): 

27 self._id = result.task_metadata["Id"] 

28 self._result = result 

29 

30 @property 

31 def id(self) -> str: 

32 return str(self._id) 

33 

34 def cancel(self) -> None: 

35 raise NotImplementedError("Cannot cancel completed local task") 

36 

37 def state(self) -> str: 

38 return "COMPLETED" 

39 

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

41 return self._result 

42 

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

44 # TODO: Allow for asynchronous simulation 

45 raise NotImplementedError("Asynchronous local simulation unsupported") 

46 

47 def __repr__(self) -> str: 

48 return f"LocalQuantumTask('id':{self.id})"