class_docstr: Tuner is the recommended way of launching hyperparameter tuning jobs with Ray Tune.
  
  Args:
      trainable: The trainable to be tuned.
      param_space: Search space of the tuning job.
          One thing to note is that both preprocessor and dataset can be tuned here.
      tune_config: Tuning algorithm specific configs.
          Refer to ray.tune.tune_config.TuneConfig for more info.
      run_config: Runtime configuration that is specific to individual trials.
          If passed, this will overwrite the run config passed to the Trainer,
          if applicable. Refer to ray.train.RunConfig for more info.
  
  Usage pattern:
  
  .. code-block:: python
  
      from sklearn.datasets import load_breast_cancer
  
      from ray import tune
      from ray.data import from_pandas
      from ray.train import RunConfig, ScalingConfig
      from ray.train.xgboost import XGBoostTrainer
      from ray.tune.tuner import Tuner
  
      def get_dataset():
          data_raw = load_breast_cancer(as_frame=True)
          dataset_df = data_raw["data"]
          dataset_df["target"] = data_raw["target"]
          dataset = from_pandas(dataset_df)
          return dataset
  
      trainer = XGBoostTrainer(
          label_column="target",
          params={},
          datasets={"train": get_dataset()},
      )
  
      param_space = {
          "scaling_config": ScalingConfig(
              num_workers=tune.grid_search([2, 4]),
              resources_per_worker={
                  "CPU": tune.grid_search([1, 2]),
              },
          ),
          # You can even grid search various datasets in Tune.
          # "datasets": {
          #     "train": tune.grid_search(
          #         [ds1, ds2]
          #     ),
          # },
          "params": {
              "objective": "binary:logistic",
              "tree_method": "approx",
              "eval_metric": ["logloss", "error"],
              "eta": tune.loguniform(1e-4, 1e-1),
              "subsample": tune.uniform(0.5, 1.0),
              "max_depth": tune.randint(1, 9),
          },
      }
      tuner = Tuner(trainable=trainer, param_space=param_space,
          run_config=RunConfig(name="my_tune_run"))
      results = tuner.fit()
  
  To retry a failed tune run, you can then do
  
  .. code-block:: python
  
      tuner = Tuner.restore(results.experiment_path, trainable=trainer)
      tuner.fit()
  
  ``results.experiment_path`` can be retrieved from the
  :ref:`ResultGrid object <tune-analysis-docs>`. It can
  also be easily seen in the log output from your first run.
class_docstr_tok: ["Tuner","is","the","recommended","way","of","launching","hyperparameter","tuning","jobs","with","Ray","Tune",".","Args",":","trainable",":","The","trainable","to","be","tuned",".","param_space",":","Search","space","of","the","tuning","job",".","One","thing","to","note","is","that","both","preprocessor","and","dataset","can","be","tuned","here",".","tune_config",":","Tuning","algorithm","specific","configs",".","Refer","to","ray.tune.tune_config.TuneConfig","for","more","info",".","run_config",":","Runtime","configuration","that","is","specific","to","individual","trials",".","If","passed",",","this","will","overwrite","the","run","config","passed","to","the","Trainer",",","if","applicable",".","Refer","to","ray.train.RunConfig","for","more","info",".","Usage","pattern",":","..","code-block",":",":","python","from","sklearn.datasets","import","load_breast_cancer","from","ray","import","tune","from","ray.data","import","from_pandas","from","ray.train","import","RunConfig",",","ScalingConfig","from","ray.train.xgboost","import","XGBoostTrainer","from","ray.tune.tuner","import","Tuner","def","get_dataset","(",")",":","data_raw","=","load_breast_cancer","(","as_frame=True",")","dataset_df","=","data_raw","[","``","data","''","]","dataset_df","[","``","target","''","]","=","data_raw","[","``","target","''","]","dataset","=","from_pandas","(","dataset_df",")","return","dataset","trainer","=","XGBoostTrainer","(","label_column=","''","target","''",",","params=","{","}",",","datasets=","{","``","train","''",":","get_dataset","(",")","}",",",")","param_space","=","{","``","scaling_config","''",":","ScalingConfig","(","num_workers=tune.grid_search","(","[","2",",","4","]",")",",","resources_per_worker=","{","``","CPU","''",":","tune.grid_search","(","[","1",",","2","]",")",",","}",",",")",",","#","You","can","even","grid","search","various","datasets","in","Tune",".","#","``","datasets","''",":","{","#","``","train","''",":","tune.grid_search","(","#","[","ds1",",","ds2","]","#",")",",","#","}",",","``","params","''",":","{","``","objective","''",":","``","binary",":","logistic","''",",","``","tree_method","''",":","``","approx","''",",","``","eval_metric","''",":","[","``","logloss","''",",","``","error","''","]",",","``","eta","''",":","tune.loguniform","(","1e-4",",","1e-1",")",",","``","subsample","''",":","tune.uniform","(","0.5",",","1.0",")",",","``","max_depth","''",":","tune.randint","(","1",",","9",")",",","}",",","}","tuner","=","Tuner","(","trainable=trainer",",","param_space=param_space",",","run_config=RunConfig","(","name=","''","my_tune_run","''",")",")","results","=","tuner.fit","(",")","To","retry","a","failed","tune","run",",","you","can","then","do","..","code-block",":",":","python","tuner","=","Tuner.restore","(","results.experiment_path",",","trainable=trainer",")","tuner.fit","(",")","``","results.experiment_path","``","can","be","retrieved","from","the",":","ref",":","`","ResultGrid","object","<","tune-analysis-docs",">","`",".","It","can","also","be","easily","seen","in","the","log","output","from","your","first","run","."]
docstr: Executes hyperparameter tuning job as configured and returns result.
  
  Failure handling:
  For the kind of exception that happens during the execution of a trial,
  one may inspect it together with stacktrace through the returned result grid.
  See ``ResultGrid`` for reference. Each trial may fail up to a certain number.
  This is configured by ``RunConfig.FailureConfig.max_failures``.
  
  Exception that happens beyond trials will be thrown by this method as well.
  In such cases, there will be instruction like the following printed out
  at the end of console output to inform users on how to resume.
  
  Please use `Tuner.restore` to resume.
  
  .. code-block:: python
  
      import os
      from ray.tune import Tuner
  
      trainable = ...
  
      tuner = Tuner.restore(
          os.path.expanduser("~/ray_results/tuner_resume"),
          trainable=trainable
      )
      tuner.fit()
  
  Raises:
      RayTaskError: If user-provided trainable raises an exception
      TuneError: General Ray Tune error.
