def ajustaDimensao(self, dimensao, tamanho, nonZeroValues=[], labelRep="Binary"): if self.binarios == []: self.binarios = binario.inicializaBinarios(tamanho) self.dimensao = dimensao self.tamanho = tamanho if dimensao == 1: if nonZeroValues != []: self.ClearGrid() self.setTamanho(1, tamanho) # self.SetRowLabelValue( 0, "0" ) for indice in range(tamanho): if labelRep == "Binary": label = "|" + str(self.binarios[nonZeroValues[indice]]) + ">" self.SetColLabelValue(indice, label) self.SetColSize(indice, len(label) * 10) elif labelRep == "Decimal": label = "|" + str(nonZeroValues[indice]) + ">" self.SetColLabelValue(indice, label) self.SetColSize(indice, 100) else: self.setTamanho(1, 2 ** tamanho) self.ClearGrid() self.SetRowLabelValue(0, "0") for indice in range(2 ** tamanho): if labelRep == "Binary": label = "|" + str(self.binarios[indice]) + ">" self.SetColLabelValue(indice, label) self.SetColSize(indice, len(label) * 10) elif labelRep == "Decimal": label = "|" + str(indice) + ">" self.SetColLabelValue(indice, label) self.SetColSize(indice, 100) elif dimensao == 2: self.setTamanho(tamanho + 1, tamanho + 1) self.ClearGrid() for indice in range(self.tamx - 1): self.SetRowLabelValue( int(indice), str(indice) ) # Colocado para retirar as linhas com ... já que a função de ajuste de nomes ignora essas linhas self.SetColLabelValue(int(indice), str(indice)) self.SetRowLabelValue(self.tamx - 1, "...") self.SetColLabelValue(self.tamy - 1, "...") self.ajustaNomesLinhas(dimensao) # Arrumar os nomes das linhas aqui else: # Se for mais do que 2 dimensões nrotabelas = self.calculaTamanhoGrid( dimensao, tamanho ) # Recebe o número de tabelas de acordo com a dimensão e o tamanho linhas = nrotabelas * ( tamanho + 1 ) # Informa quantas linhas por tabela terá e após isso linhas terá o número de linhas para o grid self.setTamanho(linhas, tamanho + 1) self.ClearGrid() for indice in range(self.tamx - 1): self.SetRowLabelValue( int(indice), str(indice) ) # Colocado para retirar as linhas com ... já que a função de ajuste de nomes ignora essas linhas self.SetColLabelValue(int(indice), str(indice)) ret = self.tamy # Referência de quando em quando ocorre as "..." self.SetColLabelValue(self.tamy - 1, "...") while ret <= self.tamx: self.SetRowLabelValue(ret - 1, "...") ret = ret + self.tamy self.ajustaNomesLinhas(dimensao) # Arrumar os nomes das linhas
def ArrumaOperacoes(self, operations): opList = operations.split(",") #operations = "(" + operations + ")" control = False i = len(opList) - 1 while (i >=0): op = opList[i] if op[:7:] == "Control": control = True numControls = int(op[7:op.rfind("(")]) break i-=1 if control == True: controlQubits = [] controlValues = [] targetQubits = [] targetOperators = [] singleOperator = [] qubitSingleOperator = [] numTargets = 0 numControlQubits = 0 for i in range (numControls): controlQubits.append([]) controlValues.append([]) targetQubits.append([]) targetOperators.append([]) for qubit in range (len(opList)): if opList[qubit][:7:] == "Control": ind = opList[qubit].find("(") pos = opList[qubit][7:ind:] controlQubits[int(pos)-1].append(qubit+1) controlValues[int(pos)-1].append(opList[qubit][ind+1:ind+2:]) numControlQubits += 1 elif opList[qubit][:6:] == "Target": ind = opList[qubit].find("(") pos = opList[qubit][6:ind:] targetQubits[int(pos)-1].append(qubit+1) ind2 = opList[qubit].find(")") targetOperators[int(pos)-1].append(opList[qubit][ind+1:ind2:]) numTargets += 1 else: singleOperator.append(opList[qubit]) qubitSingleOperator.append(qubit+1) numSingleOperators = len (singleOperator) ## Builds the operator with the informed parameters ## binario = inicializaBinarios(numControlQubits) # Initializes the set of binary numbers acao = "(" # String that corresponding to the matrix notation of the operator operators = [] numId = 0 for pos in range(numControlQubits+numTargets+numSingleOperators): operators.append([]) for qubit in range (2**int(numControlQubits)): if acao != "(": acao += ") + (" numId = 0 binNumber = binario[qubit] # The binary number defines the operators of tensor product. The bits determines which Control operator will be added to the tensor product. binNumberList = list(binNumber) # Used to determine the Control operator (Control0 or Control1) to be added to the expession. for singleOp in range(numSingleOperators): operators[qubitSingleOperator[singleOp]-1] = singleOperator[singleOp] while binNumberList != []: for i in range(numControls): controlIndex = controlQubits[i] targetIndex = targetQubits[i] controlValuesList = list(controlValues[i]) bin = [] for j in range(len(controlValues[i])): bin.append(binNumberList.pop(0)) correctBin = True for bit in range(len(bin)): operators[controlIndex[bit]-1] = "Control"+str(i+1)+"("+bin[bit]+")" if bin[bit] != controlValuesList[bit]: correctBin = False for target in range(len(targetIndex)): if correctBin == True: operators[targetIndex[target]-1] = "Target"+str(i+1)+"("+targetOperators[i][target]+")" else: numId += 1 operators[targetIndex[target]-1] = "Target"+str(i+1)+"(Id)" if numId < numTargets: for op in operators: acao += op + "," acao = acao[:len(acao)-1:] elif acao != "(": acao = acao[:len(acao)-5:] acao += ")" operations = acao return operations
def Confirms (self, event): translate = Translate.Translate() # Instance of the translation file. customMatrices = [] # List of matrices from the customized operators. operations = "" # String of synchronized operators. for obj in self.objects: if obj.gettipo() == "envelope": self.Desagrupar (obj) for comboBox in self.cbList: if comboBox.GetValue().encode() == "": value = "Id" else: value = comboBox.GetValue().encode() if operations == "": operations += value # Get the selected operator. else: operations = operations + "," + value for operation in self.customOperators: if comboBox.GetSelection() == operation[0]: customMatrices.append(operation[1]) opList = operations.split(",") control = False for op in opList: if op[:7:] == "Control": control = True break if control == True: controlQubits = [] controlValues = [] targetQubits = [] targetOperators = [] singleOperator = [] qubitSingleOperator = [] numTargets = 0 numControlQubits = 0 for i in range (self.numControls): controlQubits.append([]) controlValues.append([]) targetQubits.append([]) targetOperators.append([]) for qubit in range (len(opList)): if opList[qubit][:7:] == "Control": ind = opList[qubit].find("(") pos = opList[qubit][7:ind:] controlQubits[int(pos)-1].append(qubit+1) controlValues[int(pos)-1].append(opList[qubit][ind+1:ind+2:]) numControlQubits += 1 elif opList[qubit][:6:] == "Target": ind = opList[qubit].find("(") pos = opList[qubit][6:ind:] targetQubits[int(pos)-1].append(qubit+1) ind2 = opList[qubit].find(")") targetOperators[int(pos)-1].append(opList[qubit][ind+1:ind2:]) numTargets += 1 else: singleOperator.append(opList[qubit]) qubitSingleOperator.append(qubit+1) numSingleOperators = len (singleOperator) ## Builds the operator with the informed parameters ## binario = inicializaBinarios(numControlQubits) # Initializes the set of binary numbers acao = "(" # String that corresponding to the matrix notation of the operator operators = [] numId = 0 for pos in range(numControlQubits+numTargets+numSingleOperators): operators.append([]) for qubit in range (2**int(numControlQubits)): if acao != "(": acao += ") + (" numId = 0 binNumber = binario[qubit] # The binary number defines the operators of tensor product. The bits determines which Control operator will be added to the tensor product. binNumberList = list(binNumber) # Used to determine the Control operator (Control0 or Control1) to be added to the expession. for singleOp in range(numSingleOperators): operators[qubitSingleOperator[singleOp]-1] = singleOperator[singleOp] while binNumberList != []: for i in range(self.numControls): controlIndex = controlQubits[i] targetIndex = targetQubits[i] controlValuesList = list(controlValues[i]) bin = [] for j in range(len(controlValues[i])): bin.append(binNumberList.pop(0)) correctBin = True for bit in range(len(bin)): operators[controlIndex[bit]-1] = "Control"+str(i+1)+"("+bin[bit]+")" if bin[bit] != controlValuesList[bit]: correctBin = False for target in range(len(targetIndex)): if correctBin == True: operators[targetIndex[target]-1] = "Target"+str(i+1)+"("+targetOperators[i][target]+")" else: numId += 1 operators[targetIndex[target]-1] = "Target"+str(i+1)+"(Id)" if numId < numTargets: for op in operators: acao += op + "," acao = acao[:len(acao)-1:] elif acao != "(": acao = acao[:len(acao)-5:] acao += ")" operations = acao dialog = Dialog.Dialog("representationChoice", self, wx.NewId(), "Representation Choose", size=(500, 400), style=wx.DEFAULT_DIALOG_STYLE) dialog.CenterOnScreen() # this does not return until the dialog is closed. val = dialog.ShowModal() if val == wx.ID_OK: representation = dialog.GetChoice()[0] else: return None dialog.Destroy() position = [self.objects[0].GetX(),self.objects[0].GetY()] if representation == "Macro": self.parent.CriaMacroRep(operations, position) self.parent.Delete3(self.objects) elif representation == "Proc. Synchronization": self.parent.CriaPP(self.sincList, operations, "Process") elif representation == "Proc. Iterative": self.parent.BuildIterative(operations,position, "Process") elif representation == "Partial Quantum Process": dialog = Dialog.Dialog("partialChoice", self, wx.NewId(), "Partial Choose", size=(500, 400), style=wx.DEFAULT_DIALOG_STYLE) dialog.CenterOnScreen() # this does not return until the dialog is closed. val = dialog.ShowModal() if val == wx.ID_OK: partial = dialog.GetChoicePartial() else: return None dialog.Destroy() self.parent.BuildQPP(operations, self.numQubits, int(partial), position) self.parent.Delete3(self.objects) elif representation == "Partial Synchronization": self.parent.CriaPP(operations,position, "Process") elif representation == "Partial. Iterative": self.parent.BuildIterative(operations,position, "Process") self.parent.Thaw() self.Destroy()