| |
| |
| import sys |
| sys.path.append('../tools/') |
| from interactCfg import * |
| from helperFunction import * |
|
|
| |
| def checkEnvironment(): |
| from Circuit import Circuit |
| circuitNum = len(Circuit.currentIDList) |
| |
| if circuitNum == 1: |
| if Circuit.currentIDList[0] == Circuit.instance.ids: |
| return Circuit.instance |
| try: |
| strs = "there are " + str(len(Circuit.currentIDList)) + " Circuit instance, please check your code" |
| raise EnvironmentError(strs) |
| except EnvironmentError as ee: |
| info = get_curl_info() |
| funName = info[0] |
| line = info[1] |
| writeErrorMsg(ee,funName,line) |
| |
|
|
| class NoCloning(Exception): |
| def __init__(self,msg = None): |
| if msg == None: |
| self.value = "" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: NoCloning\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| |
| class EnvironmentError(Exception): |
| def __init__(self,msg = None): |
| if msg == None: |
| self.value = "There are zero or more than one Circuit instance!" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: EnvironmentError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| class CodeError(Exception): |
| def __init__(self,msg=None): |
| if msg == None: |
| self.value = "There is something wrong with the QASM code!" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: CodeError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| class GateNameError(Exception): |
| def __init__(self,msg=None): |
| if msg == None: |
| self.value = "There is gates which have not defined in this platfrom!" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: GateNameError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
|
|
| |
| class IBMError(Exception): |
| def __init__(self,msg = None): |
| if msg == None: |
| self.value = "There is something wrong when calling the API of IBMQX!" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: IBMError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| class ExecuteModeError(Exception): |
| def __init__(self,msg = None): |
| if msg == None: |
| self.value = "executeMode must be either 'theory' or 'simulator', but we get another mode" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: ExecuteModeError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| class IDRepeatError(Exception): |
| def __init__(self,msg=None): |
| if msg == None: |
| self.value = "the id of the qubit has been used, please choose another id" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: IDRepeatError\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|
| |
| class NotNormal(Exception): |
| def __init__(self,msg=None): |
| if msg == None: |
| self.value = "the qubit or qubits is not normal, please normalize the measured qubit!" |
| else: |
| self.value = msg |
| def __str__(self): |
| result = "Error Type: NotNormal\r\n" |
| result += "Error Message: " + self.value |
| return result |
|
|