code: def evaluate_predictor(
      predictor: Predictor,
      test_dataset: Dataset,
      freq: str,
      metrics: List[str] = ["mean_wQuantileLoss"],
      evaluate_all_levels: bool = False,
  ):
      pred_input_it = truncate_target(
          test_dataset,
          prediction_length=predictor.prediction_length,
      )
  
      forecast_it = make_predictions(
          pred_input=pred_input_it,
          predictor=predictor,
          forecasts_at_all_levels=evaluate_all_levels,
      )
      test_ts_it = to_dataframe_it(test_dataset)
  
      evaluator = Evaluator(
          quantiles=(np.arange(20) / 20.0)[1:], num_workers=0
      )
      if not evaluate_all_levels:
          # Evaluate only the bottom level.
          agg_metrics, _ = evaluator(
              ts_iterator=test_ts_it,
              fcst_iterator=forecast_it,
          )
          metrics_to_return = {
              metric_str: agg_metrics[metric_str]
              for metric_str in metrics
          }
          return metrics_to_return
  
      # Evaluate all levels.
      metrics_to_return = evaluate_forecasts_at_all_levels(
          forecast_at_all_levels_it=forecast_it,
          test_ts_at_all_levels_it=get_ts_at_all_levels(
              ts_it=test_ts_it,
              temporal_hierarchy=TEMPORAL_HIERARCHIES[freq],
              prediction_length=predictor.prediction_length,
              target_temporal_hierarchy=TEMPORAL_HIERARCHIES[freq],
          ),
          temporal_hierarchy=TEMPORAL_HIERARCHIES[freq],
          evaluator=evaluator,
          metrics=metrics,
      )
      return metrics_to_return
  
file_path: gluonts/src/gluonts/nursery/temporal_hierarchical_forecasting/eval/evaluation.py
imports: from itertools import tee
  from typing import List
  import numpy
  from gluonts.dataset.common import Dataset
  from gluonts.evaluation import Evaluator
  from gluonts.model.predictor import Predictor
  from gluonts.nursery.temporal_hierarchical_forecasting.utils.common import TEMPORAL_HIERARCHIES
  from gluonts.nursery.temporal_hierarchical_forecasting.utils.utils import get_ts_at_all_levels, unpack_forecasts
  from gluonts.nursery.temporal_hierarchical_forecasting.utils.gluonts_helper import make_predictions, to_dataframe_it, truncate_target
label_desc: Use image node_id 1 for calling a global function with example usage: evaluate_predictor(predictor, test_dataset, freq, metrics, evaluate_all_levels) and returns: metrics_to_return, metrics_to_return