def start(self):
        super().start()
        
        # connect and connect quantum fibres
        self.MyQfiber=QuantumFibre("QFibre_A->B", length=self.fiberLenth)
        
        # create classical fibre
        self.MyCfiber=DirectConnection("CFibreConn_A->B",
            ClassicalFibre("CFibre_A->B", length=self.fiberLenth))
        
        self.node_A.connect_to(self.node_B, self.MyQfiber,
            local_port_name="portQA", remote_port_name="portQB")
        
        self.node_A.connect_to(self.node_B, self.MyCfiber,
            local_port_name="portCA", remote_port_name="portCB")
        


        #set callback functions===================================================
        self.node_B.ports["portQB"].bind_input_handler(self.QT_Bob_rec_Alice_measure)
        self.node_B.ports["portCB"].bind_input_handler(self.QT_Bob_dup)
        
        
        # Alice starts======================================================
        self.QT_Alice_EPRGen_sendQubits()
예제 #2
0
    def start(self):
        super().start()

        # connect and connect quantum fibres
        self.MyQfiber = QuantumFibre("QFibre_A->B", length=self.fiberLenth)

        # create classical fibre
        self.MyCfiber = DirectConnection(
            "CFibreConn_B->A",
            ClassicalFibre("CFibre_B->A", length=self.fiberLenth))
        self.MyCfiber2 = DirectConnection(
            "CFibreConn_A->B",
            ClassicalFibre("CFibre_A->B", length=self.fiberLenth))

        self.node_A.connect_to(self.node_B,
                               self.MyQfiber,
                               local_port_name="portQA",
                               remote_port_name="portQB")

        self.node_B.connect_to(self.node_A,
                               self.MyCfiber,
                               local_port_name="portCB_1",
                               remote_port_name="portCA_1")

        self.node_A.connect_to(self.node_B,
                               self.MyCfiber2,
                               local_port_name="portCA_2",
                               remote_port_name="portCB_2")

        #set callback functions===================================================
        self.node_B.ports["portQB"].bind_input_handler(self.E91_B_randMeas)
        self.node_A.ports["portCA_1"].bind_input_handler(
            self.E91_A_compare_keyGen)
        self.node_B.ports["portCB_2"].bind_input_handler(
            self.E91_B_compare_keyGen)

        # Alice starts======================================================
        self.E91_A_sendHalf_EPR()
예제 #3
0
    def start(self):
        super().start()

        # connect and connect quantum fibres
        self.MyQfiber = QuantumFibre("QFibre_A->B",
                                     length=self.fiberLenth,
                                     loss_model=FibreLossModel(
                                         p_loss_length=self.fibre_loss_length,
                                         p_loss_init=self.fibre_loss_init),
                                     depolar_rate=0)

        # create classical fibre
        self.MyCfiber = DirectConnection(
            "CFibreConn_A->B",
            ClassicalFibre("CFibre_A->B", length=self.fiberLenth),
            ClassicalFibre("CFibre_B->A", length=self.fiberLenth))

        self.node_A.connect_to(self.node_B,
                               self.MyQfiber,
                               local_port_name="portQA",
                               remote_port_name="portQB")

        self.node_B.connect_to(self.node_A,
                               self.MyCfiber,
                               local_port_name="portCB",
                               remote_port_name="portCA")

        #set callback functions===================================================
        self.node_B.ports["portQB"].bind_input_handler(
            self.BB84_Bob_measure_send)
        self.node_A.ports["portCA"].bind_input_handler(
            self.BB84_Alice_measure_send_keygen)
        self.node_B.ports["portCB"].bind_input_handler(self.BB84_Bob_keygen)

        # Alice starts======================================================
        self.BB84_Alice_sendQubits()
