code: def _dag_to_dot(dag: DAGNode):
      """Create a Dot graph from dag.
  
      TODO(lchu):
      1. add more Dot configs in kwargs,
      e.g. rankdir, alignment, etc.
      2. add more contents to graph,
      e.g. args, kwargs and options of each node
  
      """
      # Step 0: check dependencies and init graph
      _check_pydot_and_graphviz()
      import pydot
  
      graph = pydot.Dot(rankdir="LR")
  
      # Step 1: generate unique name for each node in dag
      nodes, edges = _get_nodes_and_edges(dag)
      name_generator = _DAGNodeNameGenerator()
      node_names = {}
      for node in nodes:
          node_names[node] = name_generator.get_node_name(node)
  
      # Step 2: create graph with all the edges
      for edge in edges:
          graph.add_edge(
              pydot.Edge(node_names[edge[0]], node_names[edge[1]])
          )
      # if there is only one node
      if len(nodes) == 1 and len(edges) == 0:
          graph.add_node(pydot.Node(node_names[nodes[0]]))
  
      return graph
  
file_path: ray/python/ray/dag/vis_utils.py
imports: from ray.dag import DAGNode
  import os
  import tempfile
  from ray.dag.utils import _DAGNodeNameGenerator
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 4 for calling a global function with example usage: _dag_to_dot(dag) and returns: graph