Пример #1
0
    def __init__(self,
                 node,
                 processor,
                 num_bits,
                 threshold=0.854,
                 port_names=["portQB_1", "portCB_1", "portCB_2"]):
        super().__init__()
        self.num_bits = num_bits
        self.node = node
        self.processor = processor
        self.portNameQ1 = port_names[0]
        self.portNameC1 = port_names[1]
        self.portNameC2 = port_names[2]
        # init value assume that all qubits are lost
        self.sourceQList = []
        self.basisInxList = [randint(0, 7) for i in range(self.num_bits)]
        self.randMeas = randint(0, 1)  #0:Z basis(standard)   1:X basis(H)
        self.locRes = None
        self.threshold = threshold
        self.successfulRate = None

        #generat qubits from source
        self.B_Source = QSource(
            "Bank_source", status=SourceStatus.EXTERNAL)  # enable frequency
        self.B_Source.ports["qout0"].bind_output_handler(
            self.storeSourceOutput)
Пример #2
0
    def _create_noiseless_processor(with_ent_source=False):
        """Factory to create a quantum processor for each end node.

        Has three memory positions and the physical instructions necessary
        for teleportation.
        """
        physical_instructions = [
            PhysicalInstruction(instr.INSTR_INIT, duration=3, parallel=True),
            PhysicalInstruction(instr.INSTR_H, duration=1, parallel=True),
            PhysicalInstruction(instr.INSTR_X, duration=1, parallel=True),
            PhysicalInstruction(instr.INSTR_Z, duration=1, parallel=True),
            PhysicalInstruction(instr.INSTR_CNOT, duration=5, parallel=True),
            PhysicalInstruction(instr.INSTR_MEASURE,
                                duration=7,
                                parallel=False),
            PhysicalInstruction(instr.INSTR_MEASURE_X,
                                duration=10,
                                parallel=False)
        ]
        processor = QuantumProcessor("quantum_processor",
                                     num_positions=100,
                                     phys_instructions=physical_instructions)

        if with_ent_source:
            ent_source = QSource('ent_source',
                                 StateSampler([ks.b00]),
                                 num_ports=2,
                                 status=SourceStatus.OFF)
            processor.add_subcomponent(ent_source, name='ent_source')

        return processor
Пример #3
0
    def run(self):
        print("client on")
        clientSource = QSource(
            "client_source", status=SourceStatus.EXTERNAL)  # enable frequency
        clientSource.ports["qout0"].bind_output_handler(self.storeSourceOutput)

        #set clock
        clock = Clock("clock", frequency=1e9, max_ticks=self.raw * self.column)
        clock.ports["cout"].connect(clientSource.ports["trigger"])
        clock.start()
 def __init__(self,node,processor,numNode,portQlist): 
     super().__init__()
     self.numNode=numNode
     self.node=node
     self.processor=processor
     self.portQlist=portQlist
     
     self.sourceQList=[]
     
     
     self.C_Source = QSource("center_source"
         ,status=SourceStatus.EXTERNAL) # enable frequency
     self.C_Source.ports["qout0"].bind_output_handler(self.storeSourceOutput)
Пример #5
0
 def __init__(self,node,processor,num_bits,
             port_names=["portQA_1","portCA_1","portCA_2"]):
     super().__init__()
     self.num_bits=num_bits
     self.node=node
     self.processor=processor
     self.portNameQ1=port_names[0]
     self.portNameC1=port_names[1]
     self.portNameC2=port_names[2]
     self.EPRList=None
     self.basisList=Random_basis_gen_75(self.num_bits)
     self.loc_mesRes=[]
     self.key=None
     self.sourceQList=[]
     
     
     
     #generat qubits from source
     self.A_Source = QSource("Alice_source"
         ,status=SourceStatus.EXTERNAL) # enable frequency
     self.A_Source.ports["qout0"].bind_output_handler(self.storeSourceOutput)
Пример #6
0
    def __init__(self,
                 node,
                 processor,
                 port_names=["portQS_1", "portCS_1", "portCS_2"],
                 realRound=5):
        super().__init__()
        self.node = node
        self.processor = processor
        self.portNameQ1 = port_names[0]
        self.portNameC1 = port_names[1]
        self.portNameC2 = port_names[2]
        self.sourceQList = []
        self.port_output = []
        self.realRound = realRound

        self.S_Source = QSource("S_source")
        self.S_Source.ports["qout0"].bind_output_handler(
            self.S_put_prepareEPR, 4)
        self.S_Source.status = SourceStatus.EXTERNAL

        self.C_delta1 = None
        self.C_delta2 = None
        self.m1 = None
        self.m2 = None
