code: def test_SubsetModel(self) -> None:
      x = torch.zeros(1, 1)
      y = torch.rand(1, 2)
      obj_t = torch.rand(2)
      model = SingleTaskGP(x, y)
      self.assertEqual(model.num_outputs, 2)
      # basic test, can subset
      obj_weights = torch.tensor([1.0, 0.0])
      subset_model_results = subset_model(model, obj_weights)
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertIsNone(ocs_sub)
      self.assertIsNone(obj_t_sub)
      self.assertEqual(model_sub.num_outputs, 1)
      self.assertTrue(torch.equal(obj_weights_sub, torch.tensor([1.0])))
      # basic test, cannot subset
      obj_weights = torch.tensor([1.0, 2.0])
      subset_model_results = subset_model(model, obj_weights)
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertIsNone(ocs_sub)
      self.assertIsNone(obj_t_sub)
      self.assertIs(model_sub, model)  # check identity
      self.assertIs(obj_weights_sub, obj_weights)  # check identity
      self.assertTrue(
          torch.equal(
              subset_model_results.indices, torch.tensor([0, 1])
          )
      )
      # test w/ outcome constraints, can subset
      obj_weights = torch.tensor([1.0, 0.0])
      ocs = (torch.tensor([[1.0, 0.0]]), torch.tensor([1.0]))
      subset_model_results = subset_model(model, obj_weights, ocs)
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertEqual(model_sub.num_outputs, 1)
      self.assertIsNone(obj_t_sub)
      self.assertTrue(torch.equal(obj_weights_sub, torch.tensor([1.0])))
      # pyre-fixme[16]: Optional type has no attribute `__getitem__`.
      self.assertTrue(torch.equal(ocs_sub[0], torch.tensor([[1.0]])))
      self.assertTrue(torch.equal(ocs_sub[1], torch.tensor([1.0])))
      self.assertTrue(
          torch.equal(subset_model_results.indices, torch.tensor([0]))
      )
      # test w/ outcome constraints, cannot subset
      obj_weights = torch.tensor([1.0, 0.0])
      ocs = (torch.tensor([[0.0, 1.0]]), torch.tensor([1.0]))
      subset_model_results = subset_model(model, obj_weights, ocs)
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertIs(model_sub, model)  # check identity
      self.assertIsNone(obj_t_sub)
      self.assertIs(obj_weights_sub, obj_weights)  # check identity
      self.assertIs(ocs_sub, ocs)  # check identity
      self.assertTrue(
          torch.equal(
              subset_model_results.indices, torch.tensor([0, 1])
          )
      )
      # test w/ objective thresholds, cannot subset
      obj_weights = torch.tensor([1.0, 0.0])
      ocs = (torch.tensor([[0.0, 1.0]]), torch.tensor([1.0]))
      subset_model_results = subset_model(
          model, obj_weights, ocs, obj_t
      )
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertIs(model_sub, model)  # check identity
      self.assertIs(obj_t, obj_t_sub)
      self.assertIs(obj_weights_sub, obj_weights)  # check identity
      self.assertTrue(
          torch.equal(
              subset_model_results.indices, torch.tensor([0, 1])
          )
      )
      self.assertIs(ocs_sub, ocs)  # check identity
      # test w/ objective thresholds, can subset
      obj_weights = torch.tensor([1.0, 0.0])
      ocs = (torch.tensor([[1.0, 0.0]]), torch.tensor([1.0]))
      subset_model_results = subset_model(
          model, obj_weights, ocs, obj_t
      )
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertTrue(
          torch.equal(subset_model_results.indices, torch.tensor([0]))
      )
      self.assertEqual(model_sub.num_outputs, 1)
      self.assertTrue(torch.equal(obj_weights_sub, torch.tensor([1.0])))
      # pyre-fixme[6]: For 1st param expected `Tensor` but got `Optional[Tensor]`.
      self.assertTrue(torch.equal(obj_t_sub, obj_t[:1]))
      self.assertTrue(torch.equal(ocs_sub[0], torch.tensor([[1.0]])))
      self.assertTrue(torch.equal(ocs_sub[1], torch.tensor([1.0])))
      # test unsupported
      yvar = torch.ones(1, 2)
      model = HeteroskedasticSingleTaskGP(x, y, yvar)
      subset_model_results = subset_model(model, obj_weights)
      model_sub = subset_model_results.model
      obj_weights_sub = subset_model_results.objective_weights
      ocs_sub = subset_model_results.outcome_constraints
      obj_t_sub = subset_model_results.objective_thresholds
      self.assertIsNone(ocs_sub)
      self.assertIs(model_sub, model)  # check identity
      self.assertIs(obj_weights_sub, obj_weights)  # check identity
      self.assertTrue(
          torch.equal(
              subset_model_results.indices, torch.tensor([0, 1])
          )
      )
      # test error on size inconsistency
      obj_weights = torch.ones(3)
      with self.assertRaises(RuntimeError):
          subset_model(model, obj_weights)
  
file_path: Ax/ax/models/tests/test_torch_model_utils.py
imports: import numpy
  import torch
  from ax.exceptions.model import ModelError
  from ax.models.torch.utils import _generate_sobol_points, is_noiseless, normalize_indices, subset_model, tensor_callable_to_array_callable
  from ax.utils.common.testutils import TestCase
  from botorch.models import HeteroskedasticSingleTaskGP, ModelListGP, SingleTaskGP
  from torch import Tensor
label_desc: Use image node_id 3 for calling the TorchUtilsTest obj's underlying member method code with example usage: obj.test_SubsetModel() without return types