예제 #4
0
def run_E91_sim(runtimes=1,
                num_bits=20,
                fibre_len=10**-9,
                noise_model=None,
                loss_init=0,
                loss_len=0):

    MyE91List_A = []  # local protocol list A
    MyE91List_B = []  # local protocol list B

    for i in range(runtimes):

        ns.sim_reset()

        # nodes====================================================================

        nodeA = Node("Alice", port_names=["portQA_1", "portCA_1", "portCA_2"])
        nodeB = Node("Bob", port_names=["portQB_1", "portCB_1", "portCB_2"])

        # processors====================================================================
        noise_model = None
        Alice_processor = sendableQProcessor(
            "processor_A",
            num_positions=100,
            mem_noise_models=None,
            phys_instructions=[
                PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X, duration=1, parallel=True)
            ])

        Bob_processor = sendableQProcessor(
            "processor_B",
            num_positions=100,
            mem_noise_models=None,
            phys_instructions=[
                PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X, duration=1, parallel=True)
            ])

        # fibres=======================================================================

        MyQfiber = QuantumFibre("QFibre_A->B",
                                length=fibre_len,
                                quantum_loss_model=None,
                                p_loss_init=loss_init,
                                p_loss_length=loss_len)
        nodeA.connect_to(nodeB,
                         MyQfiber,
                         local_port_name=nodeA.ports["portQA_1"].name,
                         remote_port_name=nodeB.ports["portQB_1"].name)

        MyCfiber = DirectConnection(
            "CFibreConn_B->A", ClassicalFibre("CFibre_B->A", length=fibre_len))
        MyCfiber2 = DirectConnection(
            "CFibreConn_A->B", ClassicalFibre("CFibre_A->B", length=fibre_len))

        nodeB.connect_to(nodeA,
                         MyCfiber,
                         local_port_name="portCB_1",
                         remote_port_name="portCA_1")
        nodeA.connect_to(nodeB,
                         MyCfiber2,
                         local_port_name="portCA_2",
                         remote_port_name="portCB_2")

        Alice_protocol = AliceProtocol(nodeA, Alice_processor, num_bits)
        Bob_protocol = BobProtocol(nodeB, Bob_processor, num_bits)
        Alice_protocol.start()
        Bob_protocol.start()
        #ns.logger.setLevel(1)
        stats = ns.sim_run()

        MyE91List_A.append(Alice_protocol.key)
        MyE91List_B.append(Bob_protocol.key)

    return MyE91List_A, MyE91List_B
예제 #5
0
def run_UBQC_sim(runtimes=1,
                 num_bits=20,
                 fibre_len=10**-9,
                 noise_model=None,
                 loss_init=0,
                 loss_len=0):

    ns.sim_reset()
    # nodes====================================================================

    nodeA = Node("Alice", port_names=["portQA_1", "portCA_1", "portCA_2"])
    nodeB = Node("Bob", port_names=["portQB_1", "portCB_1", "portCB_2"])

    # processors===============================================================

    Alice_processor = sendableQProcessor(
        "processor_A",
        num_positions=5,
        mem_noise_models=None,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_Z, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_CNOT,
                                duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True),
            PhysicalInstruction(INSTR_MEASURE_X, duration=1, parallel=True)
        ])

    Bob_processor = sendableQProcessor(
        "processor_B",
        num_positions=100,
        mem_noise_models=None,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_Z, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_CNOT,
                                duration=1,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True),
            PhysicalInstruction(INSTR_MEASURE_X, duration=1, parallel=True)
        ])

    # fibres==================================================================

    MyQfiber = QuantumFibre("QFibre_A->B",
                            length=fibre_len,
                            quantum_loss_model=None,
                            p_loss_init=loss_init,
                            p_loss_length=loss_len)
    nodeA.connect_to(nodeB,
                     MyQfiber,
                     local_port_name=nodeA.ports["portQA_1"].name,
                     remote_port_name=nodeB.ports["portQB_1"].name)

    MyCfiber = DirectConnection(
        "CFibreConn_B->A", ClassicalFibre("CFibre_B->A", length=fibre_len))
    MyCfiber2 = DirectConnection(
        "CFibreConn_A->B", ClassicalFibre("CFibre_A->B", length=fibre_len))

    nodeB.connect_to(nodeA,
                     MyCfiber,
                     local_port_name="portCB_1",
                     remote_port_name="portCA_1")
    nodeA.connect_to(nodeB,
                     MyCfiber2,
                     local_port_name="portCA_2",
                     remote_port_name="portCB_2")

    Alice = ClientProtocol(nodeA, Alice_processor, 2, 2)
    BOb = ServerProtocol(nodeB, Bob_processor, 2, 2)
    Alice.start()
    BOb.start()
    #ns.logger.setLevel(1)
    ns.sim_run()
