class_docstr: Customizable botorch model.
  
  By default, this uses a noisy Log Expected Improvement (qLogNEI) acquisition
  function on top of a model made up of separate GPs, one for each outcome. This
  behavior can be modified by providing custom implementations of the following
  components:
  
  - a `model_constructor` that instantiates and fits a model on data
  - a `model_predictor` that predicts outcomes using the fitted model
  - a `acqf_constructor` that creates an acquisition function from a fitted model
  - a `acqf_optimizer` that optimizes the acquisition function
  - a `best_point_recommender` that recommends a current "best" point (i.e.,
      what the model recommends if the learning process ended now)
  
  Args:
      model_constructor: A callable that instantiates and fits a model on data,
          with signature as described below.
      model_predictor: A callable that predicts using the fitted model, with
          signature as described below.
      acqf_constructor: A callable that creates an acquisition function from a
          fitted model, with signature as described below.
      acqf_optimizer: A callable that optimizes the acquisition function, with
          signature as described below.
      best_point_recommender: A callable that recommends the best point, with
          signature as described below.
      refit_on_cv: If True, refit the model for each fold when performing
          cross-validation.
      refit_on_update: If True, refit the model after updating the training
          data using the `update` method.
      warm_start_refitting: If True, start model refitting from previous
          model parameters in order to speed up the fitting process.
      prior: An optional dictionary that contains the specification of GP model prior.
          Currently, the keys include:
          - covar_module_prior: prior on covariance matrix e.g.
              {"lengthscale_prior": GammaPrior(3.0, 6.0)}.
          - type: type of prior on task covariance matrix e.g.`LKJCovariancePrior`.
          - sd_prior: A scalar prior over nonnegative numbers, which is used for the
              default LKJCovariancePrior task_covar_prior.
          - eta: The eta parameter on the default LKJ task_covar_prior.
  
  
  Call signatures:
  
  ::
  
      model_constructor(
          Xs,
          Ys,
          Yvars,
          task_features,
          fidelity_features,
          metric_names,
          state_dict,
          **kwargs,
      ) -> model
  
  Here `Xs`, `Ys`, `Yvars` are lists of tensors (one element per outcome),
  `task_features` identifies columns of Xs that should be modeled as a task,
  `fidelity_features` is a list of ints that specify the positions of fidelity
  parameters in 'Xs', `metric_names` provides the names of each `Y` in `Ys`,
  `state_dict` is a pytorch module state dict, and `model` is a BoTorch `Model`.
  Optional kwargs are being passed through from the `BotorchModel` constructor.
  This callable is assumed to return a fitted BoTorch model that has the same
  dtype and lives on the same device as the input tensors.
  
  ::
  
      model_predictor(model, X) -> [mean, cov]
  
  Here `model` is a fitted botorch model, `X` is a tensor of candidate points,
  and `mean` and `cov` are the posterior mean and covariance, respectively.
  
  ::
  
      acqf_constructor(
          model,
          objective_weights,
          outcome_constraints,
          X_observed,
          X_pending,
          **kwargs,
      ) -> acq_function
  
  
  Here `model` is a botorch `Model`, `objective_weights` is a tensor of weights
  for the model outputs, `outcome_constraints` is a tuple of tensors describing
  the (linear) outcome constraints, `X_observed` are previously observed points,
  and `X_pending` are points whose evaluation is pending. `acq_function` is a
  BoTorch acquisition function crafted from these inputs. For additional
  details on the arguments, see `get_qLogNEI`.
  
  ::
  
      acqf_optimizer(
          acq_function,
          bounds,
          n,
          inequality_constraints,
          equality_constraints,
          fixed_features,
          rounding_func,
          **kwargs,
      ) -> candidates
  
  Here `acq_function` is a BoTorch `AcquisitionFunction`, `bounds` is a tensor
  containing bounds on the parameters, `n` is the number of candidates to be
  generated, `inequality_constraints` are inequality constraints on parameter
  values, `fixed_features` specifies features that should be fixed during
  generation, and `rounding_func` is a callback that rounds an optimization
  result appropriately. `candidates` is a tensor of generated candidates.
  For additional details on the arguments, see `scipy_optimizer`.
  
  ::
  
      best_point_recommender(
          model,
          bounds,
          objective_weights,
          outcome_constraints,
          linear_constraints,
          fixed_features,
          model_gen_options,
          target_fidelities,
      ) -> candidates
  
  Here `model` is a TorchModel, `bounds` is a list of tuples containing bounds
  on the parameters, `objective_weights` is a tensor of weights for the model outputs,
  `outcome_constraints` is a tuple of tensors describing the (linear) outcome
  constraints, `linear_constraints` is a tuple of tensors describing constraints
  on the design, `fixed_features` specifies features that should be fixed during
  generation, `model_gen_options` is a config dictionary that can contain
  model-specific options, and `target_fidelities` is a map from fidelity feature
  column indices to their respective target fidelities, used for multi-fidelity
  optimization problems. % TODO: refer to an example.
