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 

14from abc import ABC, abstractmethod 

15from typing import Any, Dict, Union 

16 

17from braket.ir.annealing import Problem 

18from braket.ir.jaqcd import Program 

19 

20 

21class BraketSimulator(ABC): 

22 """ An abstract simulator that locally runs a quantum task. 

23 

24 The task can be either a circuit-based program or an annealing task, 

25 specified by the given IR. 

26 

27 For users creating their own simulator: to register a simulator so the 

28 Braket SDK recognizes its name, the name and class must added as an 

29 entry point for "braket.simulators". This is done by adding an entry to 

30 entry_points in the simulator package's setup.py: 

31 

32 >>> entry_points = { 

33 >>> "braket.simulators": [ 

34 >>> "backend_name = <backend_class>" 

35 >>> ] 

36 >>> } 

37 """ 

38 

39 # TODO: Move this class to the local simulator repo and take a dependency on it 

40 # As such, this will not depend on any SDK classes. 

41 

42 # TODO: Update to use new simulate() method 

43 

44 @abstractmethod 

45 def run(self, ir: Union[Program, Problem], *args, **kwargs) -> Dict[str, Any]: 

46 """ Run the task specified by the given IR. 

47 

48 Extra arguments will contain any additional information necessary to run the task, 

49 such as number of qubits. 

50 

51 Args: 

52 ir (Union[Program, Problem]): The IR representation of the program 

53 

54 Returns: 

55 Dict[str, Any]: A dict containing the results of the simulation. 

56 In order to work with braket-python-sdk, the format of the JSON dict should 

57 match that needed by GateModelQuantumTaskResult or AnnealingQuantumTaskResult 

58 from the SDK, depending on the type of task. 

59 """ 

60 raise NotImplementedError()