class_docstr: Tune driver
docstr: Do necessary preparations for the engine
  :param data: data for training
         Pandas Dataframe:
             a Pandas dataframe for training
         Numpy ndarray:
             a tuple in form of (x, y)
                  x: ndarray for training input
                  y: ndarray for training output
         Spark Dataframe:
             a Spark Dataframe for training
  :param model_builder: model creation function
  :param epochs: max epochs for training
  :param validation_data: validation data
  :param metric: metric name or metric function
  :param metric_mode: mode for metric. "min" or "max". We would infer metric_mode automated
      if user used our built-in metric in bigdl.automl.common.metric.Evaluator.
  :param metric_threshold: a trial will be terminated when metric threshold is met
  :param n_sampling: number of sampling
  :param search_space: a dictionary of search_space
  :param search_alg: str, all supported searcher provided by ray tune
         (i.e."variant_generator", "random", "ax", "dragonfly", "skopt",
         "hyperopt", "bayesopt", "bohb", "nevergrad", "optuna", "zoopt" and
         "sigopt")
  :param search_alg_params: extra parameters for searcher algorithm
  :param scheduler: str, all supported scheduler provided by ray tune
  :param scheduler_params: parameters for scheduler
  :param mc: if calculate uncertainty
  :param feature_cols: feature column names if data is Spark DataFrame.
  :param label_cols: target column names if data is Spark DataFrame.
docstr_tok: ["Do","necessary","preparations","for","the","engine",":","param","data",":","data","for","training","Pandas","Dataframe",":","a","Pandas","dataframe","for","training","Numpy","ndarray",":","a","tuple","in","form","of","(","x",",","y",")","x",":","ndarray","for","training","input","y",":","ndarray","for","training","output","Spark","Dataframe",":","a","Spark","Dataframe","for","training",":","param","model_builder",":","model","creation","function",":","param","epochs",":","max","epochs","for","training",":","param","validation_data",":","validation","data",":","param","metric",":","metric","name","or","metric","function",":","param","metric_mode",":","mode","for","metric",".","``","min","''","or","``","max","''",".","We","would","infer","metric_mode","automated","if","user","used","our","built-in","metric","in","bigdl.automl.common.metric.Evaluator",".",":","param","metric_threshold",":","a","trial","will","be","terminated","when","metric","threshold","is","met",":","param","n_sampling",":","number","of","sampling",":","param","search_space",":","a","dictionary","of","search_space",":","param","search_alg",":","str",",","all","supported","searcher","provided","by","ray","tune","(","i.e",".","``","variant_generator","''",",","``","random","''",",","``","ax","''",",","``","dragonfly","''",",","``","skopt","''",",","``","hyperopt","''",",","``","bayesopt","''",",","``","bohb","''",",","``","nevergrad","''",",","``","optuna","''",",","``","zoopt","''","and","``","sigopt","''",")",":","param","search_alg_params",":","extra","parameters","for","searcher","algorithm",":","param","scheduler",":","str",",","all","supported","scheduler","provided","by","ray","tune",":","param","scheduler_params",":","parameters","for","scheduler",":","param","mc",":","if","calculate","uncertainty",":","param","feature_cols",":","feature","column","names","if","data","is","Spark","DataFrame",".",":","param","label_cols",":","target","column","names","if","data","is","Spark","DataFrame","."]
code: def compile(
      self,
      data,
      model_builder,
      metric_mode,
      epochs=1,
      validation_data=None,
      metric=None,
      metric_threshold=None,
      n_sampling=1,
      search_space=None,
      search_alg=None,
      search_alg_params=None,
      scheduler=None,
      scheduler_params=None,
      mc=False,
      feature_cols=None,
      label_cols=None,
  ):
      """
      Do necessary preparations for the engine
      :param data: data for training
             Pandas Dataframe:
                 a Pandas dataframe for training
             Numpy ndarray:
                 a tuple in form of (x, y)
                      x: ndarray for training input
                      y: ndarray for training output
             Spark Dataframe:
                 a Spark Dataframe for training
      :param model_builder: model creation function
      :param epochs: max epochs for training
      :param validation_data: validation data
      :param metric: metric name or metric function
      :param metric_mode: mode for metric. "min" or "max". We would infer metric_mode automated
          if user used our built-in metric in bigdl.automl.common.metric.Evaluator.
      :param metric_threshold: a trial will be terminated when metric threshold is met
      :param n_sampling: number of sampling
      :param search_space: a dictionary of search_space
      :param search_alg: str, all supported searcher provided by ray tune
             (i.e."variant_generator", "random", "ax", "dragonfly", "skopt",
             "hyperopt", "bayesopt", "bohb", "nevergrad", "optuna", "zoopt" and
             "sigopt")
      :param search_alg_params: extra parameters for searcher algorithm
      :param scheduler: str, all supported scheduler provided by ray tune
      :param scheduler_params: parameters for scheduler
      :param mc: if calculate uncertainty
      :param feature_cols: feature column names if data is Spark DataFrame.
      :param label_cols: target column names if data is Spark DataFrame.
      """
      # metric and metric's mode
      self.metric_name = (
          metric.__name__
          if callable(metric)
          else (metric or DEFAULT_METRIC_NAME)
      )
      self.mode = metric_mode
      self.stopper = TrialStopper(
          metric_threshold=metric_threshold,
          epochs=epochs,
          metric=self.metric_name,
          mode=self.mode,
      )
      self.num_samples = n_sampling
      self.search_space = search_space
  
      self._search_alg = RayTuneSearchEngine._set_search_alg(
          search_alg, search_alg_params, self.metric_name, self.mode
      )
      self._scheduler = RayTuneSearchEngine._set_scheduler(
          scheduler, scheduler_params, self.metric_name, self.mode
      )
      metric_func = None if not callable(metric) else metric
      self.train_func = self._prepare_train_func(
          data=data,
          model_builder=model_builder,
          validation_data=validation_data,
          metric_name=self.metric_name,
          metric_func=metric_func,
          mode=self.mode,
          mc=mc,
          remote_dir=self.remote_dir,
          resources_per_trial=self.resources_per_trial,
          feature_cols=feature_cols,
          label_cols=label_cols,
      )
  
imports: import ray
  from ray import tune
  import os
  from bigdl.orca.automl.search.base import SearchEngine, TrialOutput, GoodError
  from bigdl.orca.automl.search.parameters import DEFAULT_LOGGER_NAME, DEFAULT_METRIC_NAME
  from bigdl.orca.automl.search.ray_tune.utils import convert_bayes_configs
  from bigdl.orca.automl.search.utils import get_ckpt_hdfs, put_ckpt_hdfs
  from ray.tune import Stopper
  from bigdl.orca.automl.model.abstract import ModelBuilder
  from bigdl.orca.data import ray_xshards
  from ray.tune.progress_reporter import TrialProgressCallback
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 3 for calling the RayTuneSearchEngine obj's underlying member method code with example usage: obj.compile(data, model_builder, metric_mode, epochs, validation_data, metric, metric_threshold, n_sampling, search_space, search_alg, search_alg_params, scheduler, scheduler_params, mc, feature_cols, label_cols) without return types