def set_parameters(topology: Topology):
    # set memory parameters
    MEMO_FREQ = 2e3
    MEMO_EXPIRE = 0
    MEMO_EFFICIENCY = 1
    MEMO_FIDELITY = 0.9349367588934053
    for node in topology.get_nodes_by_type("QuantumRouter"):
        node.memory_array.update_memory_params("frequency", MEMO_FREQ)
        node.memory_array.update_memory_params("coherence_time", MEMO_EXPIRE)
        node.memory_array.update_memory_params("efficiency", MEMO_EFFICIENCY)
        node.memory_array.update_memory_params("raw_fidelity", MEMO_FIDELITY)

    # set detector parameters
    DETECTOR_EFFICIENCY = 0.9
    DETECTOR_COUNT_RATE = 5e7
    DETECTOR_RESOLUTION = 100
    for node in topology.get_nodes_by_type("BSMNode"):
        node.bsm.update_detectors_params("efficiency", DETECTOR_EFFICIENCY)
        node.bsm.update_detectors_params("count_rate", DETECTOR_COUNT_RATE)
        node.bsm.update_detectors_params("time_resolution", DETECTOR_RESOLUTION)
        
    # set entanglement swapping parameters
    SWAP_SUCC_PROB = 0.90
    SWAP_DEGRADATION = 0.99
    for node in topology.get_nodes_by_type("QuantumRouter"):
        node.network_manager.protocol_stack[1].set_swapping_success_rate(SWAP_SUCC_PROB)
        node.network_manager.protocol_stack[1].set_swapping_degradation(SWAP_DEGRADATION)
        
    # set quantum channel parameters
    ATTENUATION = 1e-5
    QC_FREQ = 1e11
    for qc in topology.qchannels:
        qc.attenuation = ATTENUATION
        qc.frequency = QC_FREQ
Example #2
0
def test_add_node():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    n1 = Node("n1", tl)
    topo.add_node(n1)
    assert len(topo.nodes) == 1
    assert topo.nodes["n1"] == n1
Example #3
0
def test_load_config():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    # NOTE: test should be run from Sequence-python directory
    #   if test needs to be run from a different directory, rewrite path
    #   this also applies to the next test (test_load_config_2)
    config_file = "tests/topology/topology.json"
    topo.load_config(config_file)
    config = json5.load(open(config_file))

    # check if have all nodes plus extra middle node
    assert len(topo.nodes) == len(config["nodes"]) + 1
    assert topo.graph["alice"] == {"bob": 3e3}
Example #4
0
def test_load_config_2():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    config_file = "example/starlight.json"
    topo.load_config(config_file)
    config = json5.load(open(config_file))

    assert len(topo.nodes) == len(config["nodes"]) + 10
    assert len(
        topo.cchannels
    ) == 36 + 20  # number of all-to-all connections plus middle node connectivity
    starlight = topo.nodes["StarLight"]
    assert starlight.cchannels["NU"].delay == (
        0.79e9 + 0.80e9) / 4  # avg. round trip / 2
    table = starlight.network_manager.protocol_stack[0].forwarding_table
    assert table["NU"] == "NU"
    assert table["UChicago_HC"] == "UChicago_PME"
    assert table["Argonne_2"] == "Argonne_1"
Example #5
0
def test_add_quantum_connection():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    n1 = Node("n1", tl)
    n2 = Node("n2", tl)
    n3 = QuantumRouter("n3", tl)
    n4 = QuantumRouter("n4", tl)
    topo.add_node(n1)
    topo.add_node(n2)
    topo.add_node(n3)
    topo.add_node(n4)

    topo.add_quantum_connection("n1", "n2", attenuation=1e-5, distance=1e3)

    assert topo.graph["n1"] == {"n2": 1e3}

    topo.add_quantum_connection("n3", "n4", attenuation=1e-5, distance=1e3)

    assert len(topo.nodes) == 5  # added middle node
    assert topo.graph["n3"] == {"middle_n3_n4": 500}
    channels = [e for e in tl.entities if type(e) == QuantumChannel]
    assert len(channels) == 3
