code: def test_project_to_target_fidelity(self):
      for batch_shape, dtype in itertools.product(
          ([], [2]), (torch.float, torch.double)
      ):
          X = torch.rand(
              *batch_shape, 3, 4, device=self.device, dtype=dtype
          )
          # test default behavior
          X_proj = project_to_target_fidelity(X)
          ones = torch.ones(
              *X.shape[:-1], 1, device=self.device, dtype=dtype
          )
          self.assertTrue(torch.equal(X_proj[..., :, [-1]], ones))
          self.assertTrue(torch.equal(X_proj[..., :-1], X[..., :-1]))
          # test custom target fidelity
          target_fids = {2: 0.5}
          X_proj = project_to_target_fidelity(
              X, target_fidelities=target_fids
          )
          self.assertTrue(torch.equal(X_proj[..., :, [2]], 0.5 * ones))
          # test multiple target fidelities
          target_fids = {2: 0.5, 0: 0.1}
          X_proj = project_to_target_fidelity(
              X, target_fidelities=target_fids
          )
          self.assertTrue(torch.equal(X_proj[..., :, [0]], 0.1 * ones))
          self.assertTrue(torch.equal(X_proj[..., :, [2]], 0.5 * ones))
          # test gradients
          X.requires_grad_(True)
          X_proj = project_to_target_fidelity(
              X, target_fidelities=target_fids
          )
          out = (X_proj**2).sum()
          out.backward()
          self.assertTrue(torch.all(X.grad[..., [0, 2]] == 0))
          self.assertTrue(
              torch.equal(X.grad[..., [1, 3]], 2 * X[..., [1, 3]])
          )
          # test X without fidelity dims
          X_proj = project_to_target_fidelity(
              X[..., :2], target_fidelities=target_fids, d=4
          )
          self.assertTrue(torch.equal(X_proj[..., :, [0]], 0.1 * ones))
          self.assertTrue(torch.equal(X_proj[..., :, [2]], 0.5 * ones))
          # test unexpected shape
          msg = (
              "X must have a last dimension with size `d` or `d-d_f`,"
              " but got 3."
          )
          with self.assertRaisesRegex(BotorchTensorDimensionError, msg):
              project_to_target_fidelity(
                  X[..., :3], target_fidelities=target_fids, d=4
              )
  
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 TestFidelityUtils obj's underlying member method code with example usage: obj.test_project_to_target_fidelity() without return types