docstr: Make sure Pareto-related functions run.
  
  Data is generated manually; this does not check that the points are actually
  Pareto-efficient or that everything works end-to-end.
docstr_tok: ["Make","sure","Pareto-related","functions","run",".","Data","is","generated","manually",";","this","does","not","check","that","the","points","are","actually","Pareto-efficient","or","that","everything","works","end-to-end","."]
code: def helper_test_pareto_frontier(
      self, _, outcome_constraints: Optional[List[OutcomeConstraint]]
  ) -> None:
      """
      Make sure Pareto-related functions run.
  
      Data is generated manually; this does not check that the points are actually
      Pareto-efficient or that everything works end-to-end.
      """
      exp = get_branin_experiment_with_multi_objective(
          has_optimization_config=True, with_batch=True
      )
      for trial in exp.trials.values():
          trial.mark_running(no_runner_required=True).mark_completed()
      metrics_dict = not_none(exp.optimization_config).metrics
      objective_bound = 5.0
      objective_thresholds = [
          ObjectiveThreshold(
              metric=metrics_dict[f"branin_{letter}"],
              bound=objective_bound,
              relative=False,
              op=ComparisonOp.LEQ,
          )
          for letter in "ab"
      ]
      # appease Pyre (this condition is True)
      if isinstance(
          exp.optimization_config, MultiObjectiveOptimizationConfig
      ):
          exp.optimization_config = (
              exp.optimization_config.clone_with_args(
                  objective_thresholds=objective_thresholds,
                  outcome_constraints=outcome_constraints,
              )
          )
  
      n_outcomes = 3 if outcome_constraints is not None else 2
      exp.attach_data(
          get_branin_data_multi_objective(
              trial_indices=exp.trials.keys(), num_objectives=n_outcomes
          ),
      )
      modelbridge = TorchModelBridge(
          search_space=exp.search_space,
          model=MultiObjectiveBotorchModel(),
          optimization_config=exp.optimization_config,
          transforms=[transform_1, transform_2],
          experiment=exp,
          data=exp.fetch_data(),
      )
      with patch(
          PARETO_FRONTIER_EVALUATOR_PATH,
          wraps=pareto_frontier_evaluator,
      ) as wrapped_frontier_evaluator:
          observed_frontier = observed_pareto_frontier(
              modelbridge=modelbridge,
              objective_thresholds=objective_thresholds,
          )
  
      wrapped_frontier_evaluator.assert_called_once()
      self.assertIsNone(wrapped_frontier_evaluator.call_args[1]["X"])
      self.assertEqual(1, len(observed_frontier))
      self.assertEqual(observed_frontier[0].arm_name, "0_0")
  
      with self.assertRaises(ValueError):
          predicted_pareto_frontier(
              modelbridge=modelbridge,
              objective_thresholds=objective_thresholds,
              observation_features=[],
          )
  
      predicted_frontier = predicted_pareto_frontier(
          modelbridge=modelbridge,
          objective_thresholds=objective_thresholds,
          observation_features=None,
      )
      self.assertEqual(predicted_frontier[0].arm_name, "0_0")
  
      observation_features = [
          ObservationFeatures(parameters={"x1": 0.0, "x2": 1.0}),
          # magic number to ensure the model makes one non-negative
          # prediction, so there is a point within the thresholds
          ObservationFeatures(parameters={"x1": -2.0, "x2": 6.3}),
      ]
      extra_outcome = (
          ["branin_c"] if outcome_constraints is not None else []
      )
      observation_data = [
          ObservationData(
              metric_names=["branin_b", "branin_a"] + extra_outcome,
              means=np.arange(1, 1 + n_outcomes),
              covariance=np.eye(n_outcomes),
          ),
          ObservationData(
              metric_names=["branin_a", "branin_b"] + extra_outcome,
              means=np.arange(3, 3 + n_outcomes),
              covariance=np.eye(n_outcomes),
          ),
      ]
      # appease Pyre (this condition is True)
      if isinstance(
          exp.optimization_config, MultiObjectiveOptimizationConfig
      ):
          predicted_frontier = predicted_pareto_frontier(
              modelbridge=modelbridge,
              objective_thresholds=objective_thresholds,
              observation_features=observation_features,
              optimization_config=exp.optimization_config,
          )
      self.assertTrue(len(predicted_frontier) <= 2)
      self.assertIsNone(predicted_frontier[0].arm_name, None)
  
      with patch(
          PARETO_FRONTIER_EVALUATOR_PATH,
          wraps=pareto_frontier_evaluator,
      ) as wrapped_frontier_evaluator:
          (
              observed_frontier,
              f,
              obj_w,
              obj_t,
          ) = get_pareto_frontier_and_configs(
              modelbridge=modelbridge,
              objective_thresholds=objective_thresholds,
              observation_features=observation_features,
              observation_data=observation_data,
              use_model_predictions=False,
          )
  
      wrapped_frontier_evaluator.assert_called_once()
      self.assertEqual(f.shape, (1, n_outcomes))
      self.assertTrue(
          torch.equal(obj_w[:2], -torch.ones(2, dtype=torch.double))
      )
      self.assertTrue(obj_t is not None)
      self.assertTrue(
          torch.equal(
              not_none(obj_t)[:2],
              torch.full((2,), 5.0, dtype=torch.double),
          )
      )
      observed_frontier2 = pareto_frontier(
          modelbridge=modelbridge,
          objective_thresholds=objective_thresholds,
          observation_features=observation_features,
          observation_data=observation_data,
          use_model_predictions=False,
      )
      self.assertEqual(observed_frontier, observed_frontier2)
  
      # Remove the thresholds for testing None handling.
      checked_cast(
          MultiObjectiveOptimizationConfig,
          modelbridge._optimization_config,
      )._objective_thresholds = []
      with patch(
          PARETO_FRONTIER_EVALUATOR_PATH,
          wraps=pareto_frontier_evaluator,
      ) as wrapped_frontier_evaluator:
          (
              observed_frontier,
              f,
              obj_w,
              obj_t,
          ) = get_pareto_frontier_and_configs(
              modelbridge=modelbridge,
              objective_thresholds=None,
              observation_features=observation_features,
              observation_data=observation_data,
              use_model_predictions=False,
          )
      wrapped_frontier_evaluator.assert_called_once()
      self.assertIsNone(wrapped_frontier_evaluator.call_args[1]["X"])
      true_Y = torch.tensor(
          [[2.0, 1.0], [3.0, 4.0]], dtype=torch.double
      )
      self.assertTrue(
          torch.equal(
              wrapped_frontier_evaluator.call_args[1]["Y"][:, :2],
              true_Y,
          )
      )
      self.assertTrue(
          torch.equal(objective_bound - f[:, :2], true_Y[1:, :])
      )
      self.assertIsNone(obj_t)
  
