class_docstr: **All classes in 'botorch_modular' directory are under
  construction, incomplete, and should be treated as alpha
  versions only.**
  
  Ax wrapper for BoTorch ``Model``, subcomponent of ``BoTorchModel``
  and is not meant to be used outside of it.
  
  Args:
      botorch_model_class: ``Model`` class to be used as the underlying
          BoTorch model. If None is provided a model class will be selected (either
          one for all outcomes or a ModelList with separate models for each outcome)
          will be selected automatically based off the datasets at `construct` time.
      model_options: Dictionary of options / kwargs for the BoTorch
          ``Model`` constructed during ``Surrogate.fit``.
          Note that the corresponding attribute will later be updated to include any
          additional kwargs passed into ``BoTorchModel.fit``.
      mll_class: ``MarginalLogLikelihood`` class to use for model-fitting.
      mll_options: Dictionary of options / kwargs for the MLL.
      outcome_transform_classes: List of BoTorch outcome transforms classes. Passed
          down to the BoTorch ``Model``. Multiple outcome transforms can be chained
          together using ``ChainedOutcomeTransform``.
      outcome_transform_options: Outcome transform classes kwargs. The keys are
          class string names and the values are dictionaries of outcome transform
          kwargs. For example,
          `
          outcome_transform_classes = [Standardize]
          outcome_transform_options = {
              "Standardize": {"m": 1},
          `
          For more options see `botorch/models/transforms/outcome.py`.
      input_transform_classes: List of BoTorch input transforms classes.
          Passed down to the BoTorch ``Model``. Multiple input transforms
          will be chained together using ``ChainedInputTransform``.
      input_transform_options: Input transform classes kwargs. The keys are
          class string names and the values are dictionaries of input transform
          kwargs. For example,
          `
          input_transform_classes = [Normalize, Round]
          input_transform_options = {
              "Normalize": {"d": 3},
              "Round": {"integer_indices": [0], "categorical_features": {1: 2}},
          }
          `
          For more input options see `botorch/models/transforms/input.py`.
      covar_module_class: Covariance module class. This gets initialized after
          parsing the ``covar_module_options`` in ``covar_module_argparse``,
          and gets passed to the model constructor as ``covar_module``.
      covar_module_options: Covariance module kwargs.
      likelihood: ``Likelihood`` class. This gets initialized with
          ``likelihood_options`` and gets passed to the model constructor.
      likelihood_options: Likelihood options.
      allow_batched_models: Set to true to fit the models in a batch if supported.
          Set to false to fit individual models to each metric in a loop.
