code: def create_neg_subgraph(
      pos_g,
      neg_g,
      chunk_size,
      neg_sample_size,
      is_chunked,
      neg_head,
      num_nodes,
  ):
      """KG models need to know the number of chunks, the chunk size and negative sample size
      of a negative subgraph to perform the computation more efficiently.
      This function tries to infer all of these information of the negative subgraph
      and create a wrapper class that contains all of the information.
  
      Parameters
      ----------
      pos_g : DGLGraph
          Graph holding positive edges.
      neg_g : DGLGraph
          Graph holding negative edges.
      chunk_size : int
          Chunk size of negative subgrap.
      neg_sample_size : int
          Negative sample size of negative subgrap.
      is_chunked : bool
          If True, the sampled batch is chunked.
      neg_head : bool
          If True, negative_mode is 'head'
          If False, negative_mode is 'tail'
      num_nodes: int
          Total number of nodes in the whole graph.
  
      Returns
      -------
      ChunkNegEdgeSubgraph
          Negative graph wrapper
      """
      assert neg_g.number_of_edges() % pos_g.number_of_edges() == 0
      # We use all nodes to create negative edges. Regardless of the sampling algorithm,
      # we can always view the subgraph with one chunk.
      if (neg_head and len(neg_g.head_nid) == num_nodes) or (
          not neg_head and len(neg_g.tail_nid) == num_nodes
      ):
          num_chunks = 1
          chunk_size = pos_g.number_of_edges()
      elif is_chunked:
          # This is probably for evaluation.
          if (
              pos_g.number_of_edges() < chunk_size
              and neg_g.number_of_edges() % neg_sample_size == 0
          ):
              num_chunks = 1
              chunk_size = pos_g.number_of_edges()
          # This is probably the last batch in the training. Let's ignore it.
          elif pos_g.number_of_edges() % chunk_size > 0:
              return None
          else:
              num_chunks = int(pos_g.number_of_edges() / chunk_size)
          assert num_chunks * chunk_size == pos_g.number_of_edges()
      else:
          num_chunks = pos_g.number_of_edges()
          chunk_size = 1
      return ChunkNegEdgeSubgraph(
          neg_g, num_chunks, chunk_size, neg_sample_size, neg_head
      )
  
imports: import math
  import numpy
  import scipy
  import dgl.backend
  import dgl
  import os
  import sys
  import pickle
  import time
  from dgl.base import NID, EID
  import pdb
label_desc: Use image node_id 5 for calling a global function with example usage: create_neg_subgraph(pos_g, neg_g, chunk_size, neg_sample_size, is_chunked, neg_head, num_nodes) and returns: ChunkNegEdgeSubgraph, None