def setup_network(source_attempts, memory_depth, **kwargs):

    # retrieve setup parameters from sim_params, substituting defaults when required
    source_frequency = kwargs.get('source_frequency', 100e6)
    channel_A_length = kwargs.get('channel_A_length', 1)
    channel_A_static_loss = kwargs.get('channel_A_static_loss', 0)
    channel_A_loss = kwargs.get('channel_A_loss', 0)
    channel_A_speed = kwargs.get('channel_A_speed', 3e5)
    channel_B_length = kwargs.get('channel_B_length', 1)
    channel_B_static_loss = kwargs.get('channel_B_static_loss', 0)
    channel_B_loss = kwargs.get('channel_B_loss', 0)
    channel_B_speed = kwargs.get('channel_B_speed', 3e5)
    memory_T1 = kwargs.get('memory_T1', 1.0e8)
    memory_T2 = kwargs.get('memory_T2', 1.0e4)
    physical_instructions = kwargs.get('physical_instructions', None)

    # find each channel's propagation time [ns]:
    propagation_time_A = (channel_A_length / channel_A_speed) * 1e9
    propagation_time_B = (channel_B_length / channel_B_speed) * 1e9

    if propagation_time_A < propagation_time_B:
        clock_A_delay = propagation_time_B - propagation_time_A
        clock_B_delay = 0
        clock_R_delay = propagation_time_B
    elif propagation_time_A > propagation_time_B:
        clock_A_delay = 0
        clock_B_delay = propagation_time_A - propagation_time_B
        clock_R_delay = propagation_time_A
    else:
        clock_A_delay = 0
        clock_B_delay = 0
        clock_R_delay = propagation_time_A  # arbitrary choice since matched time

    source_period = 1e9 / source_frequency  # source period [ns]
    clock_model = {
        'timing_model':
        GaussianDelayModel(delay_mean=source_period, delay_std=0.00)
    }

    channel_A_model = {
        'quantum_loss_model':
        FibreLossModel(loss_init=channel_A_static_loss,
                       p_loss_length=channel_A_loss),
        'delay_model':
        FibreDelayModel(c=channel_A_speed)
    }  # define channel_A_model according to passed sim_params

    channel_B_model = {
        'quantum_loss_model':
        FibreLossModel(loss_init=channel_B_static_loss,
                       p_loss_length=channel_B_loss),
        'delay_model':
        FibreDelayModel(c=channel_B_speed)
    }  # define channel_B_model according to passed sim_params

    memory_model = T1T2NoiseModel(memory_T1, memory_T2)

    network = Network('Entanglement_swap')
    node_a, node_b, node_r = network.add_nodes(['node_A', 'node_B', 'node_R'])

    state_sampler = StateSampler(
        qs_reprs=[ks.s11], probabilities=[1.0], formalism=QFormalism.DM
    )  # define desired states to be generated by source

    # Setup end node A:
    source_a = QSource(
        name='QSource_node_A',
        state_sampler=state_sampler,
        num_ports=2,
        status=SourceStatus.EXTERNAL,
        output_meta={
            'qm_replace': True,
            'qm_positions': [0]
        }
    )  # allow incoming qubits to replace anything in slot 0, recall we use the default slots only to sort into slots with QProgram
    clock_a = Clock(
        name='Clock_node_A',
        models=clock_model,
        start_delay=clock_A_delay,
        max_ticks=source_attempts
    )  # "max_ticks" will timeout the program after desired number of connection attempts
    node_a.add_subcomponent(source_a)
    node_a.add_subcomponent(clock_a)

    # Setup end node B:
    source_b = QSource(
        name='QSource_node_B',
        state_sampler=state_sampler,
        num_ports=2,
        status=SourceStatus.EXTERNAL,
        output_meta={
            'qm_replace': True,
            'qm_positions': [1]
        }
    )  # allow incoming qubits to replace anything in slot 1, recall we use the default slots only to sort into slots with QProgram
    clock_b = Clock(
        name='Clock_node_B',
        models=clock_model,
        start_delay=clock_B_delay,
        max_ticks=source_attempts
    )  # "max_ticks" will timeout the program after desired number of connection attempts
    node_b.add_subcomponent(source_b)
    node_b.add_subcomponent(clock_b)

    # Setup midpoint repeater node R:
    if memory_depth == 0:  # special case, initialize non-physical processor to handle measurement on simultaneous input
        total_positions = 2
        qprocessor_r = QuantumProcessor(name='QProcessor_R',
                                        num_positions=total_positions,
                                        fallback_to_nonphysical=True,
                                        phys_instructions=None,
                                        memory_noise_models=None)
    else:
        total_positions = memory_depth * 2 + 2
        qprocessor_r = QuantumProcessor(
            name='QProcessor_R',
            num_positions=total_positions,
            fallback_to_nonphysical=True,
            phys_instructions=physical_instructions,
            memory_noise_models=memory_model)

    if memory_depth != 0:  # initialization of memories
        for position in qprocessor_r.mem_positions[2:memory_depth + 2]:
            memory_default, = ns.qubits.create_qubits(1, no_state=True)
            ns.qubits.assign_qstate([memory_default],
                                    ns.h0,
                                    formalism=QFormalism.DM)
            position.add_property(
                'origin', value=node_a.name
            )  # first half of qmemory is allocated for qubits from node_A
            position.set_qubit(memory_default)  # initialize to default state
            position.in_use = False
            position.add_property(name='status', value="IDLE")
        for position in qprocessor_r.mem_positions[memory_depth + 2:]:
            memory_default, = ns.qubits.create_qubits(1, no_state=True)
            ns.qubits.assign_qstate([memory_default],
                                    ns.h0,
                                    formalism=QFormalism.DM)
            position.add_property(
                'origin', value=node_b.name
            )  # second half of qmemory is allocated for qubits from node_B
            position.set_qubit(memory_default)  # initialize to default state
            position.in_use = False
            position.add_property(name='status', value="IDLE")

        qprocessor_r.set_position_used(
            True, position=0
        )  # flag as used, never accessed for storage, used as holding location to sort into memory
        qprocessor_r.set_position_used(
            True, position=1)  # flag as used, never accessed for storage

    node_r.add_subcomponent(qprocessor_r)

    clock_r = Clock(name='Clock_node_R',
                    models=clock_model,
                    start_delay=clock_R_delay,
                    max_ticks=source_attempts)
    node_r.add_subcomponent(clock_r)

    # Setup quantum channels:
    qchannel_ar = QuantumChannel(name='QChannel_A->R',
                                 length=channel_A_length,
                                 models=channel_A_model)
    port_name_a, port_name_ra = network.add_connection(
        node_a,
        node_r,
        channel_to=qchannel_ar,
        label='quantum',
        port_name_node1='conn|A->R|',
        port_name_node2='conn|R<-A|')
    qchannel_br = QuantumChannel(name='QChannel_B->R',
                                 length=channel_B_length,
                                 models=channel_B_model)
    port_name_b, port_name_rb = network.add_connection(
        node_b,
        node_r,
        channel_to=qchannel_br,
        label='quantum',
        port_name_node1='conn|B->R|',
        port_name_node2='conn|R<-B|')
    # Setup Alice ports:
    node_a.subcomponents['QSource_node_A'].ports['qout0'].forward_output(
        node_a.ports[port_name_a])

    # Setup Bob ports:
    node_b.subcomponents['QSource_node_B'].ports['qout0'].forward_output(
        node_b.ports[port_name_b])

    # Set up Repeater ports:
    node_r.ports[port_name_ra].forward_input(
        node_r.subcomponents['QProcessor_R'].ports['qin0']
    )  # incoming qubits on QChannel_A->R go to slot 0
    node_r.ports[port_name_rb].forward_input(
        node_r.subcomponents['QProcessor_R'].ports['qin1']
    )  # incoming qubits on QChannel_B->R go to slot 1'

    return network
