code: def multigraph_paths(G, source, cutoff=None):
      
      if cutoff is None:
          cutoff = (len(G.edges()) * len(G.nodes())) + 1
  
      # the path starts at the node specified
      current = [(source, 0)]
      # traversals we need to go back and do
      queue = []
      # completed paths
      traversals = []
  
      for i in range(cutoff):
          # paths are stored as (node, instance) so
          # get the node of the last place visited
          current_node = current[-1][0]
          # get all the children of the current node
          child = G[current_node]
  
          if len(child) == 0:
              # we have no children, so we are at the end of this path
              # save the path as a completed traversal
              traversals.append(current)
              # if there is nothing on the queue, we are done
              if len(queue) == 0:
                  break
              # otherwise continue traversing with the next path
              # on the queue
              current = queue.pop()
          else:
              # oh no, we have multiple edges from current -> child
              start = True
              # iterate through child nodes and edge instances
              for node in child.keys():
                  for instance in child[node].keys():
                      if start:
                          # if this is the first edge, keep it on the
                          # current traversal and save the others for later
                          current.append((node, instance))
                          start = False
                      else:
                          # this child has multiple instances
                          # so we will need to traverse them multiple times
                          # we appended a node to current, so only take the
                          # first n-1 visits
                          queue.append(current[:-1] + [(node, instance)])
      return traversals
docs: 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