def get_cross_edges(graph, partitions, ranked=False):
    """
    Get the edges in the network which go between partitions.
    If ranked is True, only include edges which go from lower-ranked partitions
    to higher-ranked partitions.
    These edges are used to determine the interface functions.
    """
    # construct a map of nodes to their partitions
    n_parts = {node: i for (i, part) in enumerate(partitions) for node in part}

    def edge_predicate(e):
        src = n_parts[e.source]
        tgt = n_parts[e.target]
        return (ranked and src < tgt) or (not ranked and src != tgt)

    return [e.tuple for e in graph.es if edge_predicate(e)]