code: def test_get_trace(self) -> None:
      # Alias for easier access.
      get_trace = BestPointMixin._get_trace
  
      # Single objective, minimize.
      exp = get_experiment_with_observations(
          observations=[[11], [10], [9], [15], [5]], minimize=True
      )
      self.assertEqual(get_trace(exp), [11, 10, 9, 9, 5])
      # Same experiment with maximize via new optimization config.
      opt_conf = not_none(exp.optimization_config).clone()
      opt_conf.objective.minimize = False
      self.assertEqual(get_trace(exp, opt_conf), [11, 11, 11, 15, 15])
  
      # Scalarized.
      exp = get_experiment_with_observations(
          observations=[[1, 1], [2, 2], [3, 3]],
          scalarized=True,
      )
      self.assertEqual(get_trace(exp), [2, 4, 6])
  
      # Multi objective.
      exp = get_experiment_with_observations(
          observations=[
              [1, 1],
              [-1, 100],
              [1, 2],
              [3, 3],
              [2, 4],
              [2, 1],
          ],
      )
      self.assertEqual(get_trace(exp), [1, 1, 2, 9, 11, 11])
  
      # W/o ObjectiveThresholds (infering ObjectiveThresholds from nadir point)
      checked_cast(
          MultiObjectiveOptimizationConfig, exp.optimization_config
      ).objective_thresholds = []
      self.assertEqual(get_trace(exp), [0.0, 0.0, 2.0, 8.0, 11.0, 11.0])
  
      # W/ constraints.
      exp = get_experiment_with_observations(
          observations=[
              [-1, 1, 1],
              [1, 2, 1],
              [3, 3, -1],
              [2, 4, 1],
              [2, 1, 1],
          ],
          constrained=True,
      )
      self.assertEqual(get_trace(exp), [0, 2, 2, 8, 8])
  
      # W/ relative constraints & status quo.
      exp.status_quo = Arm(
          parameters={"x": 0.5, "y": 0.5}, name="status_quo"
      )
      exp.optimization_config.outcome_constraints[0].bound = 1.0
      exp.optimization_config.outcome_constraints[0].relative = True
      # Fails if there's no data for status quo.
      with self.assertRaisesRegex(
          DataRequiredError, "relative constraint"
      ):
          get_trace(exp)
      # Add data for status quo.
      trial = Trial(experiment=exp).add_arm(arm=exp.status_quo)
      df_dict = [
          {
              "trial_index": trial.index,
              "metric_name": m,
              "arm_name": "status_quo",
              "mean": 0.0,
              "sem": 0.0,
          }
          for m in ["m1", "m2", "m3"]
      ]
      status_quo_data = Data(df=pd.DataFrame.from_records(df_dict))
      exp.attach_data(data=status_quo_data)
      self.assertEqual(get_trace(exp), [0, 2, 2, 8, 8])
  
      # W/ first objective being minimized.
      exp = get_experiment_with_observations(
          observations=[[1, 1], [-1, 2], [3, 3], [-2, 4], [2, 1]],
          minimize=True,
      )
      self.assertEqual(get_trace(exp), [0, 2, 2, 8, 8])
  
      # W/ empty data.
      exp = get_experiment_with_trial()
      self.assertEqual(get_trace(exp), [])
  
      # test batch trial
      exp = get_experiment_with_batch_trial()
      trial = exp.trials[0]
      exp.optimization_config.outcome_constraints[0].relative = False
      trial.mark_running(no_runner_required=True).mark_completed()
      df_dict = []
      for i, arm in enumerate(trial.arms):
          df_dict.extend(
              [
                  {
                      "trial_index": 0,
                      "metric_name": m,
                      "arm_name": arm.name,
                      "mean": float(i),
                      "sem": 0.0,
                  }
                  for m in exp.metrics.keys()
              ]
          )
      exp.attach_data(Data(df=pd.DataFrame.from_records(df_dict)))
      self.assertEqual(get_trace(exp), [len(trial.arms) - 1])
      # test that there is performance metric in the trace for each
      # completed/early-stopped trial
      trial1 = checked_cast(BatchTrial, trial).clone_to()
      trial1.mark_abandoned()
      arms = get_arms_from_dict(get_arm_weights2())
      trial2 = exp.new_batch_trial(GeneratorRun(arms))
      trial2.mark_running(no_runner_required=True).mark_completed()
      df_dict2 = []
      for i, arm in enumerate(trial2.arms):
          df_dict2.extend(
              [
                  {
                      "trial_index": 2,
                      "metric_name": m,
                      "arm_name": arm.name,
                      "mean": 10 * float(i),
                      "sem": 0.0,
                  }
                  for m in exp.metrics.keys()
              ]
          )
      exp.attach_data(Data(df=pd.DataFrame.from_records(df_dict2)))
      self.assertEqual(get_trace(exp), [2, 20.0])
  
file_path: Ax/ax/service/tests/test_best_point.py
imports: from unittest.mock import Mock
  import pandas
  from ax.core.arm import Arm
  from ax.core.batch_trial import BatchTrial
  from ax.core.data import Data
  from ax.core.generator_run import GeneratorRun
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig
  from ax.core.trial import Trial
  from ax.exceptions.core import DataRequiredError
  from ax.service.utils.best_point_mixin import BestPointMixin
  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_arm_weights2, get_arms_from_dict, get_experiment_with_batch_trial, get_experiment_with_observations, get_experiment_with_trial
label_desc: Use image node_id 1 for calling the TestBestPointMixin obj's underlying member method code with example usage: obj.test_get_trace() without return types