Example #6
0
def test_get_nodes_by_type():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    n1 = Node("n1", tl)
    n2 = QuantumRouter("n2", tl)
    n3 = BSMNode("n3", tl, ["n2", "n4"])
    n4 = QuantumRouter("n4", tl)
    topo.add_node(n1)
    topo.add_node(n2)
    topo.add_node(n3)
    topo.add_node(n4)

    nodes = topo.get_nodes_by_type("QuantumRouter")
    print(topo.nodes.items())

    assert nodes == [n2, n4]
Example #7
0
def test_add_classical_connection():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    n1 = Node("n1", tl)
    n2 = Node("n2", tl)
    topo.add_node(n1)
    topo.add_node(n2)

    topo.add_classical_connection("n1", "n2", distance=1e3)

    assert topo.graph["n1"] == {}
    channels = [e for e in tl.entities if type(e) == ClassicalChannel]
    assert len(channels) == 1
    assert channels[0].ends == [n1, n2]
Example #8
0
def test_add_classical_connection():
    tl = Timeline()
    topo = Topology("test_topo", tl)

    n1 = Node("n1", tl)
    n2 = Node("n2", tl)
    topo.add_node(n1)
    topo.add_node(n2)

    topo.add_classical_connection("n1", "n2", distance=1e3)

    assert topo.graph["n1"] == {}
    channels = [e for e in tl.entities if type(e) == ClassicalChannel]
    assert len(channels) == 2
    for channel in channels:
        ends = [channel.receiver, channel.sender]
        assert n1 in ends and n2 in ends
def program(config_file, SEED):
    # Experiment params and config
    print(config_file, SEED, "start")
    network_config_file = "%s.json" % config_file
    runtime = 1e15

    seed(SEED)
    tl = Timeline(runtime)
    network_topo = Topology("network_topo", tl)
    network_topo.load_config(network_config_file)

    # display components
    #   nodes can be interated from Topology.nodes.values()
    #   quantum channels from Topology.qchannels
    #   classical channels from Topology.cchannels
    # print("Nodes:")
    # for name, node in network_topo.nodes.items():
    #     print("\t" + name + ": ", node)
    # print("Quantum Channels:")
    # for qc in network_topo.qchannels:
    #     print("\t" + qc.name + ": ", qc)
    # print("Classical Channels:")
    # for cc in network_topo.cchannels:
    #     print("\t" + cc.name + ": ", cc, "\tdelay:", cc.delay)

    # update forwarding table
    # for name, node in network_topo.nodes.items():
    #     if isinstance(node, QuantumRouter):
    #         table = network_topo.generate_forwarding_table(name)
    #         # print(name)
    #         for dst in table:
    #             next_node = table[dst]
    #             node.network_manager.protocol_stack[0].add_forwarding_rule(dst, next_node)
    #             # print("  ", dst, next_node)

    # set memory parameters
    MEMO_FREQ = 2e5
    MEMO_EXPIRE = 1.3
    MEMO_EFFICIENCY = 0.75
    MEMO_FIDELITY = 0.9909987775181183
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            node.memory_array.update_memory_params("frequency", MEMO_FREQ)
            node.memory_array.update_memory_params("coherence_time", MEMO_EXPIRE)
            node.memory_array.update_memory_params("efficiency", MEMO_EFFICIENCY)
            node.memory_array.update_memory_params("raw_fidelity", MEMO_FIDELITY)

    # set detector parameters
    DETECTOR_EFFICIENCY = 0.8
    DETECTOR_COUNT_RATE = 5e7
    DETECTOR_RESOLUTION = 100
    for name, node in network_topo.nodes.items():
        if isinstance(node, BSMNode):
            node.bsm.update_detectors_params("efficiency", DETECTOR_EFFICIENCY)
            node.bsm.update_detectors_params("count_rate", DETECTOR_COUNT_RATE)
            node.bsm.update_detectors_params("time_resolution", DETECTOR_RESOLUTION)

    # set quantum channel parameters
    ATTENUATION = 0.0002
    QC_FREQ = 5e7
    for qc in network_topo.qchannels:
        qc.attenuation = ATTENUATION
        qc.frequency = QC_FREQ

    # set entanglement swapping parameters
    SWAP_SUCC_PROB = 0.64
    SWAP_DEGRADATION = 0.99
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            node.network_manager.protocol_stack[1].set_swapping_success_rate(SWAP_SUCC_PROB)
            node.network_manager.protocol_stack[1].set_swapping_degradation(SWAP_DEGRADATION)

    nodes_name = []
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            nodes_name.append(name)

    apps = []
    for i, name in enumerate(nodes_name):
        app_node_name = name
        others = nodes_name[:]
        others.remove(app_node_name)
        app = RandomRequestApp(network_topo.nodes[app_node_name], others, i+SEED)
        apps.append(app)
        app.start()

    tl.init()
    tl.run()
    for app in apps:
        # print(app.node.name)
        # print("  ", len(app.get_wait_time()))
        # print("  ", app.get_wait_time())
        throughput = app.get_throughput()
        # print(" ", app.reserves)
        # print("  ", throughput)

    initiators = []
    responders = []
    start_times = []
    end_times = []
    memory_sizes = []
    fidelities = []
    wait_times = []
    throughputs = []
    for node in network_topo.nodes.values():
        if isinstance(node, QuantumRouter):
            initiator = node.name
            reserves = node.app.reserves
            _wait_times = node.app.get_wait_time()
            _throughputs = node.app.get_throughput()
            min_size = min(len(reserves), len(_wait_times), len(_throughputs))
            reserves = reserves[:min_size]
            _wait_times = _wait_times[:min_size]
            _throughputs = _throughputs[:min_size]
            for reservation, wait_time, throughput in zip(reserves, _wait_times, _throughputs):
                responder, s_t, e_t, size, fidelity = reservation
                initiators.append(initiator)
                responders.append(responder)
                start_times.append(s_t)
                end_times.append(e_t)
                memory_sizes.append(size)
                fidelities.append(fidelity)
                wait_times.append(wait_time)
                throughputs.append(throughput)
    log = {"Initiator": initiators, "Responder": responders, "Start_time": start_times, "End_time": end_times,
           "Memory_size": memory_sizes, "Fidelity": fidelities, "Wait_time": wait_times, "Throughput": throughputs}

    log_path = "%s/%s/" % (config_file, SEED)
    import os
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    df = pd.DataFrame(log)
    df.to_csv("%srequest.csv"%log_path)

    node_names = []
    start_times = []
    end_times = []
    memory_sizes = []
    for node in network_topo.nodes.values():
        if isinstance(node, QuantumRouter):
            node_name = node.name
            for reservation in node.network_manager.protocol_stack[1].accepted_reservation:
                s_t, e_t, size = reservation.start_time, reservation.end_time, reservation.memory_size
                if reservation.initiator != node.name and reservation.responder != node.name:
                    size *= 2
                node_names.append(node_name)
                start_times.append(s_t)
                end_times.append(e_t)
                memory_sizes.append(size)
    log = {"Node": node_names, "Start_time": start_times, "End_time": end_times, "Memory_size": memory_sizes}
    df = pd.DataFrame(log)
    df.to_csv("%smemory_usage.csv" % log_path)

    print(config_file, SEED, "done")
