code: def generate_pcs(nni_search_space_content):
      """
      Generate the Parameter Configuration Space (PCS) which defines the
      legal ranges of the parameters to be optimized and their default values.
      Generally, the format is:
      # parameter_name categorical {value_1, ..., value_N} [default value]
      # parameter_name ordinal {value_1, ..., value_N} [default value]
      # parameter_name integer [min_value, max_value] [default value]
      # parameter_name integer [min_value, max_value] [default value] log
      # parameter_name real [min_value, max_value] [default value]
      # parameter_name real [min_value, max_value] [default value] log
      Reference: https://automl.github.io/SMAC3/stable/options.html
  
      Parameters
      ----------
      nni_search_space_content: search_space
          The search space in this experiment in nni
  
      Returns
      -------
      Parameter Configuration Space (PCS)
          the legal ranges of the parameters to be optimized and their default values
  
      Raises
      ------
      RuntimeError
          unsupported type or value error or incorrect search space
      """
      categorical_dict = {}
      search_space = nni_search_space_content
  
      def dump_categorical(fd, key, categories):
          choice_len = len(categories)
          if key in categorical_dict:
              raise RuntimeError(
                  "%s has already existed, please make sure search space has no duplicate key."
                  % key
              )
          categorical_dict[key] = search_space[key]["_value"]
          fd.write(
              "%s categorical {%s} [0]\n"
              % (key, ",".join(map(str, range(choice_len))))
          )
  
      with open("param_config_space.pcs", "w") as pcs_fd:
          if isinstance(search_space, dict):
              for key in search_space.keys():
                  if isinstance(search_space[key], dict):
                      try:
                          if search_space[key]["_type"] == "choice":
                              dump_categorical(
                                  pcs_fd,
                                  key,
                                  search_space[key]["_value"],
                              )
                          elif search_space[key]["_type"] == "randint":
                              lower, upper = search_space[key]["_value"]
                              if lower + 1 == upper:
                                  dump_categorical(pcs_fd, key, [lower])
                              else:
                                  pcs_fd.write(
                                      "%s integer [%d, %d] [%d]\n"
                                      % (key, lower, upper - 1, lower)
                                  )
                          elif search_space[key]["_type"] == "uniform":
                              low, high = search_space[key]["_value"]
                              if low == high:
                                  dump_categorical(pcs_fd, key, [low])
                              else:
                                  pcs_fd.write(
                                      "%s real [%s, %s] [%s]\n"
                                      % (key, low, high, low)
                                  )
                          elif (
                              search_space[key]["_type"] == "loguniform"
                          ):
                              # use np.round here to ensure that the rounded default value is in the range,
                              # which will be rounded in configure_space package
                              low, high = list(
                                  np.round(
                                      np.log(
                                          search_space[key]["_value"]
                                      ),
                                      10,
                                  )
                              )
                              if low == high:
                                  dump_categorical(
                                      pcs_fd,
                                      key,
                                      [search_space[key]["_value"][0]],
                                  )
                              else:
                                  pcs_fd.write(
                                      "%s real [%s, %s] [%s]\n"
                                      % (key, low, high, low)
                                  )
                          elif search_space[key]["_type"] == "quniform":
                              low, high, q = search_space[key][
                                  "_value"
                              ][0:3]
                              vals = np.clip(
                                  np.arange(
                                      np.round(low / q),
                                      np.round(high / q) + 1,
                                  )
                                  * q,
                                  low,
                                  high,
                              ).tolist()
                              pcs_fd.write(
                                  "%s ordinal {%s} [%s]\n"
                                  % (
                                      key,
                                      json.dumps(vals)[1:-1],
                                      json.dumps(vals[0]),
                                  )
                              )
                          else:
                              raise RuntimeError(
                                  "unsupported _type %s"
                                  % search_space[key]["_type"]
                              )
                      except:
                          raise RuntimeError("_type or _value error.")
          else:
              raise RuntimeError("incorrect search space.")
          return categorical_dict
      return None
  
imports: import json
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: generate_pcs(nni_search_space_content) and returns: None, categorical_dict