imports: from contextlib import ExitStack
  from typing import List, Optional
  from unittest.mock import patch
  import numpy
  import torch
  from ax.core.metric import Metric
  from ax.core.observation import ObservationData, ObservationFeatures
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig
  from ax.core.outcome_constraint import ComparisonOp, ObjectiveThreshold, OutcomeConstraint
  from ax.core.parameter_constraint import ParameterConstraint
  from ax.exceptions.core import UnsupportedError
  from ax.modelbridge.factory import get_sobol
  from ax.modelbridge.modelbridge_utils import get_pareto_frontier_and_configs, observed_hypervolume, observed_pareto_frontier, pareto_frontier, predicted_hypervolume, predicted_pareto_frontier
  from ax.modelbridge.registry import Cont_X_trans, ST_MTGP_trans, Y_trans
  from ax.modelbridge.torch import TorchModelBridge
  from ax.models.torch.botorch_modular.model import BoTorchModel
  from ax.models.torch.botorch_moo import MultiObjectiveBotorchModel
  from ax.models.torch.botorch_moo_defaults import infer_objective_thresholds, pareto_frontier_evaluator
  from ax.service.utils.report_utils import exp_to_df
  from ax.utils.common.testutils import TestCase
  from ax.utils.common.typeutils import checked_cast, not_none
  from ax.utils.testing.core_stubs import get_branin_data_multi_objective, get_branin_experiment_with_multi_objective, get_hierarchical_search_space, get_hss_trials_with_fixed_parameter, get_non_monolithic_branin_moo_data, TEST_SOBOL_SEED
  from ax.utils.testing.mock import fast_botorch_optimize
  from ax.utils.testing.modeling_stubs import transform_1, transform_2
  from botorch.utils.multi_objective.pareto import is_non_dominated
label_desc: Use image node_id 1 for calling the MultiObjectiveTorchModelBridgeTest obj's underlying member method code with example usage: obj.helper_test_pareto_frontier(_, outcome_constraints) without return types