예제 #6
0
    def __init__(self, nodeList, processorList, fibreLen, initNodeID,
                 targetNodeID, lossInd, lossLen):
        self.nodeList = nodeList
        self.processorList = processorList

        self.initNodeID = initNodeID
        self.targetNodeID = targetNodeID

        self.num_node = len(nodeList)
        self.fibre_len = fibreLen

        # A rand
        self.r = randint(0, 1)
        self.b = randint(0, 1)
        # B rand
        self.c = randint(0, 1)
        self.s = randint(0, 1)

        self.keyI = None
        self.keyT = None

        self.TimeF = 0.0  #time recorded when started
        self.TimeD = 0.0  #time cost for this bit to form

        #self.QfibreList=[]
        #self.CfibreList=[]

        # if not forwarded, connect them with Q,C fibres
        if self.nodeList[self.initNodeID].get_conn_port(self.initNodeID + 1,
                                                        label='Q') == None:

            #print("create fibres")
            # create quantum fibre and connect
            self.QfibreList = [
                QuantumFibre(name="QF" + str(i),
                             length=self.fibre_len,
                             p_loss_init=lossInd,
                             p_loss_length=0.25)
                for i in range(self.num_node - 1)
            ]

            for i in range(self.num_node - 1):
                self.nodeList[i].connect_to(self.nodeList[i + 1],
                                            self.QfibreList[i],
                                            label='Q')

            # create classical fibre and connect
            self.CfibreList = [
                DirectConnection(
                    "CF" + str(i),
                    ClassicalFibre(name="CFibre_forth", length=self.fibre_len),
                    ClassicalFibre(name="CFibre_back", length=self.fibre_len))
                for i in range(self.num_node - 1)
            ]
            for i in range(self.num_node - 1):
                self.nodeList[i].connect_to(self.nodeList[i + 1],
                                            self.CfibreList[i],
                                            label='C')

            # do forward according to position

            # No need to forward if I next to T
            if self.initNodeID + 1 != self.targetNodeID:
                self.ForwardSetting(self.initNodeID + 1, self.targetNodeID)
                self.ForwardSettingBK(self.initNodeID, self.targetNodeID - 1)

            # case I !=O nor next to O
            if self.initNodeID >= 1:
                self.ForwardSetting(1, self.initNodeID)
                self.ForwardSettingBK(0, self.initNodeID - 1)

            # case T !=D nor next to D
            if self.targetNodeID < len(self.nodeList) - 2:
                self.ForwardSetting(self.targetNodeID + 1,
                                    self.nodeList[-1].ID)
                self.ForwardSettingBK(self.targetNodeID,
                                      self.nodeList[-1].ID - 1)

        super().__init__()
예제 #7
0
def run_E91_sim(runtimes=1, num_bits=20, fibre_len=10**-9, noise_model=None):

    MyE91List_A = []  # local protocol list A
    MyE91List_B = []  # local protocol list B

    for i in range(runtimes):

        ns.sim_reset()

        # Hardware configuration
        Alice_processor = sendableQProcessor(
            "processor_A",
            num_positions=100,
            mem_noise_models=None,
            phys_instructions=[
                PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True)
            ],
            topologies=[None, None, None, None, None, None])

        #mem_noise_models=[DepolarNoiseModel(0)] * 100
        Bob_processor = sendableQProcessor(
            "processor_B",
            num_positions=100,
            mem_noise_models=None,
            phys_instructions=[
                PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=1,
                                    q_noise_model=noise_model),
                PhysicalInstruction(INSTR_MEASURE, duration=1, parallel=True)
            ],
            topologies=[None, None, None, None, None, None])

        node_A = Node("A",
                      ID=0,
                      port_names=["portQA_1", "portCA_1", "portCA_2"])
        node_B = Node("B",
                      ID=1,
                      port_names=["portQB_1", "portCB_1", "portCB_2"])

        # connection
        MyQfiber = QuantumFibre("QFibre_A->B",
                                length=fibre_len,
                                quantum_loss_model=None)
        # default value:
        # p_loss_init=0.2, p_loss_length=0.25,depolar_rate=0, c=200000, models=None

        MyCfiber = DirectConnection(
            "CFibreConn_B->A", ClassicalFibre("CFibre_B->A", length=fibre_len))

        MyCfiber2 = DirectConnection(
            "CFibreConn_A->B", ClassicalFibre("CFibre_A->B", length=fibre_len))

        node_A.connect_to(node_B,
                          MyQfiber,
                          local_port_name=node_A.ports["portQA_1"].name,
                          remote_port_name=node_B.ports["portQB_1"].name)

        node_B.connect_to(node_A,
                          MyCfiber,
                          local_port_name="portCB_1",
                          remote_port_name="portCA_1")

        node_A.connect_to(node_B,
                          MyCfiber2,
                          local_port_name="portCA_2",
                          remote_port_name="portCB_2")

        Alice = E91_A(node=node_A,
                      processor=Alice_processor,
                      num_bits=num_bits,
                      portNameQ1="portQA_1",
                      portNameC1="portCA_1",
                      portNameC2="portCA_2")
        Bob = E91_B(node=node_B,
                    processor=Bob_processor,
                    num_bits=num_bits,
                    portNameQ1="portQB_1",
                    portNameC1="portCB_1",
                    portNameC2="portCB_2")

        for i in Alice.A_prepare_qubits():
            pass

        ns.sim_run()

        MyE91List_A.append(Alice.key)
        MyE91List_B.append(Bob.key)

    return MyE91List_A, MyE91List_B