class_docstr: Objective generated from a generic callable.
  
  Allows to construct arbitrary MC-objective functions from a generic
  callable. In order to be able to use gradient-based acquisition function
  optimization it should be possible to backpropagate through the callable.
  
  Example:
      >>> generic_objective = GenericMCObjective(
              lambda Y, X: torch.sqrt(Y).sum(dim=-1),
          )
      >>> samples = sampler(posterior)
      >>> objective = generic_objective(samples)
class_docstr_tok: ["Objective","generated","from","a","generic","callable",".","Allows","to","construct","arbitrary","MC-objective","functions","from","a","generic","callable",".","In","order","to","be","able","to","use","gradient-based","acquisition","function","optimization","it","should","be","possible","to","backpropagate","through","the","callable",".","Example",":",">",">",">","generic_objective","=","GenericMCObjective","(","lambda","Y",",","X",":","torch.sqrt","(","Y",")",".sum","(","dim=-1",")",",",")",">",">",">","samples","=","sampler","(","posterior",")",">",">",">","objective","=","generic_objective","(","samples",")"]
docstr: Args:
      objective: A callable `f(samples, X)` mapping a
          `sample_shape x batch-shape x q x m`-dim Tensor `samples` and
          an optional `batch-shape x q x d`-dim Tensor `X` to a
          `sample_shape x batch-shape x q`-dim Tensor of objective values.
code: def __init__(
      self, objective: Callable[[Tensor, Optional[Tensor]], Tensor]
  ) -> None:
      r"""
      Args:
          objective: A callable `f(samples, X)` mapping a
              `sample_shape x batch-shape x q x m`-dim Tensor `samples` and
              an optional `batch-shape x q x d`-dim Tensor `X` to a
              `sample_shape x batch-shape x q`-dim Tensor of objective values.
      """
      super().__init__()
      if len(inspect.signature(objective).parameters) == 1:
          warnings.warn(
              "The `objective` callable of `GenericMCObjective` is expected to "
              "take two arguments. Passing a callable that expects a single "
              "argument will result in an error in future versions.",
              DeprecationWarning,
          )
  
          def obj(
              samples: Tensor, X: Optional[Tensor] = None
          ) -> Tensor:
              return objective(samples)
  
          self.objective = obj
      else:
          self.objective = objective
  
imports: from __future__ import annotations
  import inspect
  import warnings
  from abc import ABC, abstractmethod
  from typing import Callable, List, Optional, TYPE_CHECKING, Union
  import torch
  from botorch.exceptions.errors import BotorchTensorDimensionError, UnsupportedError
  from botorch.exceptions.warnings import InputDataWarning
  from botorch.models.model import Model
  from botorch.models.transforms.outcome import Standardize
  from botorch.posteriors.gpytorch import GPyTorchPosterior, scalarize_posterior
  from botorch.sampling import IIDNormalSampler
  from botorch.utils import apply_constraints
  from gpytorch.distributions import MultitaskMultivariateNormal, MultivariateNormal
  from linear_operator.operators.dense_linear_operator import to_linear_operator
  from torch import Tensor
  from torch.nn import Module
  from botorch.models.deterministic import DeterministicModel
label_desc: Use image node_id 1 to create a new GenericMCObjective object from inherited base classes: MCAcquisitionObjective with example: obj = GenericMCObjective(objective)