Esempio n. 1
0
 def __init__(self,
              num_bits=8,
              fibre_len=10**-6,
              fibre_loss_init=0.2,
              fibre_loss_length=0.25):  #,fibreLossModel=default
     super().__init__()
     self.node_A = Node("A", ID=0, port_names=["portQA", "portCA"])
     self.node_B = Node("B", ID=1, port_names=["portQB", "portCB"])
     self.MyQfiber = None
     self.MyCfiber = None
     self.num_bits = num_bits
     self.stateList = None
     self.res_measure = None
     self.key_A = []
     self.key_B = []
     self.fiberLenth = fibre_len
     self.fibre_loss_init = fibre_loss_init
     self.fibre_loss_length = fibre_loss_length
     self.start()
Esempio n. 2
0
    def __init__(self, num_bits=8, fibre_len=10**-6):
        super().__init__()
        self.node_A = Node("A",
                           ID=0,
                           port_names=["portQA", "portCA_1", "portCA_2"])
        self.node_B = Node("B",
                           ID=1,
                           port_names=["portQB", "portCB_1", "portCB_2"])
        self.MyQfiber = None
        self.MyCfiber = None
        self.num_bits = num_bits
        self.qListA = []
        self.qListB = []
        self.basisList_A = []
        self.basisList_B = []
        self.res_measure_A = []
        self.res_measure_B = []
        self.key_A = []
        self.key_B = []

        self.fiberLenth = fibre_len
        self.start()
Esempio n. 3
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
Esempio n. 4
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()
Esempio n. 5
0
def run_E91_sim(runtimes=1,num_bits=20,fibre_len=10**-9,memNoiseMmodel=None,processorNoiseModel=None
               ,loss_init=0,loss_len=0,QChV=2.083*10**-4,CChV=2.083*10**-4):
    
    MyE91List_A=[]  # local protocol list A
    MyE91List_B=[]  # local protocol list B
    MyKeyRateList=[]
    
    A_originBasisList=[]
    B_measureBasisList=[]
    
    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=QuantumProcessor("processor_A", num_positions=10**5,
            mem_noise_models=memNoiseMmodel, phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_Z, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_H, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_CNOT,duration=10,q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_MEASURE, duration=10,q_noise_model=processorNoiseModel, parallel=True),
            PhysicalInstruction(INSTR_MEASURE_X, duration=10,q_noise_model=processorNoiseModel, parallel=True)])


        Bob_processor=QuantumProcessor("processor_B", num_positions=10**5,
            mem_noise_models=memNoiseMmodel, phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_Z, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_H, duration=1, q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_CNOT,duration=10,q_noise_model=processorNoiseModel),
            PhysicalInstruction(INSTR_MEASURE, duration=10,q_noise_model=processorNoiseModel, parallel=True),
            PhysicalInstruction(INSTR_MEASURE_X, duration=10,q_noise_model=processorNoiseModel, parallel=True)])


        # channels==================================================================
        
        MyQChannel=QuantumChannel("QChannel_A->B",delay=10
            ,length=fibre_len
            ,models={"quantum_loss_model":
            FibreLossModel(p_loss_init=loss_init,p_loss_length=loss_len, rng=None),
            "delay_model": FibreDelayModel(c=QChV)})
        
        nodeA.connect_to(nodeB, MyQChannel,
            local_port_name =nodeA.ports["portQA_1"].name,
            remote_port_name=nodeB.ports["portQB_1"].name)
        

        MyCChannel = ClassicalChannel("CChannel_B->A",delay=0
            ,length=fibre_len)
        MyCChannel2= ClassicalChannel("CChannel_A->B",delay=0
            ,length=fibre_len)
        

        nodeB.connect_to(nodeA, MyCChannel,
                            local_port_name="portCB_1", remote_port_name="portCA_1")
        nodeA.connect_to(nodeB, MyCChannel2,
                            local_port_name="portCA_2", remote_port_name="portCB_2")

        
        startTime=ns.sim_time()
        #print("startTime:",startTime)
        
        Alice_protocol = AliceProtocol(nodeA,Alice_processor,num_bits)
        Bob_protocol = BobProtocol(nodeB,Bob_processor,num_bits)
        Bob_protocol.start()
        Alice_protocol.start()
        #ns.logger.setLevel(1)
        stats = ns.sim_run()
        
        '''
        endTime=Bob_protocol.endTime
        #print("endTime:",endTime)
        MyE91List_A.append(Alice_protocol.key)
        MyE91List_B.append(Bob_protocol.key)
        #simple key length calibration
        s = SequenceMatcher(None, Alice_protocol.key, Bob_protocol.key)# unmatched rate
        MyKeyRateList.append((len(Bob_protocol.key)*(1-s.ratio()))*10**9/(endTime-startTime)) #second
        '''
        
        MyE91List_A.append(Alice_protocol.key)
        MyE91List_B.append(Bob_protocol.key)
        
        A_originBasisList.append(Alice_protocol.basisList)
        B_measureBasisList.append(Bob_protocol.basisList)
        
        
    #return MyE91List_A, MyE91List_B, MyKeyRateList

    return MyE91List_A, MyE91List_B, A_originBasisList, B_measureBasisList
