code: def test_compute_best_feasible_objective(self):
      for dtype in (torch.float, torch.double):
          with self.subTest(dtype=dtype):
              tkwargs = {"dtype": dtype, "device": self.device}
              n = 5
              X = torch.arange(n, **tkwargs).view(-1, 1)
              for batch_shape, sample_shape in itertools.product(
                  (torch.Size([]), torch.Size([2])),
                  (torch.Size([1]), torch.Size([3])),
              ):
                  means = torch.arange(n, **tkwargs).view(-1, 1)
                  if len(batch_shape) > 0:
                      view_means = means.view(1, *means.shape)
                      means = view_means.expand(
                          batch_shape + means.shape
                      )
                  if sample_shape[0] == 1:
                      samples = means.unsqueeze(0)
                  else:
                      samples = torch.stack(
                          [means, means + 1, means + 4], dim=0
                      )
                  variances = torch.tensor(
                      [0.09, 0.25, 0.36, 0.25, 0.09], **tkwargs
                  ).view(-1, 1)
                  mm = MockModel(
                      MockPosterior(mean=means, variance=variances)
                  )
  
                  # testing all feasible points
                  obj = samples.squeeze(-1)
                  constraints = [
                      lambda samples: -torch.ones_like(samples[..., 0])
                  ]
                  best_f = compute_best_feasible_objective(
                      samples=samples, obj=obj, constraints=constraints
                  )
                  self.assertAllClose(
                      best_f, obj.amax(dim=-1, keepdim=True)
                  )
  
                  # testing with some infeasible points
                  con_cutoff = 3.0
                  best_f = compute_best_feasible_objective(
                      samples=samples,
                      obj=obj,
                      constraints=[
                          lambda samples: samples[..., 0]
                          - (con_cutoff + 1 / 2)
                      ],
                      model=mm,
                      X_baseline=X,
                  )
  
                  if sample_shape[0] == 3:
                      # under some samples, all baseline points are infeasible, so
                      # the best_f is set to the negative infeasible cost for
                      # for samples where no point is feasible
                      expected_best_f = torch.tensor(
                          [
                              3.0,
                              3.0,
                              -get_infeasible_cost(
                                  X=X,
                                  model=mm,
                              ).item(),
                          ],
                          **tkwargs,
                      ).view(-1, 1)
                      if len(batch_shape) > 0:
                          # When `batch_shape = (b,)`, this expands `expected_best_f`
                          # from shape (3, 1) to (3, 1, 1), then to
                          # (1, 1, ..., 1, 3, b, 1), where there are
                          # `len(sample_shape) - 1` leading ones.
                          expected_best_f = expected_best_f.unsqueeze(
                              1
                          ).repeat(
                              *[1] * len(sample_shape), *batch_shape, 1
                          )
                  else:
                      expected_best_f = torch.full(
                          sample_shape + batch_shape + torch.Size([1]),
                          con_cutoff,
                          **tkwargs,
                      )
                  self.assertAllClose(best_f, expected_best_f)
                  # test some feasible points with infeasible obi
                  if sample_shape[0] == 3:
                      best_f = compute_best_feasible_objective(
                          samples=samples,
                          obj=obj,
                          constraints=[
                              lambda samples: samples[..., 0]
                              - (con_cutoff + 1 / 2)
                          ],
                          infeasible_obj=torch.ones(1, **tkwargs),
                      )
                      expected_best_f[-1] = 1
                      self.assertAllClose(best_f, expected_best_f)
  
                  # testing with no feasible points and infeasible obj
                  infeasible_obj = torch.tensor(torch.pi, **tkwargs)
                  expected_best_f = torch.full(
                      sample_shape + batch_shape + torch.Size([1]),
                      torch.pi,
                      **tkwargs,
                  )
  
                  best_f = compute_best_feasible_objective(
                      samples=samples,
                      obj=obj,
                      constraints=[
                          lambda X: torch.ones_like(X[..., 0])
                      ],
                      infeasible_obj=infeasible_obj,
                  )
                  self.assertAllClose(best_f, expected_best_f)
  
                  # testing with no feasible points and not infeasible obj
                  def objective(Y, X):
                      return Y.squeeze(-1) - 5.0
  
                  best_f = compute_best_feasible_objective(
                      samples=samples,
                      obj=obj,
                      constraints=[
                          lambda X: torch.ones_like(X[..., 0])
                      ],
                      model=mm,
                      X_baseline=X,
                      objective=objective,
                  )
                  expected_best_f = torch.full(
                      sample_shape + batch_shape + torch.Size([1]),
                      -get_infeasible_cost(
                          X=X, model=mm, objective=objective
                      ).item(),
                      **tkwargs,
                  )
                  self.assertAllClose(best_f, expected_best_f)
  
                  with self.assertRaisesRegex(
                      ValueError, "Must specify `model`"
                  ):
                      best_f = compute_best_feasible_objective(
                          samples=means,
                          obj=obj,
                          constraints=[
                              lambda X: torch.ones_like(X[..., 0])
                          ],
                          X_baseline=X,
                      )
                  with self.assertRaisesRegex(
                      ValueError, "Must specify `X_baseline`"
                  ):
                      best_f = compute_best_feasible_objective(
                          samples=means,
                          obj=obj,
                          constraints=[
                              lambda X: torch.ones_like(X[..., 0])
                          ],
                          model=mm,
                      )
  
imports: import itertools
  from unittest import mock
  from unittest.mock import patch
  import torch
  from botorch.acquisition.objective import GenericMCObjective, LearnedObjective
  from botorch.acquisition.utils import compute_best_feasible_objective, expand_trace_observations, get_acquisition_function, get_infeasible_cost, get_optimal_samples, project_to_sample_points, project_to_target_fidelity, prune_inferior_points, repeat_to_match_aug_dim
  from botorch.exceptions.errors import BotorchTensorDimensionError, DeprecationError, UnsupportedError
  from botorch.models import SingleTaskGP
  from botorch.utils.testing import BotorchTestCase, MockModel, MockPosterior
  from gpytorch.distributions import MultivariateNormal
label_desc: Use image node_id 1 for calling the TestConstraintUtils obj's underlying member method code with example usage: obj.test_compute_best_feasible_objective() and returns: unknown