code: def construct_edges(var_name, all_ops, all_vars, all_edges):
      """
      Construct path edges from var's from_node to to_nodes.
      Algorithm:
          1. Judge if src_node and dst_node have the same parent node, if yes, link them directly
          and fill information in all_edges, return.
          2. Find the closest common ancestor, repeat link node and its parent until reach the common ancestor.
          Every time construct a new edge, fill information in all_edges.
      Args:
          var_name: name of variable to process
          all_ops: used to index all nodes.
          all_vars:  used to index all variables.
          all_edges: used to store and index all edges
      """
      from_node = all_vars[var_name]["from_node"]
      to_nodes = all_vars[var_name]["to_nodes"]
  
      def _construct_edge(src_node, dst_node):
          if (
              all_ops[src_node]["parent_node"]
              == all_ops[dst_node]["parent_node"]
          ):
              if (src_node, dst_node) not in all_edges:
                  all_edges[(src_node, dst_node)] = {
                      "from_node": src_node,
                      "to_node": dst_node,
                      "vars": {var_name},
                      "label": "",
                  }
              else:
                  all_edges[(src_node, dst_node)]["vars"].add(var_name)
          else:
              common_ancestor = os.path.commonpath([src_node, dst_node])
              common_ancestor = pathlib.Path(
                  common_ancestor
              ).as_posix()  # in windows, os.path.commonpath will return windows path, we should convert it to posix
              src_base_node = src_node
              while True:
                  parent_node = all_ops[src_base_node]["parent_node"]
                  if parent_node == common_ancestor:
                      break
                  if (src_base_node, parent_node) not in all_edges:
                      all_edges[(src_base_node, parent_node)] = {
                          "from_node": src_base_node,
                          "to_node": parent_node,
                          "vars": {var_name},
                          "label": "",
                      }
                  else:
                      all_edges[(src_base_node, parent_node)][
                          "vars"
                      ].add(var_name)
                  src_base_node = parent_node
              dst_base_node = dst_node
              while True:
                  parent_node = all_ops[dst_base_node]["parent_node"]
                  if parent_node == common_ancestor:
                      break
                  if (parent_node, dst_base_node) not in all_edges:
                      all_edges[(parent_node, dst_base_node)] = {
                          "from_node": parent_node,
                          "to_node": dst_base_node,
                          "vars": {var_name},
                          "label": "",
                      }
                  else:
                      all_edges[(parent_node, dst_base_node)][
                          "vars"
                      ].add(var_name)
                  dst_base_node = parent_node
              if (src_base_node, dst_base_node) not in all_edges:
                  all_edges[(src_base_node, dst_base_node)] = {
                      "from_node": src_base_node,
                      "to_node": dst_base_node,
                      "vars": {var_name},
                      "label": "",
                  }
              else:
                  all_edges[(src_base_node, dst_base_node)]["vars"].add(
                      var_name
                  )
          return
  
      if from_node and to_nodes:
          for to_node in to_nodes:
              if from_node == to_node:
                  continue
              _construct_edge(from_node, to_node)
  
file_path: VisualDL/visualdl/component/graph/graph_component.py
imports: import collections
  import os.path
  import pathlib
  import re
  from .None import utils
label_desc: Use image node_id 3 for calling a global function with example usage: construct_edges(var_name, all_ops, all_vars, all_edges) without return types