code: def get_objective_weights_transform(
      weights: Optional[Tensor],
  ) -> Callable[[Tensor, Optional[Tensor]], Tensor]:
      r"""Create a linear objective callable from a set of weights.
  
      Create a callable mapping a Tensor of size `b x q x m` and an (optional)
      Tensor of size `b x q x d` to a Tensor of size `b x q`, where `m` is the
      number of outputs of the model using scalarization via the objective weights.
      This callable supports broadcasting (e.g. for calling on a tensor of shape
      `mc_samples x b x q x m`). For `m = 1`, the objective weight is used to
      determine the optimization direction.
  
      Args:
          weights: a 1-dimensional Tensor containing a weight for each task.
              If not provided, the identity mapping is used.
  
      Returns:
          Transform function using the objective weights.
  
      Example:
          >>> weights = torch.tensor([0.75, 0.25])
          >>> transform = get_objective_weights_transform(weights)
      """
      # if no weights provided, just extract the single output
      if weights is None:
          return lambda Y: Y.squeeze(-1)
  
      def _objective(Y: Tensor, X: Optional[Tensor] = None):
          r"""Evaluate objective.
  
          Note: einsum multiples Y by weights and sums over the `m`-dimension.
          Einsum is ~2x faster than using `(Y * weights.view(1, 1, -1)).sum(dim-1)`.
  
          Args:
              Y: A `... x b x q x m` tensor of function values.
  
          Returns:
              A `... x b x q`-dim tensor of objective values.
          """
          return torch.einsum("...m, m", [Y, weights])
  
      return _objective
  
file_path: botorch/botorch/utils/objective.py
imports: from __future__ import annotations
  import warnings
  from typing import Callable, List, Optional, Union
  import torch
  from botorch.utils.safe_math import log_fatmoid, logexpit
  from botorch.utils.transforms import normalize_indices
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: get_objective_weights_transform(weights) and returns: _objective, function, torch