Package: qlep
Quantum Leader Election Protocols (QLEP)DescriptionThe current project propose a template for developing and testing quantum leader election protocols. Most of the research protocols are implemented and can be compared with new proposals.
The scope of the project is to contain all the protocols in a single repository and to be able to compare them on the same benchmarks.InstallpipinstallqlepUse of AWS providerFollow instructionshttps://aws.amazon.com/blogs/quantum-computing/setting-up-your-local-development-environment-in-amazon-braket/exportAWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_IDexportAWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEYexportAWS_DEFAULT_REGION=us-west-1Use of IBM providerFollow instructionshttps://github.com/Qiskit/qiskit-ibm-providerfromqiskit_ibm_providerimportIBMProviderIBMProvider.save_account('YOUR_IBM_TOKEN')Latex for plotssudoapt-getinstall-ytexlive-latex-base
sudoapt-getinstall-ytexlive-latex-extra
sudoapt-getinstall-ydvipng
sudoapt-getinstall-ycm-superUsageimportqlepqdp=qlep.core.QuantumDataProvider(provider=qlep.core.Provider.AER,backend_name="aer_simulator")committee=qlep.core.CommitteeType.ALL.get_committee(no_nodes=8,committee_size=8)current_qlep=qlep.ecc.WalshQLEP(no_nodes=8,no_elections=10,quantum_data_provider=qdp,committee=committee)current_qlep.generate_quantum_data()current_qlep.simulate_elections()# only if latex is installedcurrent_qlep.draw_boxplot(simulate_file_name=current_qlep.get_simulate_file_name(),draw_directory="plots")Test your proposed protocolimportqlep# numpyimportnumpyasnp# qiskitimportqiskit# override decoratorfromtyping_extensionsimportoverrideclassNQLEP(qlep.core.QuantumLeaderElectionProtocolwithPoS):r"""An example class for a dummy quantum leader election protocol"""def__init__(self,no_nodes:int,no_elections:int=1,quantum_data_provider:qlep.core.QuantumDataProvider=None,committee:qlep.core.Committee=None,)->None:super().__init__(election_type=qlep.core.ElectionType.NEWPROTOCOL,no_nodes=no_nodes,no_elections=no_elections,quantum_data_provider=quantum_data_provider,committee=committee)@overridedefget_quantum_circuits(self,measure:bool=True)->list[qiskit.QuantumCircuit]:return[NQLEPStateGenerator.get_quantum_circuits(no_nodes=self.quantum_no_nodes,measure=measure)]@overridedefget_leader_election_algorithm(self)->qlep.core.LeaderElectionAlgorithm:returnNQLEPLeaderElectionAlgorithm()@overridedefget_malicious_attacker(self)->qlep.core.MaliciousAttacker:returnNQLEPMaliciousAttacker()classNQLEPStateGenerator:@staticmethoddefget_quantum_circuits(no_nodes:int,measure:bool=True)->qiskit.QuantumCircuit:# the number of qubitsno_qubits=no_nodes# the qubits registerquantum_registers=qiskit.QuantumRegister(no_qubits,'q')ifmeasure:# the classic registersclassic_registers=qiskit.ClassicalRegister(no_qubits,'c')# the quantum circuit which use the qubits# and the classic bits registersquantum_circuit=qiskit.QuantumCircuit(quantum_registers,classic_registers)else:quantum_circuit=qiskit.QuantumCircuit(quantum_registers)# create the superposition for the first two qubitsquantum_circuit.h(quantum_registers[0])quantum_circuit.cx(quantum_registers[0],quantum_registers[1])quantum_circuit.x(quantum_registers[0])quantum_circuit.barrier()ifmeasure:quantum_circuit.measure(quantum_registers,classic_registers)returnquantum_circuitclassNQLEPLeaderElectionAlgorithm(qlep.core.LeaderElectionAlgorithm):def__init__(self)->None:super().__init__()@overridedefelect(self,data:np.ndarray)->int:match(data[0,0,0],data[0,0,1]):case(1,0):return0case(0,1):return1case_:return-1classNQLEPMaliciousAttacker(qlep.core.MaliciousAttacker):def__init__(self)->None:super().__init__()@overridedefattack(self,register_ids:np.ndarray,data:np.ndarray,malicious_ids:np.ndarray)->np.ndarray:# get the malicious nodesmalicious_nodes=[xforxinregister_idsifxinmalicious_ids]# if no malicious nodes under our control than return the given dataifnotmalicious_nodes:returndata# init return datamodified_data=np.copy(data)# verify if the first two nodes are maliciousmatch(register_ids[0]inmalicious_ids,register_ids[1]inmalicious_ids):case(True,False):modified_data[0,0,0]=1case(False,True):modified_data[0,0,1]=1case(True,True):modified_data[0,0,0]=1modified_data[0,0,1]=0case_:passreturnmodified_dataCreditsList of colaborators:Stefan-Dan CiocirlanDumitrel LoghinLicenseDistributed under the EUPL v1.2 License. SeeLICENSE.txtfor more information.