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 

15import uuid 

16from typing import Union 

17 

18from braket.tasks import AnnealingQuantumTaskResult, GateModelQuantumTaskResult, QuantumTask 

19 

20 

21class LocalQuantumTask(QuantumTask): 

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

23 

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

25 """ 

26 

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

28 self._id = uuid.uuid4() 

29 self._result = result 

30 

31 @property 

32 def id(self) -> str: 

33 return str(self._id) 

34 

35 def cancel(self) -> None: 

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

37 

38 def state(self) -> str: 

39 return "COMPLETED" 

40 

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

42 return self._result 

43 

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

45 # TODO: Allow for asynchronous simulation 

46 raise NotImplementedError("Asynchronous local simulation unsupported") 

47 

48 def __repr__(self) -> str: 

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