code: def metis_partition(
      graph, npart, node_weights=None, edge_weights=None
  ):
      """Perform Metis Partition over graph.
  
      Graph Partition with third-party library METIS. Input graph, npart, node_weights and
      edge_weights. Return a `numpy.ndarray` denotes which cluster the node belongs to.
  
      Args:
  
          graph (pgl.Graph): The input graph for partition.
  
          npart (int): The number of part in the final cluster.
  
          node_weights (optional): The node weights for each node. We will automatically use (MinMaxScaler + 1) * 1000
                                  to convert the array into postive integers.
  
          edge_weights (optional): The edge weights for each node. We will automatically use (MinMaxScaler + 1) * 1000
                                  to convert the array into postive integers.
  
      Returns:
  
          part_id (numpy.ndarray): An int64 numpy array with shape [num_nodes, ] denotes the cluster id.
  
      """
  
      log.warning(
          "The input graph of metis_partition should be undirected."
      )
  
      if npart == 1:
          return np.zeros(graph.num_nodes, dtype=np.int64)
  
      csr = graph.adj_dst_index.numpy(inplace=False)
      indptr = csr._indptr
      v = csr._sorted_v
      sorted_eid = csr._sorted_eid
      if edge_weights is not None:
          if check_is_tensor(edge_weights):
              edge_weights = edge_weights.numpy()
          edge_weights = edge_weights[sorted_eid.tolist()]
          edge_weights = _metis_weight_scale(edge_weights)
  
      if node_weights is not None:
          if check_is_tensor(node_weights):
              node_weights = node_weights.numpy()
          node_weights = _metis_weight_scale(node_weights)
  
      # TODO: @Yelrose support recursive METIS
      # use K-way metis; recursive metis always core dump
      part_id = _metis_partition(
          graph.num_nodes,
          indptr,
          v,
          nparts=npart,
          edge_weights=edge_weights,
          node_weights=node_weights,
          recursive=False,
      )
      return part_id
  
file_path: PGL/pgl/partition.py
imports: import math
  import numpy
  from pgl.graph_kernel import metis_partition
  from pgl.utils.helper import check_is_tensor
  from pgl.utils.logger import log
label_desc: Use image node_id 2 for calling a global function with example usage: metis_partition(graph, npart, node_weights, edge_weights) and returns: part_id, np