code: def traverse(start_ops, end_ops=None, neighbors_fn=None):
      """
      Traverse a graph and output the visited nodes.
  
      Args:
          start_ops (iter): The nodes to start the traversal from.
          end_ops (iter): Optional. The nodes at which to stop traversing.
          neighbors_fn (func): Optional. Function from Op -> Iter[Op] that provides the neighbors of an op.
              Defaults to `get_consumers`.
  
      Returns:
          Set[Operation]: The visited nodes
      """
      end_ops = end_ops or set()
      neighbors_fn = neighbors_fn or get_consumers
  
      visited = set()
      queue = deque()
      queue.extend(start_ops)
  
      while queue:
          curr_op = queue.popleft()
          if curr_op in visited:
              continue
          visited.add(curr_op)
          if curr_op in end_ops:
              continue
          queue.extend(neighbors_fn(curr_op))
  
      return visited
  
file_path: autodist/autodist/kernel/common/utils.py
imports: from collections import deque
  from tensorflow.core.framework.attr_value_pb2 import AttrValue
  from tensorflow.python.util.compat import as_bytes
  from autodist.const import AUTODIST_REPLICA_PREFIX, COLOCATION_PREFIX
label_desc: Use image node_id 8 for calling a global function with example usage: traverse(start_ops, end_ops, neighbors_fn) and returns: visited