code: def add_undirected_edges(graph):
      """Makes all edges of the given `graph` bi-directional.
  
      Updates `graph` to include a reversed version of each of its edges. Multiple
      edges between the same source and target node IDs are combined by picking the
      edge with the largest weight.
  
      Args:
        graph: A `dict`: source -> (target -> weight) as returned by the
          `read_tsv_graph` function.
  
      Returns:
        `None`. Instead, this function has a side-effect on the `graph` argument.
      """
  
      def all_graph_edges():
          # Make a copy of all source IDs to avoid concurrent iteration failure.
          sources = list(graph.keys())
          for source in sources:
              # Make a copy of source's out-edges to avoid concurrent iteration failure.
              out_edges = dict(graph[source])
              for target, weight in six.iteritems(out_edges):
                  yield (source, target, weight)
  
      start_time = time.time()
      logging.info("Making all edges bi-directional...")
      for s, t, w in all_graph_edges():
          add_edge(graph, [t, s, w])
      logging.info(
          "Done (%.2f seconds). Total graph nodes: %d",
          (time.time() - start_time),
          len(graph),
      )
  
file_path: neural-structured-learning/neural_structured_learning/tools/graph_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import time
  from absl import logging
  import six
label_desc: Use image node_id 2 for calling a global function with example usage: add_undirected_edges(graph) without return types