code: def test_hypervolume(self):
      tkwargs = {"device": self.device}
      for dtype in (torch.float, torch.double):
          tkwargs["dtype"] = dtype
  
          ref_point = torch.tensor([0.0, 0.0], **tkwargs)
          hv = Hypervolume(ref_point)
  
          # test ref point
          self.assertTrue(torch.equal(ref_point, hv.ref_point))
          self.assertTrue(torch.equal(-ref_point, hv._ref_point))
  
          # test dimension errors
          with self.assertRaises(BotorchTensorDimensionError):
              hv.compute(pareto_Y=torch.empty(2, **tkwargs))
          with self.assertRaises(BotorchTensorDimensionError):
              hv.compute(pareto_Y=torch.empty(1, 1, 2, **tkwargs))
          with self.assertRaises(BotorchTensorDimensionError):
              hv.compute(pareto_Y=torch.empty(1, 3, **tkwargs))
  
          # test no pareto points
          pareto_Y = (ref_point - 1).view(1, 2)
          volume = hv.compute(pareto_Y)
          self.assertEqual(volume, 0.0)
  
          # test 1-d
          hv = Hypervolume(ref_point[:1])
          volume = hv.compute(pareto_Y=torch.ones(1, 1, **tkwargs))
          self.assertEqual(volume, 1.0)
  
          # test m=2
          hv = Hypervolume(ref_point)
          pareto_Y = torch.tensor(
              [
                  [8.5, 3.0],
                  [8.5, 3.5],
                  [5.0, 5.0],
                  [9.0, 1.0],
                  [4.0, 5.0],
              ],
              **tkwargs,
          )
          volume = hv.compute(pareto_Y=pareto_Y)
          self.assertTrue(abs(volume - 37.75) < EPS)
  
          # test nonzero reference point
          ref_point = torch.tensor([1.0, 0.5], **tkwargs)
          hv = Hypervolume(ref_point)
          volume = hv.compute(pareto_Y=pareto_Y)
          self.assertTrue(abs(volume - 28.75) < EPS)
  
          # test m=3
          # ref_point = torch.tensor([-1.1, -1.1, -1.1], **tkwargs)
          ref_point = torch.tensor([-2.1, -2.5, -2.3], **tkwargs)
          hv = Hypervolume(ref_point)
          pareto_Y = torch.tensor(
              [[-1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0]],
              **tkwargs,
          )
          volume = hv.compute(pareto_Y=pareto_Y)
          self.assertTrue(abs(volume - 11.075) < EPS)
          # self.assertTrue(abs(volume - 0.45980908291719647) < EPS)
  
          # test m=4
          ref_point = torch.tensor([-2.1, -2.5, -2.3, -2.0], **tkwargs)
          hv = Hypervolume(ref_point)
          pareto_Y = torch.tensor(
              [
                  [-1.0, 0.0, 0.0, 0.0],
                  [0.0, -1.0, 0.0, 0.0],
                  [0.0, 0.0, -1.0, 0.0],
                  [0.0, 0.0, 0.0, -1.0],
              ],
              **tkwargs,
          )
          volume = hv.compute(pareto_Y=pareto_Y)
          self.assertTrue(abs(volume - 23.15) < EPS)
  
          # test m=5
          # this pareto front is from DTLZ2 and covers several edge cases
          ref_point = torch.full(torch.Size([5]), -1.1, **tkwargs)
          hv = Hypervolume(ref_point)
          pareto_Y = torch.tensor(pareto_Y_5d, **tkwargs)
          volume = hv.compute(pareto_Y)
          self.assertTrue(abs(volume - 0.42127855991587) < EPS)
  
file_path: botorch/test/utils/multi_objective/test_hypervolume.py
imports: from __future__ import annotations
  import torch
  from botorch.exceptions.errors import BotorchError, BotorchTensorDimensionError
  from botorch.utils.multi_objective.hypervolume import Hypervolume, infer_reference_point
  from botorch.utils.testing import BotorchTestCase
label_desc: Use image node_id 1 for calling the TestHypervolume obj's underlying member method code with example usage: obj.test_hypervolume() without return types