code: def evaluate_forecasts_at_all_levels(
      forecast_at_all_levels_it,
      test_ts_at_all_levels_it,
      temporal_hierarchy,
      evaluator,
      metrics: List[str] = ["mean_wQuantileLoss"],
  ):
      # Order of forecasts obtained e.g., in case of the hierarchy: [6M, 2M, 1M]
      # (ts_1_6M, ts_1_2M, ts_1_1M, ts_2_6M, ts_2_2M, ts_2_1M, ...)
      forecast_at_all_levels_unpacked_it = unpack_forecasts(
          forecast_at_all_levels_it=forecast_at_all_levels_it,
          temporal_hierarchy=temporal_hierarchy,
          target_temporal_hierarchy=temporal_hierarchy,
      )
  
      num_levels = len(temporal_hierarchy.agg_multiples)
  
      # In one go, we can get item metrics for time series that have the same frequency.
      # So we create `num_levels` copies of the iterator and obtain the item metrics
      # for each level independently.
      forecast_at_all_levels_unpacked_it_set = tee(
          forecast_at_all_levels_unpacked_it,
          num_levels,
      )
      test_ts_at_all_levels_it_set = tee(
          test_ts_at_all_levels_it, num_levels
      )
  
      # Since forecasts for all granularities are in the same iterable,
      # we need a way to iterate through forecasts skipping some elements.
      def skip_iter(it, num_skips: int, offset: int):
          for _ in range(offset):
              next(it)
          for item in it:
              for _ in range(num_skips):
                  next(
                      it, None
                  )  # None: in case the `it` is already exhausted.
              yield item
  
      metrics_to_return = {}
      for level in range(num_levels):
          agg_metrics_level, metrics_per_ts_level = evaluator(
              ts_iterator=skip_iter(
                  test_ts_at_all_levels_it_set[level],
                  num_skips=num_levels - 1,
                  offset=level,
              ),
              fcst_iterator=skip_iter(
                  forecast_at_all_levels_unpacked_it_set[level],
                  num_skips=num_levels - 1,
                  offset=level,
              ),
          )
  
          for metric_name in metrics:
              metrics_to_return[
                  f"Freq_{temporal_hierarchy.freq_strs[level]}_{metric_name}"
              ] = agg_metrics_level[metric_name]
  
      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 2 for calling a global function with example usage: evaluate_forecasts_at_all_levels(forecast_at_all_levels_it, test_ts_at_all_levels_it, temporal_hierarchy, evaluator, metrics) and returns: metrics_to_return