Esempio n. 6
0
def run_UBQC_sim(runtimes=1,
                 fibre_len=10**-9,
                 processorNoiseModel=None,
                 memNoiseMmodel=None,
                 loss_init=0.25,
                 loss_len=0.2,
                 QChV=3 * 10**2,
                 CChV=3 * 10**2):

    resList = []
    successCount = 0
    set_qstate_formalism(QFormalism.DM)

    for i in range(runtimes):

        ns.sim_reset()

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

        nodeServer = Node("Server",
                          port_names=["portQS_1", "portCS_1", "portCS_2"])
        nodeClient = Node("Client",
                          port_names=["portQC_1", "portCC_1", "portCC_2"])

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

        processorServer = QuantumProcessor(
            "processorServer",
            num_positions=10,
            mem_noise_models=memNoiseMmodel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_CZ,
                                    duration=10,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_MEASURE, duration=10, parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X,
                                    duration=10,
                                    parallel=True),
                PhysicalInstruction(INSTR_R22, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R45, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R67, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R90, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R112, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R135, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R157, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R180, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R202, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R225, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R247, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R270, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R292, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R315, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R337, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv22, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv45, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv67, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv90, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv112, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv135, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv157, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv180, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv202, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv225, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv247, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv270, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv292, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv315, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv337, duration=1, parallel=True),
                PhysicalInstruction(INSTR_SWAP, duration=1, parallel=True)
            ])

        processorClient = QuantumProcessor(
            "processorClient",
            num_positions=10,
            mem_noise_models=memNoiseMmodel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=10,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_MEASURE, duration=10, parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X,
                                    duration=10,
                                    parallel=True),
                PhysicalInstruction(INSTR_R22, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R45, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R67, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R90, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R112, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R135, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R157, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R180, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R202, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R225, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R247, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R270, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R292, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R315, duration=1, parallel=True),
                PhysicalInstruction(INSTR_R337, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv22, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv45, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv67, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv90, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv112, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv135, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv157, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv180, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv202, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv225, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv247, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv270, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv292, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv315, duration=1, parallel=True),
                PhysicalInstruction(INSTR_Rv337, duration=1, parallel=True)
            ])

        # channels==================================================================

        MyQChannel = QuantumChannel("QChannel_S->C",
                                    delay=0,
                                    length=fibre_len,
                                    models={
                                        "quantum_loss_model":
                                        FibreLossModel(p_loss_init=loss_init,
                                                       p_loss_length=loss_len,
                                                       rng=None),
                                        "delay_model":
                                        FibreDelayModel(c=QChV)
                                    })

        nodeServer.connect_to(
            nodeClient,
            MyQChannel,
            local_port_name=nodeServer.ports["portQS_1"].name,
            remote_port_name=nodeClient.ports["portQC_1"].name)

        MyCChannel = ClassicalChannel("CChannel_C->S",
                                      delay=0,
                                      length=fibre_len)
        MyCChannel2 = ClassicalChannel("CChannel_S->C",
                                       delay=0,
                                       length=fibre_len)

        nodeClient.connect_to(nodeServer,
                              MyCChannel,
                              local_port_name="portCC_1",
                              remote_port_name="portCS_1")
        nodeServer.connect_to(nodeClient,
                              MyCChannel2,
                              local_port_name="portCS_2",
                              remote_port_name="portCC_2")

        protocolServer = ProtocolServer(nodeServer, processorServer)
        protocolClient = ProtocolClient(nodeClient, processorClient, 1)
        protocolServer.start()
        protocolClient.start()
        #ns.logger.setLevel(1)
        stats = ns.sim_run()

        resList.append(protocolClient.verified)

    for i in resList:
        if i == True:
            successCount += 1

    return successCount / runtimes
