code: def set_experiment_v1(
      experiment_config, mode, port, config_file_name
  ):
      """Call startExperiment (rest POST /experiment) with yaml file content"""
      request_data = dict()
      request_data["authorName"] = experiment_config["authorName"]
      request_data["experimentName"] = experiment_config[
          "experimentName"
      ]
      request_data["trialConcurrency"] = experiment_config[
          "trialConcurrency"
      ]
      request_data["maxExecDuration"] = experiment_config[
          "maxExecDuration"
      ]
      request_data["maxExperimentDuration"] = (
          str(experiment_config["maxExecDuration"]) + "s"
      )
      request_data["maxTrialNum"] = experiment_config["maxTrialNum"]
      request_data["maxTrialDuration"] = experiment_config[
          "maxTrialDuration"
      ]
      request_data["maxTrialNumber"] = experiment_config["maxTrialNum"]
      request_data["searchSpace"] = experiment_config.get("searchSpace")
      request_data["trainingServicePlatform"] = experiment_config.get(
          "trainingServicePlatform"
      )
      # hack for hotfix, fix config.trainingService undefined error, need refactor
      request_data["trainingService"] = {
          "platform": experiment_config.get("trainingServicePlatform")
      }
      if experiment_config.get("description"):
          request_data["description"] = experiment_config["description"]
      if experiment_config.get("multiPhase"):
          request_data["multiPhase"] = experiment_config.get(
              "multiPhase"
          )
      if experiment_config.get("multiThread"):
          request_data["multiThread"] = experiment_config.get(
              "multiThread"
          )
      if experiment_config.get("nniManagerIp"):
          request_data["nniManagerIp"] = experiment_config.get(
              "nniManagerIp"
          )
      if experiment_config.get("advisor"):
          request_data["advisor"] = experiment_config["advisor"]
          if request_data["advisor"].get("gpuNum"):
              print_error(
                  "gpuNum is deprecated, please use gpuIndices instead."
              )
          if request_data["advisor"].get("gpuIndices") and isinstance(
              request_data["advisor"].get("gpuIndices"), int
          ):
              request_data["advisor"]["gpuIndices"] = str(
                  request_data["advisor"].get("gpuIndices")
              )
      else:
          request_data["tuner"] = experiment_config["tuner"]
          if request_data["tuner"].get("gpuNum"):
              print_error(
                  "gpuNum is deprecated, please use gpuIndices instead."
              )
          if request_data["tuner"].get("gpuIndices") and isinstance(
              request_data["tuner"].get("gpuIndices"), int
          ):
              request_data["tuner"]["gpuIndices"] = str(
                  request_data["tuner"].get("gpuIndices")
              )
          if "assessor" in experiment_config:
              request_data["assessor"] = experiment_config["assessor"]
              if request_data["assessor"].get("gpuNum"):
                  print_error(
                      "gpuNum is deprecated, please remove it from your config file."
                  )
      # debug mode should disable version check
      if experiment_config.get("debug") is not None:
          request_data["versionCheck"] = not experiment_config.get(
              "debug"
          )
      # validate version check
      if experiment_config.get("versionCheck") is not None:
          request_data["versionCheck"] = experiment_config.get(
              "versionCheck"
          )
      if experiment_config.get("logCollection"):
          request_data["logCollection"] = experiment_config.get(
              "logCollection"
          )
      request_data["clusterMetaData"] = []
      if experiment_config["trainingServicePlatform"] == "kubeflow":
          request_data["clusterMetaData"].append(
              {
                  "key": "kubeflow_config",
                  "value": experiment_config["kubeflowConfig"],
              }
          )
          request_data["clusterMetaData"].append(
              {
                  "key": "trial_config",
                  "value": experiment_config["trial"],
              }
          )
      elif (
          experiment_config["trainingServicePlatform"]
          == "frameworkcontroller"
      ):
          request_data["clusterMetaData"].append(
              {
                  "key": "frameworkcontroller_config",
                  "value": experiment_config[
                      "frameworkcontrollerConfig"
                  ],
              }
          )
          request_data["clusterMetaData"].append(
              {
                  "key": "trial_config",
                  "value": experiment_config["trial"],
              }
          )
      elif experiment_config["trainingServicePlatform"] == "adl":
          request_data["clusterMetaData"].append(
              {
                  "key": "trial_config",
                  "value": experiment_config["trial"],
              }
          )
      response = rest_post(
          experiment_url(port),
          json.dumps(request_data),
          REST_TIME_OUT,
          show_error=True,
      )
      if check_response(response):
          return response
      else:
          _, stderr_full_path = get_log_path(config_file_name)
          if response is not None:
              with open(stderr_full_path, "a+") as fout:
                  fout.write(
                      json.dumps(
                          json.loads(response.text),
                          indent=4,
                          sort_keys=True,
                          separators=(",", ":"),
                      )
                  )
              print_error(
                  "Setting experiment error, error message is {}".format(
                      response.text
                  )
              )
          return None
  
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 12 for calling a global function with example usage: set_experiment_v1(experiment_config, mode, port, config_file_name) and returns: response, None