code: def test_constrained_mc_objective(self):
      for dtype in (torch.float, torch.double):
          # one feasible constraint
          obj = ConstrainedMCObjective(
              objective=generic_obj, constraints=[feasible_con]
          )
          samples = torch.randn(1, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con],
              samples=samples,
              infeasible_cost=0.0,
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
          # one infeasible constraint
          obj = ConstrainedMCObjective(
              objective=generic_obj, constraints=[infeasible_con]
          )
          samples = torch.randn(2, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[infeasible_con],
              samples=samples,
              infeasible_cost=0.0,
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
          # one feasible, one infeasible
          obj = ConstrainedMCObjective(
              objective=generic_obj,
              constraints=[feasible_con, infeasible_con],
          )
          samples = torch.randn(2, 1, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con, infeasible_con],
              samples=samples,
              infeasible_cost=torch.tensor(
                  [0.0], device=self.device, dtype=dtype
              ),
          )
          # one feasible, one infeasible different etas
          obj = ConstrainedMCObjective(
              objective=generic_obj,
              constraints=[feasible_con, infeasible_con],
              eta=torch.tensor([1, 10]),
          )
          samples = torch.randn(2, 1, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con, infeasible_con],
              samples=samples,
              eta=torch.tensor([1, 10]),
              infeasible_cost=torch.tensor(
                  [0.0], device=self.device, dtype=dtype
              ),
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
          # one feasible, one infeasible, infeasible_cost
          obj = ConstrainedMCObjective(
              objective=generic_obj,
              constraints=[feasible_con, infeasible_con],
              infeasible_cost=5.0,
          )
          samples = torch.randn(3, 2, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con, infeasible_con],
              samples=samples,
              infeasible_cost=5.0,
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
          # one feasible, one infeasible, infeasible_cost, different eta
          obj = ConstrainedMCObjective(
              objective=generic_obj,
              constraints=[feasible_con, infeasible_con],
              infeasible_cost=5.0,
              eta=torch.tensor([1, 10]),
          )
          samples = torch.randn(3, 2, device=self.device, dtype=dtype)
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con, infeasible_con],
              samples=samples,
              infeasible_cost=5.0,
              eta=torch.tensor([1, 10]),
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
          # one feasible, one infeasible, infeasible_cost, higher dimension
          obj = ConstrainedMCObjective(
              objective=generic_obj,
              constraints=[feasible_con, infeasible_con],
              infeasible_cost=torch.tensor(
                  [5.0], device=self.device, dtype=dtype
              ),
          )
          samples = torch.randn(
              4, 3, 2, device=self.device, dtype=dtype
          )
          constrained_obj = apply_constraints(
              obj=generic_obj(samples),
              constraints=[feasible_con, infeasible_con],
              samples=samples,
              infeasible_cost=5.0,
          )
          self.assertTrue(torch.equal(obj(samples), constrained_obj))
  
imports: import itertools
  import warnings
  from typing import Optional
  import torch
  from botorch import settings
  from botorch.acquisition import LearnedObjective
  from botorch.acquisition.objective import ConstrainedMCObjective, DEFAULT_NUM_PREF_SAMPLES, ExpectationPosteriorTransform, GenericMCObjective, IdentityMCObjective, LEARNED_OBJECTIVE_PREF_MODEL_MIXED_DTYPE_WARN, LinearMCObjective, MCAcquisitionObjective, PosteriorTransform, ScalarizedPosteriorTransform
  from botorch.exceptions.errors import UnsupportedError
  from botorch.exceptions.warnings import _get_single_precision_warning, InputDataWarning
  from botorch.models.deterministic import PosteriorMeanModel
  from botorch.models.pairwise_gp import PairwiseGP
  from botorch.models.transforms.input import Normalize
  from botorch.posteriors import GPyTorchPosterior
  from botorch.utils import apply_constraints
  from botorch.utils.testing import _get_test_posterior, BotorchTestCase
  from gpytorch.distributions import MultitaskMultivariateNormal, MultivariateNormal
  from linear_operator.operators.dense_linear_operator import to_linear_operator
  from torch import Tensor
label_desc: Use image node_id 1 for calling the TestConstrainedMCObjective obj's underlying member method code with example usage: obj.test_constrained_mc_objective() without return types