import pickle


def load(filename: str):
    """Loads a network from file and returns a list of modules in that network.

    The connections between the module have been set according to the file.

    Args:
        filename (str): The path to the .rtc file containing a network.

    Returns:
        (list, list): A list of Modules that are connected and ready to be run
            and a list of connections between those modules.
    """
    mc_list = pickle.load(open(filename, "rb"))
    module_dict = {}
    module_list = []
    connection_list = []

    for m in mc_list[0]:
        mod = m["retico_class"](**m["args"])
        module_dict[m["id"]] = mod
        module_list.append(mod)
    for ida, idb in mc_list[1]:
        module_dict[idb].subscribe(module_dict[ida])
        connection_list.append((module_dict[idb], module_dict[ida]))

    return (module_list, connection_list)