Skip to main content

Quantum Leader Election Protocols (QLEP)

Description

The 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.

Install

pip install qlep

Use of AWS provider

Follow instructions https://aws.amazon.com/blogs/quantum-computing/setting-up-your-local-development-environment-in-amazon-braket/

export AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
export AWS_DEFAULT_REGION=us-west-1

Use of IBM provider

Follow instructions https://github.com/Qiskit/qiskit-ibm-provider

from qiskit_ibm_provider import IBMProvider
IBMProvider.save_account('YOUR_IBM_TOKEN')

Latex for plots

sudo apt-get install -y texlive-latex-base
sudo apt-get install -y texlive-latex-extra
sudo apt-get install -y dvipng
sudo apt-get install -y cm-super

Usage

import qlep

qdp=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 installed
current_qlep.draw_boxplot(
    simulate_file_name=current_qlep.get_simulate_file_name(),
    draw_directory="plots"
)

Test your proposed protocol

import qlep
# numpy
import numpy as np
# qiskit
import qiskit
# override decorator
from typing_extensions import override


class NQLEP(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
        )

    @override
    def get_quantum_circuits(
            self,
            measure: bool = True
    ) -> list[qiskit.QuantumCircuit]:
        return [NQLEPStateGenerator.get_quantum_circuits(
                    no_nodes=self.quantum_no_nodes,
                    measure=measure
                )]

    @override
    def get_leader_election_algorithm(
            self
    ) -> qlep.core.LeaderElectionAlgorithm:
        return NQLEPLeaderElectionAlgorithm()

    @override
    def get_malicious_attacker(self) -> qlep.core.MaliciousAttacker:
        return NQLEPMaliciousAttacker()


class NQLEPStateGenerator:
    @staticmethod
    def get_quantum_circuits(
        no_nodes: int,
        measure: bool = True
    ) -> qiskit.QuantumCircuit:
        # the number of qubits
        no_qubits = no_nodes
        # the qubits register
        quantum_registers = qiskit.QuantumRegister(no_qubits, 'q')
        if measure:
            # the classic registers
            classic_registers = qiskit.ClassicalRegister(no_qubits, 'c')
            # the quantum circuit which use the qubits
            # and the classic bits registers
            quantum_circuit = qiskit.QuantumCircuit(quantum_registers,
                                                    classic_registers)
        else:
            quantum_circuit = qiskit.QuantumCircuit(quantum_registers)

        # create the superposition for the first two qubits
        quantum_circuit.h(quantum_registers[0])
        quantum_circuit.cx(quantum_registers[0], quantum_registers[1])
        quantum_circuit.x(quantum_registers[0])
        quantum_circuit.barrier()
        if measure:
            quantum_circuit.measure(quantum_registers, classic_registers)
        return quantum_circuit


class NQLEPLeaderElectionAlgorithm(qlep.core.LeaderElectionAlgorithm):
    def __init__(self) -> None:
        super().__init__()

    @override
    def elect(self, data: np.ndarray) -> int:
        match (data[0, 0, 0], data[0, 0, 1]):
            case (1, 0):
                return 0
            case (0, 1):
                return 1
            case _:
                return -1


class NQLEPMaliciousAttacker(qlep.core.MaliciousAttacker):
    def __init__(self) -> None:
        super().__init__()

    @override
    def attack(
        self,
        register_ids: np.ndarray,
        data: np.ndarray,
        malicious_ids: np.ndarray
    ) -> np.ndarray:
        # get the malicious nodes
        malicious_nodes = [x for x in register_ids if x in malicious_ids]
        # if no malicious nodes under our control than return the given data
        if not malicious_nodes:
            return data
        # init return data
        modified_data = np.copy(data)
        # verify if the first two nodes are malicious
        match (register_ids[0] in malicious_ids,
               register_ids[1] in malicious_ids):
            case (True, False):
                modified_data[0, 0, 0] = 1
            case (False, True):
                modified_data[0, 0, 1] = 1
            case (True, True):
                modified_data[0, 0, 0] = 1
                modified_data[0, 0, 1] = 0
            case _:
                pass
        return modified_data

Credits

List of colaborators:

  • Stefan-Dan Ciocirlan
  • Dumitrel Loghin

License

Distributed under the EUPL v1.2 License. See LICENSE.txt for more information.

Metadata

Release files for qlep 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for qlep 0.1.2
File Interpreter ABI Platform Actions
qlep-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for qlep-0.1.2-py2.py3-none-any.whl

Release files / qlep-0.1.2-py2.py3-none-any.whl

Download URL qlep-0.1.2-py2.py3-none-any.whl
Size 65.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
749300dd6ba2c963f2bad3af5f8abd61030e884908709108ffc585afee058821
BLAKE2b-256 checksum
How to use checksums
e5f1042a49eb7afb2f92b5d5ce2e508b9b5b7aa63838ce390dcbdbbada4ac300
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for qlep 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page