code: def _get_graph_reductions(graph):
      
      def frontier(g, nd):
          """Return the nodes after nd in the topological sort that are at the
          lowest possible level of the topological sort."""
          if g.out_degree(nd) == 0:
              return set([nd])
          else:
              frontiers = set()
              for n in g.successors(nd):
                  frontiers = frontiers.union(frontier(graph, n))
              return frontiers
      reductions = {}
      nodes_sort = list(networkx.algorithms.dag.topological_sort(graph))
      frontiers = [frontier(graph, n) for n in nodes_sort]
      # This loop ensures that if a node n2 comes after node n1 in the topological
      # sort, and their frontiers are identical then n1 can be reduced to n2.
      # If their frontiers aren't identical, the reduction cannot be done.
      for i, n1 in enumerate(nodes_sort):
          for j, n2 in enumerate(nodes_sort):
              if i > j:
                  continue
              if frontiers[i] == frontiers[j]:
                  reductions[n1] = n2
      return reductions
docs: Return transitive reductions on a DAG.
  
      This is used to reduce the set of activities of a BaseAgent to the most
      specific one(s) possible. For instance, if a BaseAgent is know to have
      'activity', 'catalytic' and 'kinase' activity, then this function will
      return {'activity': 'kinase', 'catalytic': 'kinase', 'kinase': 'kinase'}
      as the set of reductions.