code: def cli():
      title = (
          "ClearML HPO - search for the best parameters for your models"
      )
      print(title)
      parser = ArgumentParser(
          description=title, formatter_class=RawTextHelpFormatter
      )
      setup_parser(parser)
  
      # get the args
      args = parser.parse_args()
  
      if len(sys.argv) < 2:
          parser.print_help()
          exit(0)
  
      Task.init(
          project_name=args.project_name,
          task_name=args.task_name,
          task_type=Task.TaskTypes.optimizer,
          reuse_last_task_id=False,
      )
      task_id = args.task_id
      if not task_id:
          create_populate = CreateAndPopulate(script=args.script)
          create_populate.update_task_args(args.args)
          print("Creating new task")
          create_populate.create_task()
          # update Task args
          create_populate.update_task_args(args.args)
          task_id = create_populate.get_id()
  
      optimizer = HyperParameterOptimizer(
          base_task_id=task_id,
          execution_queue=args.queue,
          hyper_parameters=eval_params_search(
              args.params_search, args.params_override
          ),
          objective_metric_title=args.objective_metric_title,
          objective_metric_series=args.objective_metric_series,
          objective_metric_sign=args.objective_metric_sign,
          optimizer_class=eval_optimizer_class(args.optimizer_class),
          save_top_k_tasks_only=args.save_top_k_tasks_only,
          **build_opt_kwargs(args),
      )
  
      # make sure we sample every 30sec
      optimizer.set_report_period(0.5)
  
      print("Starting HPO process:")
      if args.local:
          optimizer.start_locally()
      else:
          optimizer.start()
  
      optimizer.wait()
      print("Optimization completed!")
      top_experiments_cnt = 10
      if (
          args.save_top_k_tasks_only != -1
          and top_experiments_cnt > args.save_top_k_tasks_only
      ):
          top_experiments_cnt = args.save_top_k_tasks_only
      print("Top {} experiments are: ".format(top_experiments_cnt))
      top_exp = optimizer.get_top_experiments(top_k=top_experiments_cnt)
      print([t.id for t in top_exp])
      optimizer.stop()
  
file_path: clearml/clearml/cli/hpo/__main__.py
imports: import json
  import sys
  from argparse import ArgumentParser, RawTextHelpFormatter
  import clearml.backend_api.session
  from clearml import Task
  from clearml.automation import DiscreteParameterRange, UniformIntegerParameterRange, UniformParameterRange, LogUniformParameterRange, HyperParameterOptimizer, RandomSearch, GridSearch
  from clearml.backend_interface.task.populate import CreateAndPopulate
  from clearml.version import __version__
label_desc: Use image node_id 5 for calling a global function with example usage: cli() without return types