docstr_tok: ["Executes","hyperparameter","tuning","job","as","configured","and","returns","result",".","Failure","handling",":","For","the","kind","of","exception","that","happens","during","the","execution","of","a","trial",",","one","may","inspect","it","together","with","stacktrace","through","the","returned","result","grid",".","See","``","ResultGrid","``","for","reference",".","Each","trial","may","fail","up","to","a","certain","number",".","This","is","configured","by","``","RunConfig.FailureConfig.max_failures","``",".","Exception","that","happens","beyond","trials","will","be","thrown","by","this","method","as","well",".","In","such","cases",",","there","will","be","instruction","like","the","following","printed","out","at","the","end","of","console","output","to","inform","users","on","how","to","resume",".","Please","use","`","Tuner.restore","`","to","resume",".","..","code-block",":",":","python","import","os","from","ray.tune","import","Tuner","trainable","=","...","tuner","=","Tuner.restore","(","os.path.expanduser","(","``","~\/ray_results\/tuner_resume","''",")",",","trainable=trainable",")","tuner.fit","(",")","Raises",":","RayTaskError",":","If","user-provided","trainable","raises","an","exception","TuneError",":","General","Ray","Tune","error","."]
code: def fit(self) -> ResultGrid:
      """Executes hyperparameter tuning job as configured and returns result.
  
      Failure handling:
      For the kind of exception that happens during the execution of a trial,
      one may inspect it together with stacktrace through the returned result grid.
      See ``ResultGrid`` for reference. Each trial may fail up to a certain number.
      This is configured by ``RunConfig.FailureConfig.max_failures``.
  
      Exception that happens beyond trials will be thrown by this method as well.
      In such cases, there will be instruction like the following printed out
      at the end of console output to inform users on how to resume.
  
      Please use `Tuner.restore` to resume.
  
      .. code-block:: python
  
          import os
          from ray.tune import Tuner
  
          trainable = ...
  
          tuner = Tuner.restore(
              os.path.expanduser("~/ray_results/tuner_resume"),
              trainable=trainable
          )
          tuner.fit()
  
      Raises:
          RayTaskError: If user-provided trainable raises an exception
          TuneError: General Ray Tune error.
      """
  
      if not self._is_ray_client:
          try:
              return self._local_tuner.fit()
          except TuneError as e:
              raise TuneError(
                  _TUNER_FAILED_MSG.format(
                      path=self._local_tuner.get_experiment_checkpoint_dir()
                  )
              ) from e
      else:
          experiment_checkpoint_dir = ray.get(
              self._remote_tuner.get_experiment_checkpoint_dir.remote()
          )
          (
              progress_reporter,
              string_queue,
          ) = (
              self._prepare_remote_tuner_for_jupyter_progress_reporting()
          )
          try:
              fit_future = self._remote_tuner.fit.remote()
              _stream_client_output(
                  fit_future,
                  progress_reporter,
                  string_queue,
              )
              return ray.get(fit_future)
          except TuneError as e:
              raise TuneError(
                  _TUNER_FAILED_MSG.format(
                      path=experiment_checkpoint_dir
                  )
              ) from e
  
imports: import logging
  import os
  from typing import Any, Callable, Dict, Optional, Type, Union, TYPE_CHECKING
  import pyarrow.fs
  import ray
  from ray.air.config import RunConfig
  from ray.air._internal.usage import AirEntrypoint
  from ray.air.util.node import _force_on_current_node
  from ray.train._internal.storage import _exists_at_fs_path, get_fs_and_path
  from ray.tune import TuneError
  from ray.tune.execution.experiment_state import _ResumeConfig
  from ray.tune.experimental.output import get_air_verbosity
  from ray.tune.result_grid import ResultGrid
  from ray.tune.trainable import Trainable
  from ray.tune.impl.tuner_internal import TunerInternal, _TUNER_PKL
  from ray.tune.tune_config import TuneConfig
  from ray.tune.progress_reporter import _prepare_progress_reporter_for_ray_client, _stream_client_output
  from ray.util import PublicAPI
label_desc: Use image node_id 5 for calling the Tuner obj's underlying member method code with example usage: obj.fit() and returns: self, ray