code: def test_list_sampler(self):
      # Test initialization.
      sampler = ListSampler(
          IIDNormalSampler(sample_shape=torch.Size([2])),
          StochasticSampler(sample_shape=torch.Size([2])),
      )
      self.assertIsInstance(sampler.samplers[0], IIDNormalSampler)
      self.assertIsInstance(sampler.samplers[1], StochasticSampler)
      self.assertEqual(sampler.sample_shape, torch.Size([2]))
  
      # Test validation.
      with self.assertRaisesRegex(
          UnsupportedError, "all samplers to have the "
      ):
          ListSampler(
              StochasticSampler(sample_shape=torch.Size([2])),
              StochasticSampler(sample_shape=torch.Size([3])),
          )
  
      # Test basic usage.
      org_samples = torch.rand(1, 5)
      p1 = MockPosterior(samples=org_samples[:, :2])
      p2 = MockPosterior(samples=org_samples[:, 2:])
      p_list = PosteriorList(p1, p2)
      samples = sampler(p_list)
      self.assertAllClose(samples, org_samples.repeat(2, 1, 1))
  
      # Test _update_base_samples.
      sampler = ListSampler(
          IIDNormalSampler(sample_shape=torch.Size([2])),
          SobolQMCNormalSampler(sample_shape=torch.Size([2])),
      )
      sampler2 = ListSampler(
          IIDNormalSampler(sample_shape=torch.Size([2])),
          SobolQMCNormalSampler(sample_shape=torch.Size([2])),
      )
      with mock.patch.object(
          sampler.samplers[0], "_update_base_samples"
      ) as update_0, mock.patch.object(
          sampler.samplers[1], "_update_base_samples"
      ) as update_1:
          sampler._update_base_samples(
              posterior=p_list, base_sampler=sampler2
          )
      update_0.assert_called_once_with(
          posterior=p1, base_sampler=sampler2.samplers[0]
      )
      update_1.assert_called_once_with(
          posterior=p2, base_sampler=sampler2.samplers[1]
      )
  
file_path: botorch/test/sampling/test_list_sampler.py
imports: from unittest import mock
  import torch
  from botorch.exceptions.errors import UnsupportedError
  from botorch.posteriors.posterior_list import PosteriorList
  from botorch.sampling.list_sampler import ListSampler
  from botorch.sampling.normal import IIDNormalSampler, SobolQMCNormalSampler
  from botorch.sampling.stochastic_samplers import StochasticSampler
  from botorch.utils.testing import BotorchTestCase, MockPosterior
label_desc: Use image node_id 1 for calling the TestListSampler obj's underlying member method code with example usage: obj.test_list_sampler() without return types