def InvertibilityTest( self, operator ): transposed = NP.transpose(operator) conjugateTransp = NP.conjugate(transposed) answer = NP.matrix(operator,complex) * NP.matrix (conjugateTransp,complex) ## Tests if 'answer' is an identity matrix ## elemAnterior = None valida = True for linha in range (len(answer)): for coluna in range (len(answer)): if linha == coluna: if elemAnterior != None: if answer[linha,coluna] == elemAnterior and answer[linha,coluna] != complex(0): elemAnterior = answer[linha,coluna] else: valida = False break else: elemAnterior = answer[linha,coluna] else: if answer[linha,coluna] != 0: valida = False break ## Check the result of previous test ## if valida == False: aviso = wx.MessageDialog( self, self.translate.translateById("custom_operator_definition_error"), self.translate.translateById("error"), wx.OK | wx.ICON_HAND ) aviso.ShowModal() ## Verify if the operator's name already is in the qGMAnalyzer library ## bib = qGMAnalyzer.qMGBib() if self.nameOp.GetValue().encode() in bib.one_qubit: valida = False aviso = wx.MessageDialog( self, self.translate.translateById("custom_operator_name_error"), self.translate.translateById("error"), wx.OK | wx.ICON_HAND ) aviso.ShowModal() if valida == True: return True else: return False
def __init__( self, parent, ID, title, objects, customOperators): wx.Frame.__init__( self, parent, ID, title, wx.Point( 400, 600 ), wx.Size( 550, 250 ) ) # Create the main window. self.panel = wx.Panel( self, wx.NewId( ), wx.Point( 0, 0 ), wx.Size( 550,250 ), wx.RAISED_BORDER ) # Create the panel where the elements will be posted. if parent != None: self.parent = parent # Instance of qPE, needed for access to some methods. self.bib = qGMAnalyzer.qMGBib() # Instance of qGMAnalyzer. self.customOperators = customOperators self.objects = objects self.commonOp = [] self.sincList = [] self.functions = [] # List of quantum operators used as choose options. self.cbList = [] # List of combo boxes. self.numControls = 0 self.numQubits = 0 macroOp = [] funcList = [] #if self.objects == []: # msgerro = wx.MessageDialog( self, "Objetos nao selecionados", "error", wx.OK | wx.ICON_HAND ) # msgerro.ShowModal( ) # msgerro.Destroy( ) # self.Destroy() for element in self.objects: if element.gettipo( ) == "envelope": self.GetBasicSinc(element) # 'self.sincList' is a list of all basic synchronizations. elif element.gettipo( ) == "macro": macroOp.append(element.getParametro()) elif element.gettipo() == "iterativo": process = element.getObjeto() operators = process.getacao() funcList.append(operators) elif element.gettipo() == "partquantum": operators = element.getacao() funcList.append(operators) for parameters in macroOp: # 'macroOp' is a list of macro's parameters. sequential = parameters.split(";") for synchronizations in sequential: funcList.append(synchronizations) for synchronizations in self.sincList: elementList = synchronizations.getshapes() for element in elementList: if element.gettipo() == "conselem" and element.getposicao() == "0": funcList.append(element.getacao().encode()) # Get the 'action' parameter(string format) of elementary process. elif element.gettipo() == "partquantum" and element.getposicaoInicial() == "0": funcList.append(element.getacao().encode()) # Get the 'action' parameter(string format) of elementary process. controlOp = 1 targetOp = 1 swapOp = 1 control = False swap = False count = 0 for name in funcList: if control == True: controlOp += 1 targetOp += 1 control = False if name[:1:] == "(": name = name[1:len(name)-1:] list = name.split(",") for operator in list: if operator[:7:] == "Control": control = True ## Trocar indice do controle para o valor de controlOp ## begin = operator[:7:] ind = operator.find("(") end = operator[ind::] operator = begin + str(controlOp) + end elif operator[:6:] == "Target": begin = operator[:6:] ind = operator.find("(") end = operator[ind::] operator = begin + str(targetOp) + end elif operator[:4:] == "Swap": if count == 2: count = 0 swapOp += 1 operator += str(swapOp) count += 1 self.functions.append(operator) self.numControls = controlOp ## Count the number of qubits involved in the synchronization ## numElements = 0 for operacoes in self.functions: if operacoes[:6:] == "Target" or operacoes[:7:] == "Control" or operacoes[:4:] == "Swap": # Indetifies the controled operator numElements += 1 elif operacoes in self.bib.one_qubit: numElements += 1 else: for index in customOperators: if operacoes == index[0]: numElements += (index[2]) #1, 2 or 3 qubits operator. self.numQubits = numElements ## Build the selection options ## maxHeight = 0 # Indicates the position of the comboBox witch is closer to the bottom of the window. posWidth = 20 # Actual position where the comboBox will be created. posHeight = 20 # Actual position where the comboBox will be created. maxCombo = 6 # Limit number of comboBoxes in one column. data = unichr(186).encode("utf-8") for qubit in range (1,numElements+1): string = "%d"+data.decode("utf-8")+" qubit" wx.StaticText(self.panel, -1, (string % qubit), (posWidth, posHeight + 5), (65, 18)) cb = self.MakeComboBox(qubit, posWidth + 65, posHeight) self.cbList.append(cb) posHeight += 30 if qubit%maxCombo == 0: # If qubit is multiple of maxCombo, change the column where the next combo will be created. posHeight = 20 posWidth += 175 if posHeight > maxHeight: maxHeight = posHeight posBut = (posWidth/2, maxHeight+30) self.okButton = wx.Button( self.panel, wx.NewId( ), "Ok", wx.Point( posBut[0], posBut[1]), wx.Size( 60, 30 ) ) self.Bind( wx.EVT_BUTTON, self.Confirms, self.okButton ) # # # self.cancelButton = wx.Button( self.panel, wx.NewId( ), "Cancel", wx.Point( posBut[0]+80, posBut[1]), wx.Size( 60, 30 ) ) self.Bind( wx.EVT_BUTTON, self.Cancel, self.cancelButton ) self.SetSize((posWidth+245,maxHeight+120))