code: def grid(dim: Dimension, num: int):
      """Build a one-dim grid of num points"""
  
      if dim.type == "categorical":
          # NOTE: Following lines have type errors, because we check the type using the `type`
          # attribute rather than using `isinstance`. This is the right thing to do, since the
          # TransformedDimension subclasses wouldn't be handled correctly using `isinstance`.
          # TODO: Would be nice for the different TransformedSpace subclasses to be generics w.r.t.
          # the type of the wrapped space. This way, we could annotate the functions below with e.g.
          # `Integer | TransformedSpace[Integer]`.
          return categorical_grid(dim, num)  # type: ignore
      elif dim.type == "integer":
          return discrete_grid(dim, num)  # type: ignore
      elif dim.type == "real":
          return real_grid(dim, num)  # type: ignore
      elif dim.type == "fidelity":
          return fidelity_grid(dim, num)  # type: ignore
      else:
          raise TypeError(
              "Grid Search only supports `real`, `integer`, `categorical` and `fidelity`: "
              f"`{dim.type}`\n"
              "For more information on dimension types, see "
              "https://orion.readthedocs.io/en/stable/user/searchspace.html"
          )
  
imports: from __future__ import annotations
  import itertools
  import logging
  import numpy
  from orion.algo.base import BaseAlgorithm
  from orion.algo.space import Categorical, Dimension, Fidelity, Integer, Real, Space
  from orion.core.utils import format_trials
label_desc: Use image node_id 1 for calling a global function with example usage: grid(dim, num) and returns: categorical_grid, discrete_grid, real_grid, fidelity_grid