Esempio n. 7
0
    def __init__(self,
                 num_bits=8,
                 fibre_len_AC=10**-6,
                 fibre_len_AB=10**-6,
                 fibre_len_BC=10**-6,
                 Money=1234,
                 depolar_rate=0,
                 time_independent=False,
                 Threshold=0.99,
                 C_delay=0):
        super().__init__()
        self.node_A = Node("A",
                           ID=0,
                           port_names=[
                               "portQ_A1", "portC_A1", "portC_A2", "portQ_A2",
                               "portC_A3"
                           ])
        self.node_B = Node("B",
                           ID=1,
                           port_names=[
                               "portQ_B1", "portC_B1", "portC_B2", "portQ_B2",
                               "portC_B3"
                           ])
        self.node_C = Node("C", ID=2, port_names=["portQ_C1", "portQ_C2"])

        self.C_Qmemory = QuantumMemory(
            "C_QMemory",
            num_bits,
            ID=0,
            memory_noise_models=DepolarNoiseModel(
                depolar_rate=depolar_rate, time_independent=time_independent)
        )  #normally time_independent is False unless using probability
        self.C_delay = C_delay

        self.MyQfiber_AC = None
        self.MyQfiber_AB = None
        self.MyQfiber_BC = None

        self.MyCfiber_AB = None
        self.MyCfiber_BA = None

        self.fiberLenth_AC = fibre_len_AC
        self.fiberLenth_AB = fibre_len_AB
        self.fiberLenth_BC = fibre_len_BC

        self.num_bits = num_bits
        self.A1ChequeBook = []
        self.A2ChequeBook = []
        self.BChequeBook = []

        self.A_saveUSN = []  #unique serial number stored in A
        self.B_saveUSN = []  #unique serial number stored in B

        self.key_BB84_A = []
        self.key_BB84_B = []

        self.Money = Money
        self.Threshold = Threshold  #Threshold of closeness about whether to accept this cheque
        self.chequeCloseness = 0
        self.Varify = False  # True = cheque accepted, False = cheque denied

        self.start()
Esempio n. 8
0
def run_QLine_sim(I,
                  T,
                  maxKeyLen=1,
                  fibreLen=10**-3,
                  memNoise=None,
                  noise_model=None,
                  lossInd=0.2,
                  lossLen=0.25):

    # Hardware configuration
    processorA = sendableQProcessor(
        "processor_A",
        num_positions=2,
        mem_noise_models=memNoise,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE,
                                duration=5,
                                q_noise_model=noise_model,
                                parallel=True)
        ])

    #mem_noise_models=[DepolarNoiseModel(0)] * 100
    processorB = sendableQProcessor(
        "processor_B",
        num_positions=2,
        mem_noise_models=memNoise,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE,
                                duration=5,
                                q_noise_model=noise_model,
                                parallel=True)
        ])

    processorC = sendableQProcessor(
        "processor_C",
        num_positions=2,
        mem_noise_models=memNoise,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE,
                                duration=5,
                                q_noise_model=noise_model,
                                parallel=True)
        ])

    processorD = sendableQProcessor(
        "processor_D",
        num_positions=2,
        mem_noise_models=memNoise,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE,
                                duration=5,
                                q_noise_model=noise_model,
                                parallel=True)
        ])

    processorE = sendableQProcessor(
        "processor_E",
        num_positions=2,
        mem_noise_models=memNoise,
        phys_instructions=[
            PhysicalInstruction(INSTR_INIT, duration=1, parallel=True),
            PhysicalInstruction(INSTR_X, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_H, duration=2,
                                q_noise_model=noise_model),
            PhysicalInstruction(INSTR_MEASURE,
                                duration=5,
                                q_noise_model=noise_model,
                                parallel=True)
        ])

    node_A = Node("A", ID=0)
    node_B = Node("B", ID=1)
    node_C = Node("C", ID=2)
    node_D = Node("D", ID=3)
    #node_E = Node("E",ID=4)

    nodeList = [node_A, node_B, node_C, node_D]
    processorList = [processorA, processorB, processorC, processorD]

    keyListI = []  # key for I, length unknown
    keyListT = []  # key for T, length unknown
    totalTime = 0.0
    errorTimes = 0

    for i in range(maxKeyLen):
        ns.sim_reset()
        myQLine = QLine(nodeList=nodeList,
                        processorList=processorList,
                        fibreLen=fibreLen,
                        initNodeID=I,
                        targetNodeID=T,
                        lossInd=lossInd,
                        lossLen=lossLen)
        myQLine.start()
        ns.sim_run()

        if myQLine.keyI == myQLine.keyT and myQLine.keyI != None:
            keyListI.append(myQLine.keyI)
            keyListT.append(myQLine.keyT)
            totalTime += myQLine.TimeD

        elif myQLine.keyI != myQLine.keyT:
            errorTimes += 1
            #print(myQLine.keyI)
            #print(myQLine.keyT)

    return keyListI, keyListT, totalTime  #,errorTimes
