code: def verify_hetero_graph(g, parts):
      num_nodes = {ntype: 0 for ntype in g.ntypes}
      num_edges = {etype: 0 for etype in g.canonical_etypes}
      for part in parts:
          assert len(g.ntypes) == len(F.unique(part.ndata[dgl.NTYPE]))
          assert len(g.canonical_etypes) == len(
              F.unique(part.edata[dgl.ETYPE])
          )
          for ntype in g.ntypes:
              ntype_id = g.get_ntype_id(ntype)
              inner_node_mask = _get_inner_node_mask(part, ntype_id)
              num_inner_nodes = F.sum(
                  F.astype(inner_node_mask, F.int64), 0
              )
              num_nodes[ntype] += num_inner_nodes
          for etype in g.canonical_etypes:
              etype_id = g.get_etype_id(etype)
              inner_edge_mask = _get_inner_edge_mask(part, etype_id)
              num_inner_edges = F.sum(
                  F.astype(inner_edge_mask, F.int64), 0
              )
              num_edges[etype] += num_inner_edges
      # Verify the number of nodes are correct.
      for ntype in g.ntypes:
          print(
              "node {}: {}, {}".format(
                  ntype, g.num_nodes(ntype), num_nodes[ntype]
              )
          )
          assert g.num_nodes(ntype) == num_nodes[ntype]
      # Verify the number of edges are correct.
      for etype in g.canonical_etypes:
          print(
              "edge {}: {}, {}".format(
                  etype, g.num_edges(etype), num_edges[etype]
              )
          )
          assert g.num_edges(etype) == num_edges[etype]
  
      nids = {ntype: [] for ntype in g.ntypes}
      eids = {etype: [] for etype in g.canonical_etypes}
      for part in parts:
          _, _, eid = part.edges(form="all")
          etype_arr = F.gather_row(part.edata[dgl.ETYPE], eid)
          eid_type = F.gather_row(part.edata[dgl.EID], eid)
          for etype in g.canonical_etypes:
              etype_id = g.get_etype_id(etype)
              eids[etype].append(
                  F.boolean_mask(eid_type, etype_arr == etype_id)
              )
              # Make sure edge Ids fall into a range.
              inner_edge_mask = _get_inner_edge_mask(part, etype_id)
              inner_eids = np.sort(
                  F.asnumpy(
                      F.boolean_mask(
                          part.edata[dgl.EID], inner_edge_mask
                      )
                  )
              )
              assert np.all(
                  inner_eids
                  == np.arange(inner_eids[0], inner_eids[-1] + 1)
              )
  
          for ntype in g.ntypes:
              ntype_id = g.get_ntype_id(ntype)
              # Make sure inner nodes have Ids fall into a range.
              inner_node_mask = _get_inner_node_mask(part, ntype_id)
              inner_nids = F.boolean_mask(
                  part.ndata[dgl.NID], inner_node_mask
              )
              assert np.all(
                  F.asnumpy(
                      inner_nids
                      == F.arange(
                          F.as_scalar(inner_nids[0]),
                          F.as_scalar(inner_nids[-1]) + 1,
                      )
                  )
              )
              nids[ntype].append(inner_nids)
  
      for ntype in nids:
          nids_type = F.cat(nids[ntype], 0)
          uniq_ids = F.unique(nids_type)
          # We should get all nodes.
          assert len(uniq_ids) == g.num_nodes(ntype)
      for etype in eids:
          eids_type = F.cat(eids[etype], 0)
          uniq_ids = F.unique(eids_type)
          assert len(uniq_ids) == g.num_edges(etype)
  
imports: import json
  import os
  import tempfile
  import backend
  import dgl
  import numpy
  import pytest
  import torch
  from dgl import function
  from dgl.distributed import convert_dgl_partition_to_csc_sampling_graph, load_partition, load_partition_book, load_partition_feats, partition_graph
  from dgl.distributed.graph_partition_book import _etype_str_to_tuple, _etype_tuple_to_str, DEFAULT_ETYPE, DEFAULT_NTYPE, EdgePartitionPolicy, HeteroDataName, NodePartitionPolicy, RangePartitionBook
  from dgl.distributed.partition import _get_inner_edge_mask, _get_inner_node_mask, RESERVED_FIELD_DTYPE
  from scipy import sparse
  from utils import reset_envs
label_desc: Use image node_id 5 for calling a global function with example usage: verify_hetero_graph(g, parts) without return types