code: def unpack_forecasts(
      forecast_at_all_levels_it: Iterator[SampleForecast],
      temporal_hierarchy: TemporalHierarchy,
      target_temporal_hierarchy: TemporalHierarchy,
      num_samples: int = 100,
  ) -> Iterator[SampleForecast]:
      """
  
      :param forecast_at_all_levels_it:
          Each element of the iterator has `SampleForecast` object with samples of shape:
              (`num_samples`, `prediction_length_at_root`, `total_num_nodes`),
          where the order of the last axis is level-wise left-right ordering of the hierarchy.
      :param temporal_hierarchy:
      :param num_samples:
          Used only for asserting shapes.
      :return:
      This will get the forecasts in this order:
          (ts_1_6M, ts_1_2M, ts_1_1M, ts_2_6M, ts_2_2M, ts_2_1M, ...)
  
      """
  
      num_nodes_per_level = temporal_hierarchy.num_nodes_per_level
  
      for forecast in forecast_at_all_levels_it:
          # We iterate over each time series and unpack forecasts for that time series at different
          # time granularites at the same time.
          samples_at_all_levels = forecast.samples
          assert num_samples == forecast.num_samples
  
          start_ix = 0
          for num_nodes, agg_freq, agg_multiple in zip(
              num_nodes_per_level,
              temporal_hierarchy.freq_strs,
              temporal_hierarchy.agg_multiples,
          ):
              end_ix = start_ix + num_nodes
  
              forecast_start_date = pd.Period(
                  str(forecast.start_date),
                  freq=(
                      agg_multiple * forecast.start_date.freq
                  ).freqstr,
              )
              agg_forecast = SampleForecast(
                  samples=samples_at_all_levels[
                      ..., start_ix:end_ix
                  ].reshape(num_samples, -1),
                  start_date=forecast_start_date,
                  item_id=forecast.item_id,
                  info=forecast.info,
              )
              start_ix = end_ix
  
              if (
                  agg_multiple
                  in target_temporal_hierarchy.agg_multiples
              ):
                  yield agg_forecast
  
          # Make sure we used all the samples!
          assert start_ix == samples_at_all_levels.shape[-1]
  
imports: from typing import Iterator, List
  import numpy
  import pandas
  from gluonts.core.component import validated
  from gluonts.model.forecast import SampleForecast
  from gluonts.mx import Tensor
label_desc: Use image node_id 5 for calling a global function with example usage: unpack_forecasts(forecast_at_all_levels_it, temporal_hierarchy, target_temporal_hierarchy, num_samples) without return types