code: def test_get_infeasible_cost(self):
      for dtype in (torch.float, torch.double):
          tkwargs = {"dtype": dtype, "device": self.device}
          X = torch.ones(5, 1, **tkwargs)
          means = torch.tensor(
              [1.0, 2.0, 3.0, 4.0, 5.0], **tkwargs
          ).view(-1, 1)
          variances = torch.tensor(
              [0.09, 0.25, 0.36, 0.25, 0.09], **tkwargs
          ).view(-1, 1)
          mm = MockModel(MockPosterior(mean=means, variance=variances))
          # means - 6 * std = [-0.8, -1, -0.6, 1, 3.2]. After applying the
          # objective, the minimum becomes -6.0, so 6.0 should be returned.
          M = get_infeasible_cost(
              X=X, model=mm, objective=lambda Y, X: Y.squeeze(-1) - 5.0
          )
          self.assertAllClose(M, torch.tensor([6.0], **tkwargs))
          M = get_infeasible_cost(
              X=X,
              model=mm,
              objective=lambda Y, X: Y.squeeze(-1) - 5.0 - X[0, 0],
          )
          self.assertAllClose(M, torch.tensor([7.0], **tkwargs))
          # test it with using also X in the objective
          # Test default objective (squeeze last dim).
          M2 = get_infeasible_cost(X=X, model=mm)
          self.assertAllClose(M2, torch.tensor([1.0], **tkwargs))
          # Test multi-output.
          m_ = means.repeat(1, 2)
          m_[:, 1] -= 10
          mm = MockModel(
              MockPosterior(mean=m_, variance=variances.expand(-1, 2))
          )
          M3 = get_infeasible_cost(X=X, model=mm)
          self.assertAllClose(M3, torch.tensor([1.0, 11.0], **tkwargs))
          # With a batched model.
          means = means.expand(2, 4, -1, -1)
          variances = variances.expand(2, 4, -1, -1)
          mm = MockModel(MockPosterior(mean=means, variance=variances))
          M4 = get_infeasible_cost(X=X, model=mm)
          self.assertAllClose(M4, torch.tensor([1.0], **tkwargs))
  
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 2 for calling the TestConstraintUtils obj's underlying member method code with example usage: obj.test_get_infeasible_cost() without return types