code: def compute_best_feasible_objective(
      samples: Tensor,
      obj: Tensor,
      constraints: Optional[List[Callable[[Tensor], Tensor]]],
      model: Optional[Model] = None,
      objective: Optional[MCAcquisitionObjective] = None,
      posterior_transform: Optional[PosteriorTransform] = None,
      X_baseline: Optional[Tensor] = None,
      infeasible_obj: Optional[Tensor] = None,
  ) -> Tensor:
      """Computes the largest `obj` value that is feasible under the `constraints`. If
      `constraints` is None, returns the best unconstrained objective value.
  
      When no feasible observations exist and `infeasible_obj` is not `None`, returns
      `infeasible_obj` (potentially reshaped). When no feasible observations exist and
      `infeasible_obj` is `None`, uses `model`, `objective`, `posterior_transform`, and
      `X_baseline` to infer and return an `infeasible_obj` `M` s.t. `M < min_x f(x)`.
  
      Args:
          samples: `(sample_shape) x batch_shape x q x m`-dim posterior samples.
          obj: A `(sample_shape) x batch_shape x q`-dim Tensor of MC objective values.
          constraints: A list of constraint callables which map posterior samples to
              a scalar. The associated constraint is considered satisfied if this
              scalar is less than zero.
          model: A Model, only required when there are no feasible observations.
          objective: An MCAcquisitionObjective, only optionally used when there are no
              feasible observations.
          posterior_transform: A PosteriorTransform, only optionally used when there are
              no feasible observations.
          X_baseline: A `batch_shape x d`-dim Tensor of baseline points, only required
              when there are no feasible observations.
          infeasible_obj: A Tensor to be returned when no feasible points exist.
  
      Returns:
          A `(sample_shape) x batch_shape x 1`-dim Tensor of best feasible objectives.
      """
      if constraints is None:  # unconstrained case
          # we don't need to differentiate through X_baseline for now, so taking
          # the regular max over the n points to get best_f is fine
          with torch.no_grad():
              return obj.amax(dim=-1, keepdim=True)
  
      is_feasible = compute_feasibility_indicator(
          constraints=constraints, samples=samples
      )  # sample_shape x batch_shape x q
  
      if is_feasible.any(dim=-1).all():
          infeasible_value = -torch.inf
  
      elif infeasible_obj is not None:
          infeasible_value = infeasible_obj.item()
  
      else:
          if model is None:
              raise ValueError(
                  "Must specify `model` when no feasible observation exists."
              )
          if X_baseline is None:
              raise ValueError(
                  "Must specify `X_baseline` when no feasible observation exists."
              )
          infeasible_value = _estimate_objective_lower_bound(
              model=model,
              objective=objective,
              posterior_transform=posterior_transform,
              X=X_baseline,
          ).item()
  
      is_feasible = repeat_to_match_aug_dim(
          target_tensor=is_feasible, reference_tensor=obj
      )
      obj = torch.where(is_feasible, obj, infeasible_value)
      with torch.no_grad():
          return obj.amax(dim=-1, keepdim=True)
  
imports: from __future__ import annotations
  import math
  from typing import Callable, Dict, List, Optional, Tuple
  import torch
  from botorch.acquisition.objective import IdentityMCObjective, MCAcquisitionObjective, PosteriorTransform
  from botorch.exceptions.errors import BotorchTensorDimensionError, DeprecationError, UnsupportedError
  from botorch.models.fully_bayesian import MCMC_DIM
  from botorch.models.model import Model
  from botorch.sampling.base import MCSampler
  from botorch.sampling.get_sampler import get_sampler
  from botorch.sampling.pathwise import draw_matheron_paths
  from botorch.utils.objective import compute_feasibility_indicator
  from botorch.utils.sampling import optimize_posterior_samples
  from botorch.utils.transforms import is_ensemble, normalize_indices
  from torch import Tensor
label_desc: Use image node_id 3 for calling a global function with example usage: compute_best_feasible_objective(samples, obj, constraints, model, objective, posterior_transform, X_baseline, infeasible_obj) and returns: obj, obj