code: def define_sampler(
      batch_order: str,
      ys: List[Union[Tensor, np.ndarray, List]],
      num_classes: int,
      dist_type: str = "kl",
  ):
      if batch_order == "rand":
          logging.info("Running with random order")
          sampler = torch.utils.data.RandomSampler(ys)
      elif batch_order in ["order", "sample"]:
          kl_div = get_pair_wise_distance(
              ys, num_classes, dist_type=dist_type
          )
          if batch_order == "order":
              from python_tsp.heuristics import (
                  solve_tsp_simulated_annealing,
              )
  
              best_perm, _ = solve_tsp_simulated_annealing(kl_div)
              logging.info(f"Running with given order: {best_perm}")
              sampler = IBMBOrderedSampler(best_perm)
          else:
              logging.info("Running with weighted sampling")
              sampler = IBMBWeightedSampler(kl_div)
      else:
          raise ValueError
  
      return sampler
  
imports: import logging
  import math
  from typing import Callable, Iterator, List, NamedTuple, Optional, Tuple, Union
  import numpy
  import scipy.sparse
  import torch
  from torch import Tensor
  from tqdm import tqdm
  from torch_geometric.data import Data
  from torch_geometric.typing import SparseTensor
  from torch_geometric.utils import get_ppr, is_undirected, subgraph
label_desc: Use image node_id 5 for calling a global function with example usage: define_sampler(batch_order, ys, num_classes, dist_type) and returns: sampler