code: def raw_data_to_evaluation(
      raw_data: TEvaluationOutcome,
      metric_names: List[str],
  ) -> TEvaluationOutcome:
      """Format the trial evaluation data to a standard `TTrialEvaluation`
      (mapping from metric names to a tuple of mean and SEM) representation, or
      to a TMapTrialEvaluation.
  
      Note: this function expects raw_data to be data for a `Trial`, not a
      `BatchedTrial`.
      """
      if isinstance(raw_data, dict):
          if any(isinstance(x, dict) for x in raw_data.values()):
              raise UserInputError(
                  "Raw data is expected to be just for one arm."
              )
          for metric_name, dat in raw_data.items():
              if not isinstance(dat, tuple):
                  if not isinstance(dat, (float, int)):
                      raise UserInputError(
                          "Raw data for an arm is expected to either be a tuple of "
                          "numerical mean and SEM or just a numerical mean."
                          f"Got: {dat} for metric '{metric_name}'."
                      )
                  raw_data[metric_name] = (float(dat), None)
          return raw_data
      try:
          validate_evaluation_outcome(outcome=raw_data)
      except Exception as e:
          raise UserInputError(
              "Raw data does not conform to the expected structure. For simple "
              "evaluations of one or more metrics, `raw_data` is expected to be "
              "a dictionary of the form `{metric_name -> mean}` or `{metric_name "
              "-> (mean, SEM)}`. For fidelity or mapping (e.g., early stopping) "
              "evaluation, the expected format is `[(fidelities, {metric_name -> "
              "(mean, SEM)})]` or `[({mapping_key, mapping_value}, {metric_name -> "
              "(mean, SEM)})]`."
              f"Received {raw_data=}. Original validation error: {e}."
          )
      if isinstance(raw_data, list):
          validate_evaluation_outcome(raw_data)
          return raw_data
      elif len(metric_names) > 1:
          raise UserInputError(
              "Raw data must be a dictionary of metric names to mean "
              "for experiments with multiple metrics attached. "
              f"Got {raw_data=} for {metric_names=}."
          )
      elif isinstance(raw_data, tuple):
          return {metric_names[0]: raw_data}
      elif isinstance(raw_data, (float, int)):
          return {metric_names[0]: (raw_data, None)}
      elif isinstance(
          raw_data, (np.float32, np.float64, np.int32, np.int64)
      ):
          return {
              metric_names[0]: (
                  numpy_type_to_python_type(raw_data),
                  None,
              )
          }
      else:
          raise UserInputError(
              "Raw data has an invalid type. The data must either be in the form "
              "of a dictionary of metric names to mean, sem tuples, "
              "or a single mean, sem tuple, or a single mean."
          )
  
file_path: Ax/ax/core/formatting_utils.py
imports: from enum import Enum
  from typing import cast, Dict, List, Optional, Tuple, Type, Union
  import numpy
  from ax.core.data import Data
  from ax.core.map_data import MapData
  from ax.core.types import TEvaluationOutcome, TMapTrialEvaluation, TTrialEvaluation, validate_evaluation_outcome
  from ax.exceptions.core import UserInputError
  from ax.utils.common.typeutils import numpy_type_to_python_type
label_desc: Use image node_id 1 for calling a global function with example usage: raw_data_to_evaluation(raw_data, metric_names) and returns: raw_data, raw_data, dict, dict, dict