code: def _get_best_trial(
      experiment: Experiment,
      generation_strategy: GenerationStrategy,
      optimization_config: Optional[OptimizationConfig] = None,
      trial_indices: Optional[Iterable[int]] = None,
      use_model_predictions: bool = True,
  ) -> Optional[
      Tuple[int, TParameterization, Optional[TModelPredictArm]]
  ]:
      optimization_config = optimization_config or not_none(
          experiment.optimization_config
      )
      if optimization_config.is_moo_problem:
          raise NotImplementedError(
              "Please use `get_pareto_optimal_parameters` for multi-objective "
              "problems."
          )
      # TODO[drfreund]: Find a way to include data for last trial in the
      # calculation of best parameters.
      if use_model_predictions:
          current_model = generation_strategy._curr.model_enum
          # Cover for the case where source of `self._curr.model` was not a `Models`
          # enum but a factory function, in which case we cannot do
          # `get_model_from_generator_run` (since we don't have model type and inputs
          # recorded on the generator run.
          models_enum = (
              current_model.__class__
              if isinstance(current_model, ModelRegistryBase)
              else None
          )
  
          if models_enum is not None:
              res = best_point_utils.get_best_parameters_from_model_predictions_with_trial_index(  # noqa
                  experiment=experiment,
                  models_enum=models_enum,
                  optimization_config=optimization_config,
                  trial_indices=trial_indices,
              )
  
              if res is not None:
                  return res
  
      return (
          best_point_utils.get_best_by_raw_objective_with_trial_index(
              experiment=experiment,
              optimization_config=optimization_config,
              trial_indices=trial_indices,
          )
      )
  
imports: from abc import ABCMeta, abstractmethod
  from functools import partial
  from logging import Logger
  from typing import Dict, Iterable, List, Optional, Tuple
  import numpy
  import torch
  from ax.core.experiment import Experiment
  from ax.core.map_data import MapData
  from ax.core.objective import ScalarizedObjective
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.types import TModelPredictArm, TParameterization
  from ax.modelbridge.generation_strategy import GenerationStrategy
  from ax.modelbridge.modelbridge_utils import extract_objective_thresholds, extract_objective_weights, extract_outcome_constraints, observed_hypervolume, predicted_hypervolume, validate_and_apply_final_transform
  from ax.modelbridge.registry import get_model_from_generator_run, ModelRegistryBase
  from ax.modelbridge.torch import TorchModelBridge
  from ax.modelbridge.transforms.derelativize import Derelativize
  from ax.models.torch.botorch_moo_defaults import get_outcome_constraint_transforms, get_weighted_mc_objective_and_objective_thresholds
  from ax.plot.pareto_utils import get_tensor_converter_model
  from ax.service.utils import best_point
  from ax.service.utils.best_point import extract_Y_from_data, fill_missing_thresholds_from_nadir
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast, not_none
  from botorch.utils.multi_objective.box_decompositions import DominatedPartitioning
label_desc: Use image node_id 7 for calling the BestPointMixin obj's underlying member method code with example usage: obj._get_best_trial(experiment, generation_strategy, optimization_config, trial_indices, use_model_predictions) and returns: best_point_utils, res