code: def t_batch_mode_transform(
      expected_q: Optional[int] = None,
      assert_output_shape: bool = True,
  ) -> Callable[
      [Callable[[AcquisitionFunction, Any], Any]],
      Callable[[AcquisitionFunction, Any], Any],
  ]:
      r"""Factory for decorators enabling consistent t-batch behavior.
  
      This method creates decorators for instance methods to transform an input tensor
      `X` to t-batch mode (i.e. with at least 3 dimensions). This assumes the tensor
      has a q-batch dimension. The decorator also checks the q-batch size if `expected_q`
      is provided, and the output shape if `assert_output_shape` is `True`.
  
      Args:
          expected_q: The expected q-batch size of `X`. If specified, this will raise an
              AssertionError if `X`'s q-batch size does not equal expected_q.
          assert_output_shape: If `True`, this will raise an AssertionError if the
              output shape does not match either the t-batch shape of `X`,
              or the `acqf.model.batch_shape` for acquisition functions using
              batched models.
  
      Returns:
          The decorated instance method.
  
      Example:
          >>> class ExampleClass:
          >>>     @t_batch_mode_transform(expected_q=1)
          >>>     def single_q_method(self, X):
          >>>         ...
          >>>
          >>>     @t_batch_mode_transform()
          >>>     def arbitrary_q_method(self, X):
          >>>         ...
      """
  
      def decorator(
          method: Callable[[AcquisitionFunction, Any], Any],
      ) -> Callable[[AcquisitionFunction, Any], Any]:
          @wraps(method)
          def decorated(
              acqf: AcquisitionFunction,
              X: Any,
              *args: Any,
              **kwargs: Any,
          ) -> Any:
              # Allow using acquisition functions for other inputs (e.g. lists of strings)
              if not isinstance(X, Tensor):
                  return method(acqf, X, *args, **kwargs)
  
              if X.dim() < 2:
                  raise ValueError(
                      f"{type(acqf).__name__} requires X to have at least 2 dimensions,"
                      f" but received X with only {X.dim()} dimensions."
                  )
              elif expected_q is not None and X.shape[-2] != expected_q:
                  raise AssertionError(
                      f"Expected X to be `batch_shape x q={expected_q} x d`, but"
                      f" got X with shape {X.shape}."
                  )
              # add t-batch dim
              X = X if X.dim() > 2 else X.unsqueeze(0)
              output = method(acqf, X, *args, **kwargs)
              if hasattr(acqf, "model") and is_ensemble(acqf.model):
                  # IDEA: this could be wrapped into SampleReducingMCAcquisitionFunction
                  output = (
                      output.mean(dim=-1)
                      if not acqf._log
                      else logmeanexp(output, dim=-1)
                  )
              if assert_output_shape and not _verify_output_shape(
                  acqf=acqf,
                  X=X,
                  output=output,
              ):
                  raise AssertionError(
                      "Expected the output shape to match either the t-batch shape of "
                      "X, or the `model.batch_shape` in the case of acquisition "
                      "functions using batch models; but got output with shape "
                      f"{output.shape} for X with shape {X.shape}."
                  )
              return output
  
          return decorated
  
      return decorator
  
file_path: botorch/botorch/utils/transforms.py
imports: from __future__ import annotations
  import warnings
  from functools import wraps
  from typing import Any, Callable, List, Optional, TYPE_CHECKING
  import torch
  from botorch.utils.safe_math import logmeanexp
  from torch import Tensor
label_desc: Use image node_id 8 for calling a global function with example usage: t_batch_mode_transform(expected_q, assert_output_shape) and returns: decorator, decorated, output, method