docstr: The main process of optimizing the HP by the method within give model and HP space.
  This process provide an HPO scheme, where giving suggestion and evaluation are taken turns, and can be run on multi-GPU.
  If you want to implement your HPO algorithm, you can either follow this scheme, you should only change "_set_up", "_update_trials", "_get_suggestion", and "_best_hp".
  Or you can rewrite the whole "optimize" function.
  Parameters
  ----------
  trainer : ..train.BaseTrainer
      Including model, giving HP space and using for training
  dataset : ...datasets
      Dataset to train and evaluate.
  time_limit : int
      Max time to run HPO
  memory_limit : None
      No implementation yet
  
  Returns
  -------
  trainer: ..train.BaseTrainer
      The trainer including the best trained model
  para_json: dict
      The best HP
docstr_tok: ["The","main","process","of","optimizing","the","HP","by","the","method","within","give","model","and","HP","space",".","This","process","provide","an","HPO","scheme",",","where","giving","suggestion","and","evaluation","are","taken","turns",",","and","can","be","run","on","multi-GPU",".","If","you","want","to","implement","your","HPO","algorithm",",","you","can","either","follow","this","scheme",",","you","should","only","change","``","_set_up","''",",","``","_update_trials","''",",","``","_get_suggestion","''",",","and","``","_best_hp","''",".","Or","you","can","rewrite","the","whole","``","optimize","''","function",".","Parameters","--","--","--","--","--","trainer",":","..","train.BaseTrainer","Including","model",",","giving","HP","space","and","using","for","training","dataset",":","...","datasets","Dataset","to","train","and","evaluate",".","time_limit",":","int","Max","time","to","run","HPO","memory_limit",":","None","No","implementation","yet","Returns","--","--","--","-","trainer",":","..","train.BaseTrainer","The","trainer","including","the","best","trained","model","para_json",":","dict","The","best","HP"]
code: def optimize(
      self, trainer, dataset, time_limit=None, memory_limit=None
  ):
      """
      The main process of optimizing the HP by the method within give model and HP space.
      This process provide an HPO scheme, where giving suggestion and evaluation are taken turns, and can be run on multi-GPU.
      If you want to implement your HPO algorithm, you can either follow this scheme, you should only change "_set_up", "_update_trials", "_get_suggestion", and "_best_hp".
      Or you can rewrite the whole "optimize" function.
      Parameters
      ----------
      trainer : ..train.BaseTrainer
          Including model, giving HP space and using for training
      dataset : ...datasets
          Dataset to train and evaluate.
      time_limit : int
          Max time to run HPO
      memory_limit : None
          No implementation yet
  
      Returns
      -------
      trainer: ..train.BaseTrainer
          The trainer including the best trained model
      para_json: dict
          The best HP
      """
      start_time = time.time()
      cur_evals = 0
  
      slaves = 2
      pipes = []
      procs = []
      statuses = []
      for i in range(slaves):
          ps, pr = mp.Pipe()
          pipes.append(ps)
          proc = mp.Process(
              target=self.slave,
              args=(
                  pr,
                  trainer,
                  dataset,
              ),
          )
          proc.start()
          procs.append(proc)
          statuses.append("ready")
  
      # do something of the certain HPO algo
      self._set_up(trainer, dataset, slaves, time_limit, memory_limit)
      self.feval_name = trainer.get_feval(
          return_major=True
      ).get_eval_name()
      self.is_higher_better = trainer.get_feval(
          return_major=True
      ).is_higher_better()
  
      while cur_evals < self.max_evals:
          # timeout
          if time.time() - start_time > time_limit:
              self.logger.info(
                  "Time out of limit, Epoch: {}".format(str(cur_evals))
              )
              break
          for i in range(slaves):
              sent = pipes[i].poll()
              if sent or statuses[i] == "ready":
                  if sent:
                      cur_trainer = pipes[i].recv()
                      cur_trainer = dill.loads(cur_trainer)
                      perf = pipes[i].recv()
                      self._update_trials(
                          i, cur_trainer, perf, self.is_higher_better
                      )
                      cur_evals += 1
                      if cur_evals >= self.max_evals:
                          break
                  else:
                      statuses[i] = "running"
                  x = self._get_suggestion(i)
                  pipes[i].send(x)
  
      for i in range(slaves):
          procs[i].terminate()
  
      best_trainer, best_x = self._best_hp()
      if best_x == None:
          raise TimeTooLimitedError(
              "Given time is too limited to finish one round in HPO."
          )
      return best_trainer, best_x
  
imports: from ...utils import get_logger
  import hyperopt
  import time
  import math
  import dill
  import multiprocessing
  import copy
  import random
label_desc: Use image node_id 18 for calling the BaseHPOptimizer obj's underlying member method code with example usage: obj.optimize(trainer, dataset, time_limit, memory_limit) and returns: best_trainer,  best_x