code: def test_linear_mc_objective(self) -> None:
      # Test passes for each seed
      torch.manual_seed(torch.randint(high=1000, size=(1,)))
      for dtype in (torch.float, torch.double):
          weights = torch.rand(3, device=self.device, dtype=dtype)
          obj = LinearMCObjective(weights=weights)
          samples = torch.randn(
              4, 2, 3, device=self.device, dtype=dtype
          )
          atol = 1e-8 if dtype == torch.double else 3e-8
          rtol = 1e-5 if dtype == torch.double else 4e-5
          self.assertAllClose(
              obj(samples), samples @ weights, atol=atol, rtol=rtol
          )
          samples = torch.randn(
              5, 4, 2, 3, device=self.device, dtype=dtype
          )
          self.assertAllClose(
              obj(samples),
              samples @ weights,
              atol=atol,
              rtol=rtol,
          )
          # make sure this errors if sample output dimensions are incompatible
          shape_mismatch_msg = (
              "Output shape of samples not equal to that of weights"
          )
          with self.assertRaisesRegex(RuntimeError, shape_mismatch_msg):
              obj(
                  samples=torch.randn(
                      2, device=self.device, dtype=dtype
                  )
              )
          with self.assertRaisesRegex(RuntimeError, shape_mismatch_msg):
              obj(
                  samples=torch.randn(
                      1, device=self.device, dtype=dtype
                  )
              )
          # make sure we can't construct objectives with multi-dim. weights
          weights_1d_msg = "weights must be a one-dimensional tensor."
          with self.assertRaisesRegex(
              ValueError, expected_regex=weights_1d_msg
          ):
              LinearMCObjective(
                  weights=torch.rand(
                      2, 3, device=self.device, dtype=dtype
                  )
              )
          with self.assertRaisesRegex(
              ValueError, expected_regex=weights_1d_msg
          ):
              LinearMCObjective(
                  weights=torch.tensor(
                      1.0, device=self.device, dtype=dtype
                  )
              )
  
imports: import itertools
  import warnings
  from typing import Optional
  import torch
  from botorch import settings
  from botorch.acquisition import LearnedObjective
  from botorch.acquisition.objective import ConstrainedMCObjective, DEFAULT_NUM_PREF_SAMPLES, ExpectationPosteriorTransform, GenericMCObjective, IdentityMCObjective, LEARNED_OBJECTIVE_PREF_MODEL_MIXED_DTYPE_WARN, LinearMCObjective, MCAcquisitionObjective, PosteriorTransform, ScalarizedPosteriorTransform
  from botorch.exceptions.errors import UnsupportedError
  from botorch.exceptions.warnings import _get_single_precision_warning, InputDataWarning
  from botorch.models.deterministic import PosteriorMeanModel
  from botorch.models.pairwise_gp import PairwiseGP
  from botorch.models.transforms.input import Normalize
  from botorch.posteriors import GPyTorchPosterior
  from botorch.utils import apply_constraints
  from botorch.utils.testing import _get_test_posterior, BotorchTestCase
  from gpytorch.distributions import MultitaskMultivariateNormal, MultivariateNormal
  from linear_operator.operators.dense_linear_operator import to_linear_operator
  from torch import Tensor
label_desc: Use image node_id 1 for calling the TestLinearMCObjective obj's underlying member method code with example usage: obj.test_linear_mc_objective() without return types