class_docstr: Util class for setting up and logging to MLflow.
  
  Use this util for any library that needs MLflow logging/tracking logic
  such as Ray Tune or Ray Train.
class_docstr_tok: ["Util","class","for","setting","up","and","logging","to","MLflow",".","Use","this","util","for","any","library","that","needs","MLflow","logging\/tracking","logic","such","as","Ray","Tune","or","Ray","Train","."]
docstr: Sets up MLflow.
  
  Sets the Mlflow tracking uri & token, and registry URI. Also sets
  the MLflow experiment that the logger should use, and possibly
  creates new experiment if it does not exist.
  
  Args:
      tracking_uri: The tracking URI for the MLflow tracking
          server.
      registry_uri: The registry URI for the MLflow model registry.
      experiment_id: The id of an already existing MLflow
          experiment to use for logging. If None is passed in
          here and the MFLOW_EXPERIMENT_ID is not set, or the
          experiment with this id does not exist,
          ``experiment_name`` will be used instead. This argument takes
          precedence over ``experiment_name`` if both are passed in.
      experiment_name: The experiment name to use for logging.
          If None is passed in here, the MLFLOW_EXPERIMENT_NAME environment
          variable is used to determine the experiment name.
          If the experiment with the name already exists with MLflow,
          it will be reused. If not, a new experiment will be created
          with the provided name if
          ``create_experiment_if_not_exists`` is set to True.
      artifact_location: The location to store run artifacts.
          If not provided, MLFlow picks an appropriate default.
          Ignored if experiment already exists.
      tracking_token: Tracking token used to authenticate with MLflow.
      create_experiment_if_not_exists: Whether to create an
          experiment with the provided name if it does not already
          exist. Defaults to True.
  
  Returns:
      Whether setup is successful.
