code: def _extract_generator_run(trial: BaseTrial) -> GeneratorRun:
      if isinstance(trial, BatchTrial):
          if len(trial.generator_run_structs) > 1:
              raise NotImplementedError(
                  "Run time is not supported with multiple generator runs per trial."
              )
          return trial._generator_run_structs[0].generator_run
      if isinstance(trial, Trial):
          return none_throws(trial.generator_run)
      raise ValueError("Unexpected trial type")
  
imports: from collections import defaultdict
  from typing import Dict, Iterable, List, NamedTuple, Optional, Set, Tuple
  import numpy
  from ax.core.arm import Arm
  from ax.core.base_trial import BaseTrial, TrialStatus
  from ax.core.batch_trial import BatchTrial
  from ax.core.data import Data
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun
  from ax.core.objective import MultiObjective
  from ax.core.observation import ObservationFeatures
  from ax.core.optimization_config import OptimizationConfig
  from ax.core.trial import Trial
  from ax.core.types import ComparisonOp
  from ax.utils.common.typeutils import not_none
  from pyre_extensions import none_throws
label_desc: Use image node_id 5 for calling a global function with example usage: _extract_generator_run(trial) and returns: trial, none_throws