code: def test_fantasized_noise(self):
      for batch_shape, m, dtype, use_octf in itertools.product(
          (torch.Size(), torch.Size([2])),
          (1, 2),
          (torch.float, torch.double),
          (False, True),
      ):
          tkwargs = {"device": self.device, "dtype": dtype}
          octf = (
              Standardize(m=m, batch_shape=batch_shape)
              if use_octf
              else None
          )
          model, _ = self._get_model_and_data(
              batch_shape=batch_shape,
              m=m,
              outcome_transform=octf,
              **tkwargs,
          )
          # fantasize
          X_f = torch.rand(
              torch.Size(batch_shape + torch.Size([4, 1])), **tkwargs
          )
          sampler = SobolQMCNormalSampler(sample_shape=torch.Size([3]))
          fm = model.fantasize(X=X_f, sampler=sampler)
          noise = (
              model.likelihood.noise.unsqueeze(-1)
              if m == 1
              else model.likelihood.noise.transpose(-1, -2)
          )
          avg_noise = noise.mean(dim=-2, keepdim=True)
          fm_noise = (
              fm.likelihood.noise.unsqueeze(-1)
              if m == 1
              else fm.likelihood.noise.transpose(-1, -2)
          )
  
          self.assertTrue((fm_noise[..., -4:, :] == avg_noise).all())
          # pass tensor of noise
          # noise is assumed to be outcome transformed
          # batch shape x n' x m
          obs_noise = torch.full(
              X_f.shape[:-1] + torch.Size([m]),
              0.1,
              dtype=dtype,
              device=self.device,
          )
          fm = model.fantasize(
              X=X_f, sampler=sampler, observation_noise=obs_noise
          )
          fm_noise = (
              fm.likelihood.noise.unsqueeze(-1)
              if m == 1
              else fm.likelihood.noise.transpose(-1, -2)
          )
          self.assertTrue((fm_noise[..., -4:, :] == obs_noise).all())
          # test batch shape x 1 x m
          obs_noise = torch.full(
              X_f.shape[:-2] + torch.Size([1, m]),
              0.1,
              dtype=dtype,
              device=self.device,
          )
          fm = model.fantasize(
              X=X_f, sampler=sampler, observation_noise=obs_noise
          )
          fm_noise = (
              fm.likelihood.noise.unsqueeze(-1)
              if m == 1
              else fm.likelihood.noise.transpose(-1, -2)
          )
          self.assertTrue(
              (
                  fm_noise[..., -4:, :]
                  == obs_noise.expand(X_f.shape[:-1] + torch.Size([m]))
              ).all()
          )
  
imports: import itertools
  import warnings
  import torch
  from botorch.exceptions.warnings import OptimizationWarning
  from botorch.fit import fit_gpytorch_mll
  from botorch.models.gp_regression import FixedNoiseGP, HeteroskedasticSingleTaskGP, SingleTaskGP
  from botorch.models.transforms import Normalize, Standardize
  from botorch.models.transforms.input import InputStandardize
  from botorch.posteriors import GPyTorchPosterior
  from botorch.sampling import SobolQMCNormalSampler
  from botorch.utils.datasets import SupervisedDataset
  from botorch.utils.sampling import manual_seed
  from botorch.utils.test_helpers import get_pvar_expected
  from botorch.utils.testing import _get_random_data, BotorchTestCase
  from gpytorch.kernels import MaternKernel, RBFKernel, ScaleKernel
  from gpytorch.likelihoods import _GaussianLikelihoodBase, FixedNoiseGaussianLikelihood, GaussianLikelihood, HeteroskedasticNoise
  from gpytorch.means import ConstantMean, ZeroMean
  from gpytorch.mlls.exact_marginal_log_likelihood import ExactMarginalLogLikelihood
  from gpytorch.mlls.noise_model_added_loss_term import NoiseModelAddedLossTerm
  from gpytorch.priors import GammaPrior
label_desc: Use image node_id 5 for calling the TestFixedNoiseGP obj's underlying member method code with example usage: obj.test_fantasized_noise() without return types