code: def test_penalized_mc_objective(self):
      for dtype in (torch.float, torch.double):
          init_point = torch.tensor(
              [0.0, 0.0, 0.0, 0.0, 0.0], device=self.device, dtype=dtype
          )
          l1_penalty_obj = L1PenaltyObjective(init_point=init_point)
          obj = PenalizedMCObjective(
              objective=generic_obj,
              penalty_objective=l1_penalty_obj,
              regularization_parameter=0.1,
          )
          # test self.expand_dim
          self.assertIsNone(obj.expand_dim)
          # test 'd' Tensor X
          samples = torch.randn(4, 3, device=self.device, dtype=dtype)
          X = torch.randn(4, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(X)
          self.assertTrue(
              torch.equal(obj(samples, X), penalized_obj.squeeze(0))
          )
          # test 'q x d' Tensor X
          samples = torch.randn(
              4, 2, 3, device=self.device, dtype=dtype
          )
          X = torch.randn(2, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(X)
          self.assertTrue(torch.equal(obj(samples, X), penalized_obj))
          # test 'batch-shape x q x d' Tensor X
          samples = torch.randn(
              4, 3, 2, 3, device=self.device, dtype=dtype
          )
          X = torch.randn(3, 2, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(X)
          self.assertTrue(torch.equal(obj(samples, X), penalized_obj))
  
          # test passing expand_dim
          expand_dim = -2
          obj2 = PenalizedMCObjective(
              objective=generic_obj,
              penalty_objective=l1_penalty_obj,
              regularization_parameter=0.1,
              expand_dim=expand_dim,
          )
          self.assertEqual(obj2.expand_dim, -2)
          # test 'd' Tensor X
          mcmc_samples = 8
          # MCMC_dim = -3
          samples = torch.randn(
              mcmc_samples, 4, 3, device=self.device, dtype=dtype
          )
          X = torch.randn(4, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(
              X
          ).unsqueeze(expand_dim)
          self.assertTrue(torch.equal(obj2(samples, X), penalized_obj))
          # test 'q x d' Tensor X
          # MCMC_dim = -3
          samples = torch.randn(
              4, mcmc_samples, 2, 3, device=self.device, dtype=dtype
          )
          X = torch.randn(2, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(
              X
          ).unsqueeze(expand_dim)
          self.assertTrue(torch.equal(obj2(samples, X), penalized_obj))
          # test 'batch-shape x q x d' Tensor X
          # MCMC_dim = -3
          samples = torch.randn(
              4, 3, mcmc_samples, 2, 3, device=self.device, dtype=dtype
          )
          X = torch.randn(3, 2, 5, device=self.device, dtype=dtype)
          penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(
              X
          ).unsqueeze(expand_dim)
          self.assertTrue(torch.equal(obj2(samples, X), penalized_obj))
  
imports: import torch
  from botorch.acquisition.analytic import ExpectedImprovement
  from botorch.acquisition.monte_carlo import qExpectedImprovement
  from botorch.acquisition.penalized import GaussianPenalty, group_lasso_regularizer, GroupLassoPenalty, L0Approximation, L0PenaltyApprox, L0PenaltyApproxObjective, L1Penalty, L1PenaltyObjective, L2Penalty, PenalizedAcquisitionFunction, PenalizedMCObjective
  from botorch.exceptions import UnsupportedError
  from botorch.sampling.normal import IIDNormalSampler
  from botorch.utils.testing import BotorchTestCase, MockModel, MockPosterior
  from torch import Tensor
label_desc: Use image node_id 1 for calling the TestPenalizedMCObjective obj's underlying member method code with example usage: obj.test_penalized_mc_objective() without return types