class_docstr: A wrapper around ZOOpt to provide trial suggestions.
  
  ZOOptSearch is a library for derivative-free optimization. It is backed by
  the `ZOOpt <https://github.com/polixir/ZOOpt>`__ package. Currently,
  Asynchronous Sequential RAndomized COordinate Shrinking (ASRacos)
  is implemented in Tune.
  
  To use ZOOptSearch, install zoopt (>=0.4.1): ``pip install -U zoopt``.
  
  Tune automatically converts search spaces to ZOOpt"s format:
  
  .. code-block:: python
  
      from ray import train, tune
      from ray.tune.search.zoopt import ZOOptSearch
  
      "config": {
          "iterations": 10,  # evaluation times
          "width": tune.uniform(-10, 10),
          "height": tune.uniform(-10, 10)
      }
  
      zoopt_search_config = {
          "parallel_num": 8,  # how many workers to parallel
      }
  
      zoopt_search = ZOOptSearch(
          algo="Asracos",  # only support Asracos currently
          budget=20,  # must match `num_samples` in `tune.TuneConfig()`.
          dim_dict=dim_dict,
          metric="mean_loss",
          mode="min",
          **zoopt_search_config
      )
  
      tuner = tune.Tuner(
          my_objective,
          tune_config=tune.TuneConfig(
              search_alg=zoopt_search,
              num_samples=20
          ),
          run_config=train.RunConfig(
              name="zoopt_search",
              stop={"timesteps_total": 10}
          ),
          param_space=config
      )
      tuner.fit()
  
  If you would like to pass the search space manually, the code would
  look like this:
  
  .. code-block:: python
  
      from ray import train, tune
      from ray.tune.search.zoopt import ZOOptSearch
      from zoopt import ValueType
  
      dim_dict = {
          "height": (ValueType.CONTINUOUS, [-10, 10], 1e-2),
          "width": (ValueType.DISCRETE, [-10, 10], False),
          "layers": (ValueType.GRID, [4, 8, 16])
      }
  
      "config": {
          "iterations": 10,  # evaluation times
      }
  
      zoopt_search_config = {
          "parallel_num": 8,  # how many workers to parallel
      }
  
      zoopt_search = ZOOptSearch(
          algo="Asracos",  # only support Asracos currently
          budget=20,  # must match `num_samples` in `tune.TuneConfig()`.
          dim_dict=dim_dict,
          metric="mean_loss",
          mode="min",
          **zoopt_search_config
      )
  
      tuner = tune.Tuner(
          my_objective,
          tune_config=tune.TuneConfig(
              search_alg=zoopt_search,
              num_samples=20
          ),
          run_config=train.RunConfig(
              name="zoopt_search",
              stop={"timesteps_total": 10}
          ),
      )
      tuner.fit()
  
  Parameters:
      algo: To specify an algorithm in zoopt you want to use.
          Only support ASRacos currently.
      budget: Number of samples.
      dim_dict: Dimension dictionary.
          For continuous dimensions: (continuous, search_range, precision);
          For discrete dimensions: (discrete, search_range, has_order);
          For grid dimensions: (grid, grid_list).
          More details can be found in zoopt package.
      metric: The training result objective value attribute. If None
          but a mode was passed, the anonymous metric `_metric` will be used
          per default.
      mode: One of {min, max}. Determines whether objective is
          minimizing or maximizing the metric attribute.
      points_to_evaluate: Initial parameter suggestions to be run
          first. This is for when you already have some good parameters
          you want to run first to help the algorithm make better suggestions
          for future parameters. Needs to be a list of dicts containing the
          configurations.
      parallel_num: How many workers to parallel. Note that initial
          phase may start less workers than this number. More details can
          be found in zoopt package.