Пример #8
0
    def _create_processor(dephase_rate,
                          t_times,
                          memory_size,
                          qsource=None,
                          qdetect=None,
                          ent_source=False):

        gate_noise_model = DephaseNoiseModel(dephase_rate,
                                             time_independent=False)
        memory_noise_model = T1T2NoiseModel(T1=t_times['T1'], T2=t_times['T2'])

        physical_instructions = [
            PhysicalInstruction(instr.INSTR_INIT,
                                duration=1,
                                parallel=False,
                                q_noise_model=gate_noise_model),
            PhysicalInstruction(instr.INSTR_H,
                                duration=1,
                                parallel=False,
                                q_noise_model=gate_noise_model),
            PhysicalInstruction(instr.INSTR_X,
                                duration=1,
                                parallel=False,
                                q_noise_model=gate_noise_model),
            PhysicalInstruction(instr.INSTR_Z,
                                duration=1,
                                parallel=False,
                                q_noise_model=gate_noise_model),
            PhysicalInstruction(instr.INSTR_MEASURE,
                                duration=10,
                                parallel=False,
                                q_noise_model=gate_noise_model),
            PhysicalInstruction(instr.INSTR_MEASURE_X,
                                duration=10,
                                parallel=False,
                                q_noise_model=gate_noise_model)
        ]
        processor = QuantumProcessor("quantum_processor",
                                     num_positions=memory_size,
                                     mem_noise_models=[memory_noise_model] *
                                     memory_size,
                                     phys_instructions=physical_instructions)
        if qsource is not None:
            qubit_source = QSource('qubit_source',
                                   StateSampler([ks.s0, ks.s1],
                                                list(qsource['probs'])),
                                   double_frequency=qsource['freq'],
                                   num_ports=1,
                                   status=SourceStatus.OFF)
            processor.add_subcomponent(qubit_source)

        if ent_source:
            ent_source = QSource('ent_source',
                                 StateSampler([ks.b00]),
                                 num_ports=2,
                                 status=SourceStatus.OFF)
            processor.add_subcomponent(ent_source, name='ent_source')

        if qdetect is not None:
            qubit_detector_z = QuantumDetector(
                'qubit_detector_z',
                system_delay=qdetect['sys_delay'],
                dead_time=qdetect['dead_time'])
            qubit_detector_x = QuantumDetector(
                'qubit_detector_x',
                system_delay=qdetect['sys_delay'],
                dead_time=qdetect['dead_time'],
                observable=ops.X)
            processor.add_subcomponent(qubit_detector_z)
            processor.add_subcomponent(qubit_detector_x)

        return processor