コード例 #1
0
def set_settings(settings):
    for section, section_settings in settings.items():
        for key, value in section_settings.items():
            Settings.set_setting(section=section, key=key, value=value)
コード例 #2
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def t1(value):
    """The effective T1 to be used for noisy qubits"""
    Settings.set_setting("BACKEND", "t1", str(value))
コード例 #3
0
def construct_topology_config(topology, nodes, save_fig=True):
    """
    Constructs a json file at config/topology.json, used to define the topology of the network.

    :param topology: str
        Should be one of the following: None, 'complete', 'ring', 'random_tree'.
    :param nodes: list of str
        List of the names of the nodes.
    :param save_fig: bool
        Whether to save a picture of the network
    :return: None
    """
    if topology:
        if isinstance(topology, dict):
            adjacency_dct = {node: topology[node] for node in nodes}
        elif topology == "complete":
            adjacency_dct = {}
            for i, node in enumerate(nodes):
                adjacency_dct[node] = nodes[:i] + nodes[i + 1:]

        elif topology == "ring":
            adjacency_dct = {}
            nn = len(nodes)
            for i, node in enumerate(nodes):
                adjacency_dct[node] = [
                    nodes[(i - 1) % nn], nodes[(i + 1) % nn]
                ]

        elif topology == "path":
            adjacency_dct = {}
            nn = len(nodes)
            for i, node in enumerate(nodes):
                if i == 0:
                    adjacency_dct[node] = [nodes[i + 1]]
                elif i == (nn - 1):
                    adjacency_dct[node] = [nodes[i - 1]]
                else:
                    adjacency_dct[node] = [
                        nodes[(i - 1) % nn], nodes[(i + 1) % nn]
                    ]

        elif topology == "random_tree":
            adjacency_dct = get_random_tree(nodes)

        elif topology[:16] == "random_connected":
            try:
                nr_edges = int(topology[17:])
            except ValueError:
                raise ValueError(
                    "When specifying a random connected graph use the format 'random_connected_{nr_edges}',"
                    "where 'nr_edges' is the number of edges of the graph.")
            except IndexError:
                raise ValueError(
                    "When specifying a random connected graph use the format 'random_connected_{nr_edges}',"
                    "where 'nr_edges' is the number of edges of the graph.")
            adjacency_dct = get_random_connected(nodes, nr_edges)

        else:
            raise ValueError("Unknown topology name")

        # Get path to SimulaQron folder
        simulaqron_path = get_simulaqron_path.main()

        if save_fig:
            network = nx.from_dict_of_lists(adjacency_dct)
            try:
                nx.draw(network, with_labels=True)
            except _tkinter.TclError as err:
                logging.warning(
                    "Could not draw since there seems to be no screen. Error: {}"
                    .format(err))
            else:
                fig_path = os.path.join(simulaqron_path, "config/topology.png")
                plt.savefig(fig_path)

        topology_file = os.path.join(simulaqron_path, "config/topology.json")
        with open(topology_file, "w") as top_file:
            json.dump(adjacency_dct, top_file)

        Settings.set_setting("BACKEND", "topology_file",
                             "config/topology.json")
    else:
        Settings.set_setting("BACKEND", "topology_file", "")
コード例 #4
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def nodes_file(value):
    """The path to the topology file to be used, can be ""."""
    Settings.set_setting("BACKEND", "nodes_file", value)
コード例 #5
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def noisy_qubits(value):
    """Whether qubits should be noisy (on/off)"""
    if value == "on":
        Settings.set_setting("BACKEND", "noisy_qubits", 'True')
    else:
        Settings.set_setting("BACKEND", "noisy_qubits", 'False')
コード例 #6
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def recv_retry_time(value):
    """When receiving a qubit or EPR pair, how long to wait between checks of whether a qubit is received."""
    Settings.set_setting("BACKEND", "waittimerecv", str(value))
コード例 #7
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def log_level(value):
    """Log level for both backend and frontend."""
    Settings.set_setting("BACKEND", "loglevel", value)
    Settings.set_setting("FRONTEND", "loglevel", value)
コード例 #8
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def recv_timeout(value):
    """When receiving a qubit or EPR pair, how long to wait until raising a timeout."""
    Settings.set_setting("BACKEND", "recvtimeout", str(value))
    Settings.set_setting("BACKEND", "recveprtimeout", str(value))
コード例 #9
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def conn_retry_time(value):
    """If setup fails, how long to wait until a retry."""
    Settings.set_setting("BACKEND", "waittime", str(value))
コード例 #10
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def max_registers(value):
    """How many registers a node can hold."""
    Settings.set_setting("BACKEND", "maxregs_per_node", str(value))
コード例 #11
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def max_qubits(value):
    """Max virt-qubits per node and max sim-qubits per register."""
    Settings.set_setting("BACKEND", "maxqubits_per_node", str(value))
コード例 #12
0
ファイル: SimulaQron.py プロジェクト: twobombs/SimulaQron
def backend(value):
    """The backend to use (stabilizer, projectq, qutip)."""
    Settings.set_setting("BACKEND", "backend", value)