class_docstr_tok: ["A","wrapper","around","ZOOpt","to","provide","trial","suggestions",".","ZOOptSearch","is","a","library","for","derivative-free","optimization",".","It","is","backed","by","the","`","ZOOpt","<","https",":","\/\/github.com\/polixir\/ZOOpt",">","`","__","package",".","Currently",",","Asynchronous","Sequential","RAndomized","COordinate","Shrinking","(","ASRacos",")","is","implemented","in","Tune",".","To","use","ZOOptSearch",",","install","zoopt","(",">","=0.4.1",")",":","``","pip","install","-U","zoopt","``",".","Tune","automatically","converts","search","spaces","to","ZOOpt","''","s","format",":","..","code-block",":",":","python","from","ray","import","train",",","tune","from","ray.tune.search.zoopt","import","ZOOptSearch","``","config","''",":","{","``","iterations","''",":","10",",","#","evaluation","times","``","width","''",":","tune.uniform","(","-10",",","10",")",",","``","height","''",":","tune.uniform","(","-10",",","10",")","}","zoopt_search_config","=","{","``","parallel_num","''",":","8",",","#","how","many","workers","to","parallel","}","zoopt_search","=","ZOOptSearch","(","algo=","''","Asracos","''",",","#","only","support","Asracos","currently","budget=20",",","#","must","match","`","num_samples","`","in","`","tune.TuneConfig","(",")","`",".","dim_dict=dim_dict",",","metric=","''","mean_loss","''",",","mode=","''","min","''",",","*","*","zoopt_search_config",")","tuner","=","tune.Tuner","(","my_objective",",","tune_config=tune.TuneConfig","(","search_alg=zoopt_search",",","num_samples=20",")",",","run_config=train.RunConfig","(","name=","''","zoopt_search","''",",","stop=","{","``","timesteps_total","''",":","10","}",")",",","param_space=config",")","tuner.fit","(",")","If","you","would","like","to","pass","the","search","space","manually",",","the","code","would","look","like","this",":","..","code-block",":",":","python","from","ray","import","train",",","tune","from","ray.tune.search.zoopt","import","ZOOptSearch","from","zoopt","import","ValueType","dim_dict","=","{","``","height","''",":","(","ValueType.CONTINUOUS",",","[","-10",",","10","]",",","1e-2",")",",","``","width","''",":","(","ValueType.DISCRETE",",","[","-10",",","10","]",",","False",")",",","``","layers","''",":","(","ValueType.GRID",",","[","4",",","8",",","16","]",")","}","``","config","''",":","{","``","iterations","''",":","10",",","#","evaluation","times","}","zoopt_search_config","=","{","``","parallel_num","''",":","8",",","#","how","many","workers","to","parallel","}","zoopt_search","=","ZOOptSearch","(","algo=","''","Asracos","''",",","#","only","support","Asracos","currently","budget=20",",","#","must","match","`","num_samples","`","in","`","tune.TuneConfig","(",")","`",".","dim_dict=dim_dict",",","metric=","''","mean_loss","''",",","mode=","''","min","''",",","*","*","zoopt_search_config",")","tuner","=","tune.Tuner","(","my_objective",",","tune_config=tune.TuneConfig","(","search_alg=zoopt_search",",","num_samples=20",")",",","run_config=train.RunConfig","(","name=","''","zoopt_search","''",",","stop=","{","``","timesteps_total","''",":","10","}",")",",",")","tuner.fit","(",")","Parameters",":","algo",":","To","specify","an","algorithm","in","zoopt","you","want","to","use",".","Only","support","ASRacos","currently",".","budget",":","Number","of","samples",".","dim_dict",":","Dimension","dictionary",".","For","continuous","dimensions",":","(","continuous",",","search_range",",","precision",")",";","For","discrete","dimensions",":","(","discrete",",","search_range",",","has_order",")",";","For","grid","dimensions",":","(","grid",",","grid_list",")",".","More","details","can","be","found","in","zoopt","package",".","metric",":","The","training","result","objective","value","attribute",".","If","None","but","a","mode","was","passed",",","the","anonymous","metric","`","_metric","`","will","be","used","per","default",".","mode",":","One","of","{","min",",","max","}",".","Determines","whether","objective","is","minimizing","or","maximizing","the","metric","attribute",".","points_to_evaluate",":","Initial","parameter","suggestions","to","be","run","first",".","This","is","for","when","you","already","have","some","good","parameters","you","want","to","run","first","to","help","the","algorithm","make","better","suggestions","for","future","parameters",".","Needs","to","be","a","list","of","dicts","containing","the","configurations",".","parallel_num",":","How","many","workers","to","parallel",".","Note","that","initial","phase","may","start","less","workers","than","this","number",".","More","details","can","be","found","in","zoopt","package","."]
code: def _setup_zoopt(self):
      if self._metric is None and self._mode:
          # If only a mode was passed, use anonymous metric
          self._metric = DEFAULT_METRIC
  
      _dim_list = []
      for k in self._dim_dict:
          self._dim_keys.append(k)
          _dim_list.append(self._dim_dict[k])
  
      init_samples = None
      if self._points_to_evaluate:
          logger.warning(
              "`points_to_evaluate` is ignored by ZOOpt in versions <= 0.4.1."
          )
          init_samples = [
              Solution(x=tuple(point[dim] for dim in self._dim_keys))
              for point in self._points_to_evaluate
          ]
      dim = zoopt.Dimension2(_dim_list)
      par = zoopt.Parameter(
          budget=self._budget, init_samples=init_samples
      )
      if self._algo == "sracos" or self._algo == "asracos":
          from zoopt.algos.opt_algorithms.racos.sracos import SRacosTune
  
          self.optimizer = SRacosTune(
              dimension=dim,
              parameter=par,
              parallel_num=self.parallel_num,
              **self.kwargs,
          )
  
file_path: ray/python/ray/tune/search/zoopt/zoopt_search.py
imports: import copy
  import logging
  from typing import Dict, List, Optional, Tuple
  import ray
  import ray.cloudpickle
  from ray.tune.result import DEFAULT_METRIC
  from ray.tune.search.sample import Categorical, Domain, Float, Integer, Quantized, Uniform
  from ray.tune.search import UNRESOLVED_SEARCH_SPACE, UNDEFINED_METRIC_MODE, UNDEFINED_SEARCH_SPACE, Searcher
  from ray.tune.search.variant_generator import parse_spec_vars
  from ray.tune.utils.util import unflatten_dict
label_desc: Use image node_id 2 for calling the ZOOptSearch obj's underlying member method code with example usage: obj._setup_zoopt() without return types