Esempio n. 9
0
def run_QToken_sim(runTimes=1,
                   num_bits=100,
                   fibre_len=0,
                   waitTime=1,
                   processNoiseModel=None,
                   memNoiseModel=None,
                   loss_init=0,
                   loss_len=0,
                   threshold=0.854,
                   fibreLoss_init=0.2,
                   fibreLoss_len=0.25,
                   QChDelay=1,
                   CChDelay=0):

    resList = []

    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 = QuantumProcessor(
            "processor_A",
            num_positions=3 * 10**3,
            mem_noise_models=memNoiseModel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=10,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_MEASURE,
                                    duration=10,
                                    q_noise_model=processNoiseModel,
                                    parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X,
                                    duration=10,
                                    q_noise_model=processNoiseModel,
                                    parallel=True)
            ])

        Bob_processor = QuantumProcessor(
            "processor_B",
            num_positions=3 * 10**3,
            mem_noise_models=memNoiseModel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=10,
                                    q_noise_model=processNoiseModel),
                PhysicalInstruction(INSTR_MEASURE,
                                    duration=10,
                                    q_noise_model=processNoiseModel,
                                    parallel=True),
                PhysicalInstruction(INSTR_MEASURE_X,
                                    duration=10,
                                    q_noise_model=processNoiseModel,
                                    parallel=True)
            ])

        # channels==================================================================

        MyQChannel = QuantumChannel("QChannel_B->A",
                                    delay=QChDelay,
                                    length=fibre_len,
                                    models={
                                        "myFibreLossModel":
                                        FibreLossModel(
                                            p_loss_init=fibreLoss_init,
                                            p_loss_length=fibreLoss_len,
                                            rng=None)
                                    })

        nodeB.connect_to(nodeA,
                         MyQChannel,
                         local_port_name=nodeB.ports["portQB_1"].name,
                         remote_port_name=nodeA.ports["portQA_1"].name)

        MyCChannel = ClassicalChannel("CChannel_A->B",
                                      delay=CChDelay,
                                      length=fibre_len)
        MyCChannel2 = ClassicalChannel("CChannel_B->A",
                                       delay=CChDelay,
                                       length=fibre_len)

        nodeA.connect_to(nodeB,
                         MyCChannel,
                         local_port_name="portCA_1",
                         remote_port_name="portCB_1")
        nodeB.connect_to(nodeA,
                         MyCChannel2,
                         local_port_name="portCB_2",
                         remote_port_name="portCA_2")

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

        resList.append(Bob_protocol.successfulRate)
        #print("Bob_protocol.successfulRate:",Bob_protocol.successfulRate)

    return sum(resList) / len(resList)