class_docstr_tok: ["Customizable","botorch","model",".","By","default",",","this","uses","a","noisy","Log","Expected","Improvement","(","qLogNEI",")","acquisition","function","on","top","of","a","model","made","up","of","separate","GPs",",","one","for","each","outcome",".","This","behavior","can","be","modified","by","providing","custom","implementations","of","the","following","components",":","-","a","`","model_constructor","`","that","instantiates","and","fits","a","model","on","data","-","a","`","model_predictor","`","that","predicts","outcomes","using","the","fitted","model","-","a","`","acqf_constructor","`","that","creates","an","acquisition","function","from","a","fitted","model","-","a","`","acqf_optimizer","`","that","optimizes","the","acquisition","function","-","a","`","best_point_recommender","`","that","recommends","a","current","``","best","''","point","(","i.e.",",","what","the","model","recommends","if","the","learning","process","ended","now",")","Args",":","model_constructor",":","A","callable","that","instantiates","and","fits","a","model","on","data",",","with","signature","as","described","below",".","model_predictor",":","A","callable","that","predicts","using","the","fitted","model",",","with","signature","as","described","below",".","acqf_constructor",":","A","callable","that","creates","an","acquisition","function","from","a","fitted","model",",","with","signature","as","described","below",".","acqf_optimizer",":","A","callable","that","optimizes","the","acquisition","function",",","with","signature","as","described","below",".","best_point_recommender",":","A","callable","that","recommends","the","best","point",",","with","signature","as","described","below",".","refit_on_cv",":","If","True",",","refit","the","model","for","each","fold","when","performing","cross-validation",".","refit_on_update",":","If","True",",","refit","the","model","after","updating","the","training","data","using","the","`","update","`","method",".","warm_start_refitting",":","If","True",",","start","model","refitting","from","previous","model","parameters","in","order","to","speed","up","the","fitting","process",".","prior",":","An","optional","dictionary","that","contains","the","specification","of","GP","model","prior",".","Currently",",","the","keys","include",":","-","covar_module_prior",":","prior","on","covariance","matrix","e.g",".","{","``","lengthscale_prior","''",":","GammaPrior","(","3.0",",","6.0",")","}",".","-","type",":","type","of","prior","on","task","covariance","matrix","e.g.","`","LKJCovariancePrior","`",".","-","sd_prior",":","A","scalar","prior","over","nonnegative","numbers",",","which","is","used","for","the","default","LKJCovariancePrior","task_covar_prior",".","-","eta",":","The","eta","parameter","on","the","default","LKJ","task_covar_prior",".","Call","signatures",":",":",":","model_constructor","(","Xs",",","Ys",",","Yvars",",","task_features",",","fidelity_features",",","metric_names",",","state_dict",",","*","*","kwargs",",",")","-",">","model","Here","`","Xs","`",",","`","Ys","`",",","`","Yvars","`","are","lists","of","tensors","(","one","element","per","outcome",")",",","`","task_features","`","identifies","columns","of","Xs","that","should","be","modeled","as","a","task",",","`","fidelity_features","`","is","a","list","of","ints","that","specify","the","positions","of","fidelity","parameters","in","'Xs","'",",","`","metric_names","`","provides","the","names","of","each","`","Y","`","in","`","Ys","`",",","`","state_dict","`","is","a","pytorch","module","state","dict",",","and","`","model","`","is","a","BoTorch","`","Model","`",".","Optional","kwargs","are","being","passed","through","from","the","`","BotorchModel","`","constructor",".","This","callable","is","assumed","to","return","a","fitted","BoTorch","model","that","has","the","same","dtype","and","lives","on","the","same","device","as","the","input","tensors",".",":",":","model_predictor","(","model",",","X",")","-",">","[","mean",",","cov","]","Here","`","model","`","is","a","fitted","botorch","model",",","`","X","`","is","a","tensor","of","candidate","points",",","and","`","mean","`","and","`","cov","`","are","the","posterior","mean","and","covariance",",","respectively",".",":",":","acqf_constructor","(","model",",","objective_weights",",","outcome_constraints",",","X_observed",",","X_pending",",","*","*","kwargs",",",")","-",">","acq_function","Here","`","model","`","is","a","botorch","`","Model","`",",","`","objective_weights","`","is","a","tensor","of","weights","for","the","model","outputs",",","`","outcome_constraints","`","is","a","tuple","of","tensors","describing","the","(","linear",")","outcome","constraints",",","`","X_observed","`","are","previously","observed","points",",","and","`","X_pending","`","are","points","whose","evaluation","is","pending",".","`","acq_function","`","is","a","BoTorch","acquisition","function","crafted","from","these","inputs",".","For","additional","details","on","the","arguments",",","see","`","get_qLogNEI","`",".",":",":","acqf_optimizer","(","acq_function",",","bounds",",","n",",","inequality_constraints",",","equality_constraints",",","fixed_features",",","rounding_func",",","*","*","kwargs",",",")","-",">","candidates","Here","`","acq_function","`","is","a","BoTorch","`","AcquisitionFunction","`",",","`","bounds","`","is","a","tensor","containing","bounds","on","the","parameters",",","`","n","`","is","the","number","of","candidates","to","be","generated",",","`","inequality_constraints","`","are","inequality","constraints","on","parameter","values",",","`","fixed_features","`","specifies","features","that","should","be","fixed","during","generation",",","and","`","rounding_func","`","is","a","callback","that","rounds","an","optimization","result","appropriately",".","`","candidates","`","is","a","tensor","of","generated","candidates",".","For","additional","details","on","the","arguments",",","see","`","scipy_optimizer","`",".",":",":","best_point_recommender","(","model",",","bounds",",","objective_weights",",","outcome_constraints",",","linear_constraints",",","fixed_features",",","model_gen_options",",","target_fidelities",",",")","-",">","candidates","Here","`","model","`","is","a","TorchModel",",","`","bounds","`","is","a","list","of","tuples","containing","bounds","on","the","parameters",",","`","objective_weights","`","is","a","tensor","of","weights","for","the","model","outputs",",","`","outcome_constraints","`","is","a","tuple","of","tensors","describing","the","(","linear",")","outcome","constraints",",","`","linear_constraints","`","is","a","tuple","of","tensors","describing","constraints","on","the","design",",","`","fixed_features","`","specifies","features","that","should","be","fixed","during","generation",",","`","model_gen_options","`","is","a","config","dictionary","that","can","contain","model-specific","options",",","and","`","target_fidelities","`","is","a","map","from","fidelity","feature","column","indices","to","their","respective","target","fidelities",",","used","for","multi-fidelity","optimization","problems",".","%","TODO",":","refer","to","an","example","."]
code: def feature_importances(self) -> np.ndarray:
      return get_feature_importances_from_botorch_model(
          model=self._model
      )
  
imports: from __future__ import annotations
  import warnings
  from copy import deepcopy
  from logging import Logger
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.core.types import TCandidateMetadata
  from ax.exceptions.core import DataRequiredError
  from ax.models.torch.botorch_defaults import get_and_fit_model, get_qLogNEI, recommend_best_observed_point, scipy_optimizer, TAcqfConstructor
  from ax.models.torch.utils import _datasets_to_legacy_inputs, _get_X_pending_and_observed, _to_inequality_constraints, normalize_indices, predict_from_model, subset_model
  from ax.models.torch_base import TorchGenResults, TorchModel, TorchOptConfig
  from ax.models.types import TConfig
  from ax.utils.common.constants import Keys
  from ax.utils.common.docutils import copy_doc
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast
  from botorch.acquisition.acquisition import AcquisitionFunction
  from botorch.models import ModelList
  from botorch.models.model import Model
  from botorch.utils.datasets import SupervisedDataset
  from botorch.utils.transforms import is_ensemble
  from torch import Tensor
  from torch.nn import ModuleList
label_desc: Use image node_id 7 for calling the BotorchModel obj's underlying member method code with example usage: obj.feature_importances() and returns: get_feature_importances_from_botorch_model