def multigraph_paths(G, source, cutoff=None):
    """
    For a networkx MultiDiGraph, find all paths from a source node
    to leaf nodes. This function returns edge instance numbers
    in addition to nodes, unlike networkx.all_simple_paths.

    Parameters
    ---------------
    G : networkx.MultiDiGraph
      Graph to evaluate
    source : hashable
      Node to start traversal at
    cutoff : int
      Number of nodes to visit
      If None will visit all nodes

    Returns
    ----------
    traversals : (n,) list of [(node, edge instance index), ] paths
      Traversals of the multigraph
    """
    if cutoff is None:
        cutoff = len(G.edges()) * len(G.nodes()) + 1
    current = [(source, 0)]
    queue = []
    traversals = []
    for i in range(cutoff):
        current_node = current[-1][0]
        child = G[current_node]
        if len(child) == 0:
            traversals.append(current)
            if len(queue) == 0:
                break
            current = queue.pop()
        else:
            start = True
            for node in child.keys():
                for instance in child[node].keys():
                    if start:
                        current.append((node, instance))
                        start = False
                    else:
                        queue.append(current[:-1] + [(node, instance)])
    return traversals