def run_AT_sim(numNodes=4,fibre_len=10**-9,processorNoiseModel=None,memNoiseMmodel=None,loss_init=0,loss_len=0
              ,QChV=3*10**-4):
    
    # initialize
    ns.sim_reset()
    
    sideProcessorList=[]
    sideNodeList=[]
    centerPortList=[]
    channelList=[]
    
    senderID=randint(0,numNodes-1)
    receiverID=randint(0,numNodes-1)
    while receiverID==senderID:
        receiverID=randint(0,numNodes-1)
    
    
    # build star network hardware components
    ## create side components
    for i in range(numNodes):
        ### processors================================================================
        sideProcessorList.append(createProcessorAT(name="ProcessorSide_"+str(i)))
        
        ### nodes=====================================================================
        sideNodeList.append(Node("node_"+str(i), port_names=["portQside"]))
        
        ### channels==================================================================
        channelList.append(QuantumChannel("QChannel_Center->Side_"+str(i),delay=10,length=fibre_len
            ,models={"quantum_loss_model":
            FibreLossModel(p_loss_init=loss_init,p_loss_length=loss_len, rng=None),
            "delay_model": FibreDelayModel(c=QChV)}))
        
        ### record port list for center node
        centerPortList.append("PortQCenter_"+str(i))

        
        
    ## create center component
    CenterNode=Node("CenterNode", port_names=centerPortList)
    CenterProcessor=createProcessorAT(name="ProcessorCenter")
    
    ## connect==================================================================
    for i in range(numNodes):    
        CenterNode.connect_to(sideNodeList[i], channelList[i],
            local_port_name =CenterNode.ports["PortQCenter_"+str(i)].name,
            remote_port_name=sideNodeList[i].ports["portQside"].name)
    
    
    # create protocol object
    myProtocol_center = AT_Wstate_center(CenterNode,CenterProcessor,numNodes,portQlist=centerPortList)
    myProtocol_sideList=[]
    ## create side protocol
    for i in range(numNodes):
        if i==senderID:
            # create sender
            myProtocol_sideList.append(AT_Wstate_side(sideNodeList[i],sideProcessorList[i],  sender=True))
        elif i==receiverID:
            # create receiver
            myProtocol_sideList.append(AT_Wstate_side(sideNodeList[i],sideProcessorList[i],receiver=True))
        else:
            # create normal side node
            myProtocol_sideList.append(AT_Wstate_side(sideNodeList[i],sideProcessorList[i]))
        
    
    
    for sideProtocols in myProtocol_sideList:
        sideProtocols.start()
        
    myProtocol_center.start()
    
    
    #ns.logger.setLevel(1)
    stats = ns.sim_run()
Esempio n. 11
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
def run_Teleport_sim(runtimes=1,
                     fibre_len=10**-9,
                     memNoiseMmodel=None,
                     processorNoiseModel=None,
                     loss_init=0,
                     loss_len=0,
                     QChV=3 * 10**-4,
                     CChV=3 * 10**-4):

    for i in range(runtimes):

        ns.sim_reset()

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

        nodeSender = Node("SenderNode", port_names=["portC_Sender"])
        nodeReceiver = Node("ReceiverNode", port_names=["portC_Receiver"])

        # processors===============================================================
        processorSender = QuantumProcessor(
            "processorSender",
            num_positions=10,
            mem_noise_models=memNoiseMmodel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=10,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_MEASURE,
                                    duration=10,
                                    q_noise_model=processorNoiseModel,
                                    parallel=False)
            ])

        processorReceiver = QuantumProcessor(
            "processorReceiver",
            num_positions=10,
            mem_noise_models=memNoiseMmodel,
            phys_instructions=[
                PhysicalInstruction(INSTR_X,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_Z,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_H,
                                    duration=1,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_CNOT,
                                    duration=10,
                                    q_noise_model=processorNoiseModel),
                PhysicalInstruction(INSTR_MEASURE,
                                    duration=10,
                                    q_noise_model=processorNoiseModel,
                                    parallel=False)
            ])

        # channels==================================================================

        MyCChannel = ClassicalChannel("CChannel_S->R",
                                      delay=0,
                                      length=fibre_len)

        nodeSender.connect_to(nodeReceiver,
                              MyCChannel,
                              local_port_name="portC_Sender",
                              remote_port_name="portC_Receiver")

        # make an EPR pair and origin state
        oriQubit, epr1, epr2 = create_qubits(3)
        operate(epr1, H)
        operate([epr1, epr2], CNOT)

        # make oriQubit
        operate(oriQubit, H)

        myQT_Sender = QuantumTeleportationSender(node=nodeSender,
                                                 processor=processorSender,
                                                 SendQubit=oriQubit,
                                                 EPR_1=epr1)
        myQT_Receiver = QuantumTeleportationReceiver(
            node=nodeReceiver, processor=processorReceiver, EPR_2=epr2)

        myQT_Receiver.start()
        myQT_Sender.start()
        #ns.logger.setLevel(1)
        stats = ns.sim_run()

    return 0