Example #10
0
if __name__ == "__main__":
    '''
    Program for drawing network from json file
    input: relative path to json file
    Graphviz library must be installed
    '''
    
    parser = argparse.ArgumentParser()
    parser.add_argument('config_file')
    parser.add_argument('-m', dest='draw_middle', action='store_true')

    args = parser.parse_args()

    tl = Timeline()
    topo = Topology("", tl)
    topo.load_config(args.config_file)
    g = Graph(format='png')
    g.attr(layout='neato', overlap='false')

    nodes = list(topo.nodes.keys())
    qc_ends = [(qc.ends[0].name, qc.ends[1].name) for qc in topo.qchannels]

    # add nodes and update qchannels if necessary
    for node in nodes:
        if type(topo.nodes[node]) == BSMNode:
            if args.draw_middle:
                g.node(node, label='BSM', shape='rectangle')
            else:
                connected_channels = [qc for qc in qc_ends if node in qc]
                qc_ends = [qc for qc in qc_ends if qc not in connected_channels]
            print("reservation approved at time",
                  self.node.timeline.now() * 1e-12)
        else:
            print("reservation failed at time",
                  self.node.timeline.now() * 1e-12)

    def get_memory(self, info: "MemoryInfo"):
        if info.state == "ENTANGLED" and info.remote_node == self.other:
            print("\treceived memory {} at time {}".format(
                info.index,
                self.node.timeline.now() * 1e-12))
            self.node.resource_manager.update(None, info.memory, "RAW")


