code: def convert_nas_search_space(search_space):
      """
      Args:
          param search_space: raw search space
          return: the new search space, mutable_layers will be converted into choice
      """
      if not isinstance(search_space, dict):
          return search_space
      ret = dict()
      for k, v in search_space.items():
          if "_type" not in v:
              # this should not happen
              _logger.warning(
                  "There is no _type in one of your search space values with key '%s'"
                  ". Please check your search space",
                  k,
              )
              ret[k] = v
          elif v["_type"] != "mutable_layer":
              ret[k] = v
          else:
              _logger.info(
                  "Converting mutable_layer search space with key '%s'",
                  k,
              )
              # v["_value"] looks like {'mutable_layer_1': {'layer_choice': ...} ...}
              values = v["_value"]
              for layer_name, layer_data in values.items():
                  # there should be at most layer_choice, optional_inputs, optional_input_size in layer_data
  
                  # add "_mutable_layer" as prefix so that they can be recovered later
                  layer_key = _construct_general_key(k, layer_name)
  
                  if layer_data.get(
                      "layer_choice"
                  ):  # filter out empty choice and no choice
                      layer_choice = layer_data["layer_choice"]
                  else:
                      raise ValueError(
                          "No layer choice found in %s" % layer_key
                      )
  
                  if layer_data.get("optional_input_size"):
                      input_size = layer_data["optional_input_size"]
                      if isinstance(input_size, int):
                          input_size = [input_size, input_size]
                      if (
                          input_size[0] > input_size[1]
                          or input_size[0] < 0
                      ):
                          _logger.error(
                              "Might not be able to handle optional_input_size < 0, please double check"
                          )
                      input_size[1] += 1
                  else:
                      _logger.info(
                          "Optional input choices are set to empty by default in %s",
                          layer_key,
                      )
                      input_size = [0, 1]
  
                  if layer_data.get("optional_inputs"):
                      total_state_size = len(
                          layer_data["optional_inputs"]
                      ) ** (input_size[1] - 1)
                  else:
                      _logger.info(
                          "Optional inputs not found in %s", layer_key
                      )
                      total_state_size = 1
  
                  converted = {
                      layer_key
                      + "/layer_choice": {
                          "_type": "choice",
                          "_value": layer_choice,
                      },
                      layer_key
                      + "/optional_input_size": {
                          "_type": "randint",
                          "_value": input_size,
                      },
                      layer_key
                      + "/optional_input_chosen_state": {
                          "_type": "randint",
                          "_value": [0, total_state_size],
                      },
                  }
                  _logger.info(converted)
                  ret.update(converted)
  
      return ret
  
file_path: nni/nni/common/nas_utils.py
imports: import functools
  import logging
  from ..None import trial
label_desc: Use image node_id 11 for calling a global function with example usage: convert_nas_search_space(search_space) and returns: ret, search_space