code: def to_batch(graphs: List[GraphData] = None) -> GraphData:
      """
      Convert a list of GraphData to a large graph (a batch).
  
      Parameters
      ----------
      graphs : list of GraphData
          The list of GraphData to be batched
  
      Returns
      -------
      GraphData
          The large graph containing all the graphs in the batch.
      """
  
      # Check
      if not isinstance(graphs, list):
          raise TypeError("to_batch() only accepts list of GraphData!")
      # assert isinstance(graphs, list), "to_batch() only accepts list of GraphData!"
      if not (len(graphs) > 0):
          raise ValueError(
              "Cannot convert an empty list of graphs into a big batched graph!"
          )
      # assert len(graphs) > 0, "Cannot convert an empty list of graphs into a big batched graph!"
  
      # Optimized version
      big_graph = GraphData()
      big_graph._is_batch = True
      big_graph.device = graphs[0].device
  
      total_num_nodes = 0
      for g in graphs:
          total_num_nodes += g.get_node_num()
  
      # Step 1: Add nodes
      big_graph.add_nodes(total_num_nodes)
  
      # Step 2: Set node features
      node_features = dict()
      for g in graphs:
          for feature_name in g.node_features.keys():
              if feature_name in node_features:
                  node_features[feature_name].append(
                      g.node_features[feature_name]
                  )
              else:
                  node_features[feature_name] = [
                      g.node_features[feature_name]
                  ]
      for k, v in node_features.items():
          if None in v:
              continue
          else:
              feature_tensor = torch.cat(v, dim=0)
              big_graph.node_features[k] = feature_tensor
  
      # Step 3: Set node attributes
      total_node_count = 0
      for g in graphs:
          for i in range(g.get_node_num()):
              big_graph.node_attributes[
                  total_node_count
              ] = g.node_attributes[i]
              total_node_count += 1
  
      # Step 4: Add edges
      def stack_edge_indices(gs):
          all_edge_indices = EdgeIndex(src=[], tgt=[])
          cumulative_node_num = 0
          for g in gs:
              for edge_index_tuple in g.get_all_edges():
                  src, tgt = edge_index_tuple
                  src += cumulative_node_num
                  tgt += cumulative_node_num
                  all_edge_indices.src.append(src)
                  all_edge_indices.tgt.append(tgt)
              cumulative_node_num += g.get_node_num()
          return all_edge_indices
  
      all_edge_indices = stack_edge_indices(graphs)
      big_graph.add_edges(all_edge_indices.src, all_edge_indices.tgt)
  
      # Step 5: Add edge features
      edge_features = dict()
      for g in graphs:
          for feature_name in g.edge_features.keys():
              if feature_name in edge_features:
                  edge_features[feature_name].append(
                      g.edge_features[feature_name]
                  )
              else:
                  edge_features[feature_name] = [
                      g.edge_features[feature_name]
                  ]
      for k, v in edge_features.items():
          if None in v:
              continue
          else:
              feature_tensor = torch.cat(v, dim=0)
              big_graph.edge_features[k] = feature_tensor
  
      # Step 6: Add edge attributes
      total_edge_count = 0
      for g in graphs:
          for i in range(g.get_edge_num()):
              big_graph.edge_attributes[
                  total_edge_count
              ] = g.edge_attributes[i]
              total_edge_count += 1
  
      # Step 7: Batch information preparation
      big_graph.batch_size = len(graphs)
      batch_numbers = []
      for i in range(len(graphs)):
          batch_numbers.extend([i] * graphs[i].get_node_num())
      big_graph.batch = batch_numbers
      big_graph._batch_num_nodes = [g.get_node_num() for g in graphs]
      big_graph._batch_num_edges = [g.get_edge_num() for g in graphs]
  
      return big_graph
  
imports: import os
  import warnings
  from collections import namedtuple
  from typing import Any, Callable, Dict, List, Tuple, Union
  import dgl
  import scipy.sparse
  import torch
  from torch.nn.utils.rnn import pad_sequence
  from .utils import EdgeNotFoundException, SizeMismatchException, check_and_expand, entail_zero_padding, int_to_list, slice_to_list
  from .views import BatchEdgeFeatView, BatchNodeFeatView, EdgeView, NodeFeatView, NodeView
label_desc: Use image node_id 2 for calling a global function with example usage: to_batch(graphs) and returns: big_graph, all_edge_indices