docstr_tok: ["Sets","up","MLflow",".","Sets","the","Mlflow","tracking","uri","&","token",",","and","registry","URI",".","Also","sets","the","MLflow","experiment","that","the","logger","should","use",",","and","possibly","creates","new","experiment","if","it","does","not","exist",".","Args",":","tracking_uri",":","The","tracking","URI","for","the","MLflow","tracking","server",".","registry_uri",":","The","registry","URI","for","the","MLflow","model","registry",".","experiment_id",":","The","id","of","an","already","existing","MLflow","experiment","to","use","for","logging",".","If","None","is","passed","in","here","and","the","MFLOW_EXPERIMENT_ID","is","not","set",",","or","the","experiment","with","this","id","does","not","exist",",","``","experiment_name","``","will","be","used","instead",".","This","argument","takes","precedence","over","``","experiment_name","``","if","both","are","passed","in",".","experiment_name",":","The","experiment","name","to","use","for","logging",".","If","None","is","passed","in","here",",","the","MLFLOW_EXPERIMENT_NAME","environment","variable","is","used","to","determine","the","experiment","name",".","If","the","experiment","with","the","name","already","exists","with","MLflow",",","it","will","be","reused",".","If","not",",","a","new","experiment","will","be","created","with","the","provided","name","if","``","create_experiment_if_not_exists","``","is","set","to","True",".","artifact_location",":","The","location","to","store","run","artifacts",".","If","not","provided",",","MLFlow","picks","an","appropriate","default",".","Ignored","if","experiment","already","exists",".","tracking_token",":","Tracking","token","used","to","authenticate","with","MLflow",".","create_experiment_if_not_exists",":","Whether","to","create","an","experiment","with","the","provided","name","if","it","does","not","already","exist",".","Defaults","to","True",".","Returns",":","Whether","setup","is","successful","."]
code: def setup_mlflow(
      self,
      tracking_uri: Optional[str] = None,
      registry_uri: Optional[str] = None,
      experiment_id: Optional[str] = None,
      experiment_name: Optional[str] = None,
      tracking_token: Optional[str] = None,
      artifact_location: Optional[str] = None,
      create_experiment_if_not_exists: bool = True,
  ):
      """
      Sets up MLflow.
  
      Sets the Mlflow tracking uri & token, and registry URI. Also sets
      the MLflow experiment that the logger should use, and possibly
      creates new experiment if it does not exist.
  
      Args:
          tracking_uri: The tracking URI for the MLflow tracking
              server.
          registry_uri: The registry URI for the MLflow model registry.
          experiment_id: The id of an already existing MLflow
              experiment to use for logging. If None is passed in
              here and the MFLOW_EXPERIMENT_ID is not set, or the
              experiment with this id does not exist,
              ``experiment_name`` will be used instead. This argument takes
              precedence over ``experiment_name`` if both are passed in.
          experiment_name: The experiment name to use for logging.
              If None is passed in here, the MLFLOW_EXPERIMENT_NAME environment
              variable is used to determine the experiment name.
              If the experiment with the name already exists with MLflow,
              it will be reused. If not, a new experiment will be created
              with the provided name if
              ``create_experiment_if_not_exists`` is set to True.
          artifact_location: The location to store run artifacts.
              If not provided, MLFlow picks an appropriate default.
              Ignored if experiment already exists.
          tracking_token: Tracking token used to authenticate with MLflow.
          create_experiment_if_not_exists: Whether to create an
              experiment with the provided name if it does not already
              exist. Defaults to True.
  
      Returns:
          Whether setup is successful.
      """
      if tracking_token:
          os.environ["MLFLOW_TRACKING_TOKEN"] = tracking_token
  
      self._mlflow.set_tracking_uri(tracking_uri)
      self._mlflow.set_registry_uri(registry_uri)
  
      # First check experiment_id.
      experiment_id = (
          experiment_id
          if experiment_id is not None
          else os.environ.get("MLFLOW_EXPERIMENT_ID")
      )
      if experiment_id is not None:
          from mlflow.exceptions import MlflowException
  
          try:
              self._mlflow.get_experiment(experiment_id=experiment_id)
              logger.debug(
                  f"Experiment with provided id {experiment_id} "
                  "exists. Setting that as the experiment."
              )
              self.experiment_id = experiment_id
              return
          except MlflowException:
              pass
  
      # Then check experiment_name.
      experiment_name = (
          experiment_name
          if experiment_name is not None
          else os.environ.get("MLFLOW_EXPERIMENT_NAME")
      )
      if (
          experiment_name is not None
          and self._mlflow.get_experiment_by_name(name=experiment_name)
      ):
          logger.debug(
              f"Experiment with provided name {experiment_name} "
              "exists. Setting that as the experiment."
          )
          self.experiment_id = self._mlflow.get_experiment_by_name(
              experiment_name
          ).experiment_id
          return
  
      # An experiment with the provided id or name does not exist.
      # Create a new experiment if applicable.
      if experiment_name and create_experiment_if_not_exists:
          logger.debug(
              "Existing experiment not found. Creating new "
              f"experiment with name: {experiment_name}"
          )
          self.experiment_id = self._mlflow.create_experiment(
              name=experiment_name, artifact_location=artifact_location
          )
          return
  
      if create_experiment_if_not_exists:
          raise ValueError(
              f"Experiment with the provided experiment_id: "
              f"{experiment_id} does not exist and no "
              f"experiment_name provided. At least one of "
              f"these has to be provided."
          )
      else:
          raise ValueError(
              f"Experiment with the provided experiment_id: "
              f"{experiment_id} or experiment_name: "
              f"{experiment_name} does not exist. Please "
              f"create an MLflow experiment and provide "
              f"either its id or name."
          )
  
file_path: ray/python/ray/air/_internal/mlflow.py
imports: import logging
  import os
  from packaging import version
  from copy import deepcopy
  from typing import TYPE_CHECKING, Dict, Optional
  from ray._private.dict import flatten_dict
label_desc: Use image node_id 3 for calling the _MLflowLoggerUtil obj's underlying member method code with example usage: obj.setup_mlflow(tracking_uri, registry_uri, experiment_id, experiment_name, tracking_token, artifact_location, create_experiment_if_not_exists) without return types