if __name__ == "__main__":
    random.seed(0)
    network_config = "star_network.json"

    num_periods = 5
    tl = Timeline(2e12 * num_periods)
    network_topo = Topology("network_topo", tl)
    network_topo.load_config(network_config)

    node1 = "end1"
    node2 = "end2"
    app = PeriodicApp(network_topo.nodes[node1], node2)

    tl.init()
    app.start()
    tl.run()
def program(log_path, MEMO_FREQ, MEMO_EXPIRE, MEMO_EFFICIENCY, MEMO_FIDELITY,
            DETECTOR_EFFICIENCY, DETECTOR_COUNT_RATE, DETECTOR_RESOLUTION,
            ATTENUATION, QC_FREQ, SWAP_SUCC_PROB, SWAP_DEGRADATION):
    print(log_path, "running")
    # Experiment params and config
    network_config_file = "starlight.json"
    runtime = 1e15

    seed(1)
    tl = Timeline(runtime)
    network_topo = Topology("network_topo", tl)
    network_topo.load_config(network_config_file)

    # set memory parameters
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            node.memory_array.update_memory_params("frequency", MEMO_FREQ)
            node.memory_array.update_memory_params("coherence_time",
                                                   MEMO_EXPIRE)
            node.memory_array.update_memory_params("efficiency",
                                                   MEMO_EFFICIENCY)
            node.memory_array.update_memory_params("raw_fidelity",
                                                   MEMO_FIDELITY)

    # set detector parameters
    for name, node in network_topo.nodes.items():
        if isinstance(node, BSMNode):
            node.bsm.update_detectors_params("efficiency", DETECTOR_EFFICIENCY)
            node.bsm.update_detectors_params("count_rate", DETECTOR_COUNT_RATE)
            node.bsm.update_detectors_params("time_resolution",
                                             DETECTOR_RESOLUTION)

    # set quantum channel parameters
    for qc in network_topo.qchannels:
        qc.attenuation = ATTENUATION
        qc.frequency = QC_FREQ

    # set entanglement swapping parameters
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            node.network_manager.protocol_stack[1].set_swapping_success_rate(
                SWAP_SUCC_PROB)
            node.network_manager.protocol_stack[1].set_swapping_degradation(
                SWAP_DEGRADATION)

    nodes_name = []
    for name, node in network_topo.nodes.items():
        if isinstance(node, QuantumRouter):
            nodes_name.append(name)

    apps = []
    for i, name in enumerate(nodes_name):
        app_node_name = name
        others = nodes_name[:]
        others.remove(app_node_name)
        app = RandomRequestApp(network_topo.nodes[app_node_name], others, i)
        apps.append(app)
        app.start()

    tl.init()
    tl.run()

    initiators = []
    responders = []
    start_times = []
    end_times = []
    memory_sizes = []
    fidelities = []
    wait_times = []
    throughputs = []
    for node in network_topo.nodes.values():
        if isinstance(node, QuantumRouter):
            initiator = node.name
            reserves = node.app.reserves
            _wait_times = node.app.get_wait_time()
            _throughputs = node.app.get_throughput()
            min_size = min(len(reserves), len(_wait_times), len(_throughputs))
            reserves = reserves[:min_size]
            _wait_times = _wait_times[:min_size]
            _throughputs = _throughputs[:min_size]
            for reservation, wait_time, throughput in zip(
                    reserves, _wait_times, _throughputs):
                responder, s_t, e_t, size, fidelity = reservation
                initiators.append(initiator)
                responders.append(responder)
                start_times.append(s_t)
                end_times.append(e_t)
                memory_sizes.append(size)
                fidelities.append(fidelity)
                wait_times.append(wait_time)
                throughputs.append(throughput)
    log = {
        "Initiator": initiators,
        "Responder": responders,
        "Start_time": start_times,
        "End_time": end_times,
        "Memory_size": memory_sizes,
        "Fidelity": fidelities,
        "Wait_time": wait_times,
        "Throughput": throughputs
    }

    import os
    if not os.path.exists(log_path):
        os.makedirs(log_path)

    df = pd.DataFrame(log)
    df.to_csv(log_path + "/request.csv")

    print(log_path, "Done")