code: def test_prune_inferior_points(self):
      for dtype in (torch.float, torch.double):
          X = torch.rand(3, 2, device=self.device, dtype=dtype)
          # the event shape is `q x t` = 3 x 1
          samples = torch.tensor(
              [[-1.0], [0.0], [1.0]], device=self.device, dtype=dtype
          )
          mm = MockModel(MockPosterior(samples=samples))
          # test that a batched X raises errors
          with self.assertRaises(UnsupportedError):
              prune_inferior_points(model=mm, X=X.expand(2, 3, 2))
          # test marginalize_dim
          mm2 = MockModel(
              MockPosterior(samples=samples.expand(2, 3, 1))
          )
          X_pruned = prune_inferior_points(
              model=mm2, X=X, marginalize_dim=-3
          )
          with self.assertRaises(UnsupportedError):
              # test error raised when marginalize_dim is not specified with
              # a batch model
              prune_inferior_points(model=mm2, X=X)
          self.assertTrue(torch.equal(X_pruned, X[[-1]]))
          # test that a batched model raises errors when there are multiple batch dims
          mm2 = MockModel(
              MockPosterior(samples=samples.expand(1, 2, 3, 1))
          )
          with self.assertRaises(UnsupportedError):
              prune_inferior_points(model=mm2, X=X)
          # test that invalid max_frac is checked properly
          with self.assertRaises(ValueError):
              prune_inferior_points(model=mm, X=X, max_frac=1.1)
          # test basic behaviour
          X_pruned = prune_inferior_points(model=mm, X=X)
          self.assertTrue(torch.equal(X_pruned, X[[-1]]))
          # test custom objective
          neg_id_obj = GenericMCObjective(lambda Y, X: -(Y.squeeze(-1)))
          X_pruned = prune_inferior_points(
              model=mm, X=X, objective=neg_id_obj
          )
          self.assertTrue(torch.equal(X_pruned, X[[0]]))
          # test non-repeated samples (requires mocking out MockPosterior's rsample)
          samples = torch.tensor(
              [
                  [[3.0], [0.0], [0.0]],
                  [[0.0], [2.0], [0.0]],
                  [[0.0], [0.0], [1.0]],
              ],
              device=self.device,
              dtype=dtype,
          )
          with mock.patch.object(
              MockPosterior, "rsample", return_value=samples
          ):
              mm = MockModel(MockPosterior(samples=samples))
              X_pruned = prune_inferior_points(model=mm, X=X)
          self.assertTrue(torch.equal(X_pruned, X))
          # test max_frac limiting
          with mock.patch.object(
              MockPosterior, "rsample", return_value=samples
          ):
              mm = MockModel(MockPosterior(samples=samples))
              X_pruned = prune_inferior_points(
                  model=mm, X=X, max_frac=2 / 3
              )
          if self.device.type == "cuda":
              # sorting has different order on cuda
              self.assertTrue(
                  torch.equal(
                      X_pruned, torch.stack([X[2], X[1]], dim=0)
                  )
              )
          else:
              self.assertTrue(torch.equal(X_pruned, X[:2]))
          # test that zero-probability is in fact pruned
          samples[2, 0, 0] = 10
          with mock.patch.object(
              MockPosterior, "rsample", return_value=samples
          ):
              mm = MockModel(MockPosterior(samples=samples))
              X_pruned = prune_inferior_points(model=mm, X=X)
          self.assertTrue(torch.equal(X_pruned, X[:2]))
          # test constraints
          constraints = [lambda Y: Y[..., 1] + 0.1]
          # only the last sample if feasible and it has the worst objective value
          samples = torch.tensor(
              [[1.0, 1.0], [0.0, 0.0], [-1.0, -1.0]],
              device=self.device,
              dtype=dtype,
          )
          mm = MockModel(
              MockPosterior(
                  samples=samples,
              )
          )
          X_pruned = prune_inferior_points(
              model=mm,
              X=X,
              objective=GenericMCObjective(
                  objective=lambda Y: Y[..., 0]
              ),
              constraints=constraints,
          )
          self.assertTrue(torch.equal(X_pruned, X[[-1]]))
  
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 TestPruneInferiorPoints obj's underlying member method code with example usage: obj.test_prune_inferior_points() without return types