class_docstr_tok: ["*","*","All","classes","in","'botorch_modular","'","directory","are","under","construction",",","incomplete",",","and","should","be","treated","as","alpha","versions","only",".","*","*","Ax","wrapper","for","BoTorch","``","Model","``",",","subcomponent","of","``","BoTorchModel","``","and","is","not","meant","to","be","used","outside","of","it",".","Args",":","botorch_model_class",":","``","Model","``","class","to","be","used","as","the","underlying","BoTorch","model",".","If","None","is","provided","a","model","class","will","be","selected","(","either","one","for","all","outcomes","or","a","ModelList","with","separate","models","for","each","outcome",")","will","be","selected","automatically","based","off","the","datasets","at","`","construct","`","time",".","model_options",":","Dictionary","of","options","\/","kwargs","for","the","BoTorch","``","Model","``","constructed","during","``","Surrogate.fit","``",".","Note","that","the","corresponding","attribute","will","later","be","updated","to","include","any","additional","kwargs","passed","into","``","BoTorchModel.fit","``",".","mll_class",":","``","MarginalLogLikelihood","``","class","to","use","for","model-fitting",".","mll_options",":","Dictionary","of","options","\/","kwargs","for","the","MLL",".","outcome_transform_classes",":","List","of","BoTorch","outcome","transforms","classes",".","Passed","down","to","the","BoTorch","``","Model","``",".","Multiple","outcome","transforms","can","be","chained","together","using","``","ChainedOutcomeTransform","``",".","outcome_transform_options",":","Outcome","transform","classes","kwargs",".","The","keys","are","class","string","names","and","the","values","are","dictionaries","of","outcome","transform","kwargs",".","For","example",",","`","outcome_transform_classes","=","[","Standardize","]","outcome_transform_options","=","{","``","Standardize","''",":","{","``","m","''",":","1","}",",","`","For","more","options","see","`","botorch\/models\/transforms\/outcome.py","`",".","input_transform_classes",":","List","of","BoTorch","input","transforms","classes",".","Passed","down","to","the","BoTorch","``","Model","``",".","Multiple","input","transforms","will","be","chained","together","using","``","ChainedInputTransform","``",".","input_transform_options",":","Input","transform","classes","kwargs",".","The","keys","are","class","string","names","and","the","values","are","dictionaries","of","input","transform","kwargs",".","For","example",",","`","input_transform_classes","=","[","Normalize",",","Round","]","input_transform_options","=","{","``","Normalize","''",":","{","``","d","''",":","3","}",",","``","Round","''",":","{","``","integer_indices","''",":","[","0","]",",","``","categorical_features","''",":","{","1",":","2","}","}",",","}","`","For","more","input","options","see","`","botorch\/models\/transforms\/input.py","`",".","covar_module_class",":","Covariance","module","class",".","This","gets","initialized","after","parsing","the","``","covar_module_options","``","in","``","covar_module_argparse","``",",","and","gets","passed","to","the","model","constructor","as","``","covar_module","``",".","covar_module_options",":","Covariance","module","kwargs",".","likelihood",":","``","Likelihood","``","class",".","This","gets","initialized","with","``","likelihood_options","``","and","gets","passed","to","the","model","constructor",".","likelihood_options",":","Likelihood","options",".","allow_batched_models",":","Set","to","true","to","fit","the","models","in","a","batch","if","supported",".","Set","to","false","to","fit","individual","models","to","each","metric","in","a","loop","."]
code: def __init__(
      self,
      botorch_model_class: Optional[Type[Model]] = None,
      model_options: Optional[Dict[str, Any]] = None,
      mll_class: Type[
          MarginalLogLikelihood
      ] = ExactMarginalLogLikelihood,
      mll_options: Optional[Dict[str, Any]] = None,
      outcome_transform_classes: Optional[
          List[Type[OutcomeTransform]]
      ] = None,
      outcome_transform_options: Optional[
          Dict[str, Dict[str, Any]]
      ] = None,
      input_transform_classes: Optional[
          List[Type[InputTransform]]
      ] = None,
      input_transform_options: Optional[
          Dict[str, Dict[str, Any]]
      ] = None,
      covar_module_class: Optional[Type[Kernel]] = None,
      covar_module_options: Optional[Dict[str, Any]] = None,
      likelihood_class: Optional[Type[Likelihood]] = None,
      likelihood_options: Optional[Dict[str, Any]] = None,
      allow_batched_models: bool = True,
  ) -> None:
      self.botorch_model_class = botorch_model_class
      # Copying model options to avoid mutating the original dict.
      # We later update it with any additional kwargs passed into `BoTorchModel.fit`.
      self.model_options: Dict[str, Any] = (model_options or {}).copy()
      self.mll_class = mll_class
      self.mll_options: Dict[str, Any] = mll_options or {}
      self.outcome_transform_classes = outcome_transform_classes
      self.outcome_transform_options: Dict[str, Any] = (
          outcome_transform_options or {}
      )
      self.input_transform_classes = input_transform_classes
      self.input_transform_options: Dict[str, Any] = (
          input_transform_options or {}
      )
      self.covar_module_class = covar_module_class
      self.covar_module_options: Dict[str, Any] = (
          covar_module_options or {}
      )
      self.likelihood_class = likelihood_class
      self.likelihood_options: Dict[str, Any] = likelihood_options or {}
      self.allow_batched_models = allow_batched_models
      # Store the last dataset used to fit the model for a given metric(s).
      # If the new dataset is identical, we will skip model fitting for that metric.
      # The keys are `tuple(dataset.outcome_names)`.
      self._last_datasets: Dict[Tuple[str], SupervisedDataset] = {}
      # Store a reference from a tuple of metric names to the BoTorch Model
      # corresponding to those metrics. In most cases this will be a one-tuple,
      # though we need n-tuples for LCE-M models. This will be used to skip model
      # construction & fitting if the datasets are identical.
      self._submodels: Dict[Tuple[str], Model] = {}
      # Store a reference to search space digest used while fitting the cached models.
      # We will re-fit the models if the search space digest changes.
      self._last_search_space_digest: Optional[SearchSpaceDigest] = None
  
      # These are later updated during model fitting.
      self._training_data: Optional[List[SupervisedDataset]] = None
      self._outcomes: Optional[List[str]] = None
      self._model: Optional[Model] = None
  
imports: from __future__ import annotations
  import inspect
  from copy import deepcopy
  from logging import Logger
  from typing import Any, Dict, List, Optional, OrderedDict, Tuple, Type
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.core.types import TCandidateMetadata
  from ax.exceptions.core import UserInputError
  from ax.models.model_utils import best_in_sample_point
  from ax.models.torch.botorch_modular.input_constructors.covar_modules import covar_module_argparse
  from ax.models.torch.botorch_modular.input_constructors.input_transforms import input_transform_argparse
  from ax.models.torch.botorch_modular.input_constructors.outcome_transform import outcome_transform_argparse
  from ax.models.torch.botorch_modular.utils import check_metric_dataset_match, choose_model_class, convert_to_block_design, fit_botorch_model, subset_state_dict, use_model_list
  from ax.models.torch.utils import _to_inequality_constraints, pick_best_out_of_sample_point_acqf_class, predict_from_model
  from ax.models.torch_base import TorchOptConfig
  from ax.models.types import TConfig
  from ax.utils.common.base import Base
  from ax.utils.common.constants import Keys
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast, checked_cast_optional
  from botorch.models.model import Model
  from botorch.models.model_list_gp_regression import ModelListGP
  from botorch.models.pairwise_gp import PairwiseGP
  from botorch.models.transforms.input import ChainedInputTransform, InputPerturbation, InputTransform
  from botorch.models.transforms.outcome import ChainedOutcomeTransform, OutcomeTransform
  from botorch.utils.datasets import RankingDataset, SupervisedDataset
  from gpytorch.kernels import Kernel
  from gpytorch.likelihoods.likelihood import Likelihood
  from gpytorch.mlls.exact_marginal_log_likelihood import ExactMarginalLogLikelihood
  from gpytorch.mlls.marginal_log_likelihood import MarginalLogLikelihood
  from torch import Tensor
label_desc: Use image node_id 1 to create a new Surrogate object from inherited base classes: Base with example: obj = Surrogate(botorch_model_class, model_options, mll_class, mll_options, outcome_transform_classes, outcome_transform_options, input_transform_classes, input_transform_options, covar_module_class, covar_module_options, likelihood_class, likelihood_options, allow_batched_models)