code: def launch_experiment(
      args, experiment_config, mode, experiment_id, config_version
  ):
      """follow steps to start rest server and start experiment"""
      # check packages for tuner
      package_name, module_name = None, None
      if experiment_config.get("tuner") and experiment_config[
          "tuner"
      ].get("builtinTunerName"):
          package_name = experiment_config["tuner"]["builtinTunerName"]
          module_name, _ = get_builtin_module_class_name(
              "tuners", package_name
          )
      elif experiment_config.get("advisor") and experiment_config[
          "advisor"
      ].get("builtinAdvisorName"):
          package_name = experiment_config["advisor"][
              "builtinAdvisorName"
          ]
          module_name, _ = get_builtin_module_class_name(
              "advisors", package_name
          )
      if package_name and module_name:
          try:
              stdout_full_path, stderr_full_path = get_log_path(
                  experiment_id
              )
              with open(stdout_full_path, "a+") as stdout_file, open(
                  stderr_full_path, "a+"
              ) as stderr_file:
                  check_call(
                      [
                          sys.executable,
                          "-c",
                          "import %s" % (module_name),
                      ],
                      stdout=stdout_file,
                      stderr=stderr_file,
                  )
          except CalledProcessError:
              print_error(
                  "some errors happen when import package %s."
                  % (package_name)
              )
              print_log_content(experiment_id)
              if package_name in ["SMAC", "BOHB", "PPOTuner"]:
                  print_error(
                      f"The dependencies for {package_name} can be installed through pip install nni[{package_name}]"
                  )
              raise
      if config_version == 1:
          log_dir = (
              experiment_config["logDir"]
              if experiment_config.get("logDir")
              else NNI_HOME_DIR
          )
      else:
          log_dir = (
              experiment_config["experimentWorkingDirectory"]
              if experiment_config.get("experimentWorkingDirectory")
              else NNI_HOME_DIR
          )
      log_level = (
          experiment_config["logLevel"]
          if experiment_config.get("logLevel")
          else "info"
      )
      # view experiment mode do not need debug function, when view an experiment, there will be no new logs created
      foreground = False
      if mode != "view":
          foreground = args.foreground
          if log_level not in ["trace", "debug"] and (
              args.debug or experiment_config.get("debug") is True
          ):
              log_level = "debug"
      # start rest server
      if config_version == 1:
          platform = experiment_config["trainingServicePlatform"]
      elif isinstance(experiment_config["trainingService"], list):
          platform = "hybrid"
      else:
          platform = experiment_config["trainingService"]["platform"]
  
      rest_process, start_time = start_rest_server(
          args.port,
          platform,
          mode,
          experiment_id,
          foreground,
          log_dir,
          log_level,
          args.url_prefix,
      )
      # save experiment information
      Experiments().add_experiment(
          experiment_id,
          args.port,
          start_time,
          platform,
          experiment_config.get("experimentName", "N/A"),
          pid=rest_process.pid,
          logDir=log_dir,
          prefixUrl=args.url_prefix,
      )
      # Deal with annotation
      if experiment_config.get("useAnnotation"):
          print_error(
              "You are using annotation to specify search space. This is not supported since NNI v3.0."
          )
          exit(1)
      elif config_version == 1:
          if experiment_config.get("searchSpacePath"):
              search_space = get_json_content(
                  experiment_config.get("searchSpacePath")
              )
              experiment_config["searchSpace"] = search_space
          else:
              experiment_config["searchSpace"] = ""
  
      # check rest server
      running, _ = check_rest_server(args.port)
      if running:
          print_normal("Successfully started Restful server!")
      else:
          print_error("Restful server start failed!")
          print_log_content(experiment_id)
          try:
              kill_command(rest_process.pid)
          except Exception:
              raise Exception(ERROR_INFO % "Rest server stopped!")
          exit(1)
      if config_version == 1 and mode != "view":
          # set platform configuration
          set_platform_config(
              experiment_config["trainingServicePlatform"],
              experiment_config,
              args.port,
              experiment_id,
              rest_process,
          )
  
      # start a new experiment
      print_normal("Starting experiment...")
      # set debug configuration
      if mode != "view" and experiment_config.get("debug") is None:
          experiment_config["debug"] = args.debug
      if config_version == 1:
          response = set_experiment_v1(
              experiment_config, mode, args.port, experiment_id
          )
      else:
          response = set_experiment_v2(
              experiment_config, mode, args.port, experiment_id
          )
      if response:
          if experiment_id is None:
              experiment_id = json.loads(response.text).get(
                  "experiment_id"
              )
      else:
          print_error("Start experiment failed!")
          print_log_content(experiment_id)
          try:
              kill_command(rest_process.pid)
          except Exception:
              raise Exception(ERROR_INFO % "Restful server stopped!")
          exit(1)
      url_prefix_format = (
          ""
          if args.url_prefix is None
          else "/{0}".format(args.url_prefix)
      )
      if experiment_config.get("nniManagerIp"):
          web_ui_url_list = [
              "http://{0}:{1}{2}".format(
                  experiment_config["nniManagerIp"],
                  str(args.port),
                  url_prefix_format,
              )
          ]
      else:
          web_ui_url_list = get_local_urls(args.port, url_prefix_format)
      Experiments().update_experiment(
          experiment_id, "webuiUrl", web_ui_url_list
      )
  
      print_normal(
          EXPERIMENT_SUCCESS_INFO
          % (experiment_id, "   ".join(web_ui_url_list))
      )
      if mode != "view" and args.foreground:
          try:
              while True:
                  log_content = (
                      rest_process.stdout.readline()
                      .strip()
                      .decode("utf-8")
                  )
                  print(log_content)
          except KeyboardInterrupt:
              kill_command(rest_process.pid)
              print_normal("Stopping experiment...")
  
imports: import json
  import os
  from pathlib import Path
  import sys
  import string
  import random
  import time
  import re
  from subprocess import Popen, check_call, CalledProcessError, PIPE, STDOUT
  from nni.experiment.config import ExperimentConfig, convert
  from nni.tools.package_utils.tuner_factory import get_builtin_module_class_name
  from .launcher_utils import validate_all_content
  from .rest_utils import rest_put, rest_post, check_rest_server, check_response
  from .url_utils import cluster_metadata_url, experiment_url, get_local_urls, set_prefix_url
  from .config_utils import Config, Experiments
  from .common_utils import get_yml_content, get_json_content, print_error, print_normal, detect_port
  from .constants import NNI_HOME_DIR, ERROR_INFO, REST_TIME_OUT, EXPERIMENT_SUCCESS_INFO, LOG_HEADER
  from .command_utils import check_output_command, kill_command
  from .nnictl_utils import update_experiment
label_desc: Use image node_id 15 for calling a global function with example usage: launch_experiment(args, experiment_config, mode, experiment_id, config_version) without return types