def testSubsetModel(self):
    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)
    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])))
    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)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    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])))
    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])))
    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)
    self.assertIsNone(obj_t_sub)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertIs(ocs_sub, ocs)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    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)
    self.assertIs(obj_t, obj_t_sub)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    self.assertIs(ocs_sub, ocs)
    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])))
    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])))
    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)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    obj_weights = torch.ones(3)
    with self.assertRaises(RuntimeError):
        subset_model(model, obj_weights)
def testSubsetModel(self):
    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)
    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])))
    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)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    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])))
    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])))
    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)
    self.assertIsNone(obj_t_sub)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertIs(ocs_sub, ocs)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    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)
    self.assertIs(obj_t, obj_t_sub)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    self.assertIs(ocs_sub, ocs)
    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])))
    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])))
    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)
    self.assertIs(obj_weights_sub, obj_weights)
    self.assertTrue(torch.equal(subset_model_results.indices, torch.tensor([0, 1])))
    obj_weights = torch.ones(3)
    with self.assertRaises(RuntimeError):
        subset_model(model, obj_weights)