code: def test_reorder_graph(idtype):
      g = dgl.graph(
          ([0, 1, 2, 3, 4], [2, 2, 3, 2, 3]),
          idtype=idtype,
          device=F.ctx(),
      )
      g.ndata["h"] = F.copy_to(F.randn((g.num_nodes(), 3)), ctx=F.ctx())
      g.edata["w"] = F.copy_to(F.randn((g.num_edges(), 2)), ctx=F.ctx())
  
      # call with default: node_permute_algo=None, edge_permute_algo='src'
      rg = dgl.reorder_graph(g)
      assert dgl.EID in rg.edata.keys()
      src = F.asnumpy(rg.edges()[0])
      assert np.array_equal(src, np.sort(src))
  
      # call with 'rcmk' node_permute_algo
      rg = dgl.reorder_graph(g, node_permute_algo="rcmk")
      assert dgl.NID in rg.ndata.keys()
      assert dgl.EID in rg.edata.keys()
      src = F.asnumpy(rg.edges()[0])
      assert np.array_equal(src, np.sort(src))
  
      # call with 'dst' edge_permute_algo
      rg = dgl.reorder_graph(g, edge_permute_algo="dst")
      dst = F.asnumpy(rg.edges()[1])
      assert np.array_equal(dst, np.sort(dst))
  
      # call with unknown edge_permute_algo
      raise_error = False
      try:
          dgl.reorder_graph(g, edge_permute_algo="none")
      except:
          raise_error = True
      assert raise_error
  
      # reorder back to original according to stored ids
      rg = dgl.reorder_graph(g, node_permute_algo="rcmk")
      rg2 = dgl.reorder_graph(
          rg,
          "custom",
          permute_config={
              "nodes_perm": np.argsort(F.asnumpy(rg.ndata[dgl.NID]))
          },
      )
      assert F.array_equal(g.ndata["h"], rg2.ndata["h"])
      assert F.array_equal(g.edata["w"], rg2.edata["w"])
  
      # do not store ids
      rg = dgl.reorder_graph(g, store_ids=False)
      assert not dgl.NID in rg.ndata.keys()
      assert not dgl.EID in rg.edata.keys()
  
      # metis does not work on windows.
      if os.name == "nt":
          pass
      else:
          # metis_partition may fail for small graph.
          mg = create_large_graph(1000).to(F.ctx())
  
          # call with metis strategy, but k is not specified
          raise_error = False
          try:
              dgl.reorder_graph(mg, node_permute_algo="metis")
          except:
              raise_error = True
          assert raise_error
  
          # call with metis strategy, k is specified
          raise_error = False
          try:
              dgl.reorder_graph(
                  mg, node_permute_algo="metis", permute_config={"k": 2}
              )
          except:
              raise_error = True
          assert not raise_error
  
      # call with qualified nodes_perm specified
      nodes_perm = np.random.permutation(g.num_nodes())
      raise_error = False
      try:
          dgl.reorder_graph(
              g,
              node_permute_algo="custom",
              permute_config={"nodes_perm": nodes_perm},
          )
      except:
          raise_error = True
      assert not raise_error
  
      # call with unqualified nodes_perm specified
      raise_error = False
      try:
          dgl.reorder_graph(
              g,
              node_permute_algo="custom",
              permute_config={
                  "nodes_perm": nodes_perm[: g.num_nodes() - 1]
              },
          )
      except:
          raise_error = True
      assert raise_error
  
      # call with unsupported strategy
      raise_error = False
      try:
          dgl.reorder_graph(g, node_permute_algo="cmk")
      except:
          raise_error = True
      assert raise_error
  
      # heterograph: not supported
      raise_error = False
      try:
          hg = dgl.heterogrpah(
              {("user", "follow", "user"): ([0, 1], [1, 2])},
              idtype=idtype,
              device=F.ctx(),
          )
          dgl.reorder_graph(hg)
      except:
          raise_error = True
      assert raise_error
  
imports: import math
  import os
  import unittest
  import backend
  import dgl
  import dgl.function
  import dgl.partition
  import networkx
  import numpy
  import pytest
  from scipy import sparse
  from utils import parametrize_idtype
  from utils.graph_cases import get_cases
label_desc: Use image node_id 31 for calling a global function with example usage: test_reorder_graph(idtype) without return types