code: def generate_discrete_swarm(
      n_particles, dimensions, binary=False, init_pos=None
  ):
      """Generate a discrete swarm
  
      Parameters
      ----------
      n_particles : int
          number of particles to be generated in the swarm.
      dimensions: int
          number of dimensions to be generated in the swarm.
      binary : bool
          generate a binary matrix. Default is :code:`False`
      init_pos : numpy.ndarray, optional
          option to explicitly set the particles' initial positions. Set to
          :code:`None` if you wish to generate the particles randomly.
          Default is :code:`None`
  
      Returns
      -------
      numpy.ndarray
          swarm matrix of shape (n_particles, n_dimensions)
  
      Raises
      ------
      ValueError
          When init_pos during binary=True does not contain two unique values.
      TypeError
          When the argument passed to n_particles or dimensions is incorrect.
      """
      try:
          if (init_pos is not None) and binary:
              if not len(np.unique(init_pos)) <= 2:
                  raise ValueError(
                      "User-defined init_pos is not binary!"
                  )
              # init_pos maybe ones
              pos = init_pos
          elif (init_pos is not None) and not binary:
              pos = init_pos
          elif (init_pos is None) and binary:
              pos = np.random.randint(2, size=(n_particles, dimensions))
          else:
              pos = np.random.random_sample(
                  size=(n_particles, dimensions)
              ).argsort(axis=1)
      except ValueError:
          rep.logger.exception(
              "Please check the size and value of dimensions"
          )
          raise
      except TypeError:
          msg = "generate_discrete_swarm() takes an int for n_particles and dimensions"
          rep.logger.exception(msg)
          raise
      else:
          return pos
  
file_path: pyswarms/pyswarms/backend/generators.py
imports: import logging
  import numpy
  from ..utils.reporter import Reporter
  from .swarms import Swarm
label_desc: Use image node_id 2 for calling a global function with example usage: generate_discrete_swarm(n_particles, dimensions, binary, init_pos) and returns: pos