code: def test_train_prediction(features_df: Optional[pd.DataFrame]):
      if features_df is not None:
          use_feat_dynamic_real = True
          features_df_train = features_df.iloc[:-PREDICTION_LENGTH, :]
      else:
          use_feat_dynamic_real = False
          features_df_train = None
  
      # HTS
      ts_at_bottom_level = random_ts(
          num_ts=NUM_BOTTOM_TS,
          periods=PERIODS,
          freq="H",
      )
      hts = HierarchicalTimeSeries(
          ts_at_bottom_level=ts_at_bottom_level,
          S=S,
      )
  
      dataset = hts.to_dataset(feat_dynamic_real=features_df_train)
  
      estimator = DeepVARHierarchicalEstimator(
          freq=hts.freq,
          prediction_length=PREDICTION_LENGTH,
          trainer=Trainer(
              epochs=1, num_batches_per_epoch=1, hybridize=False
          ),
          S=hts.S,
          use_feat_dynamic_real=use_feat_dynamic_real,
      )
  
      predictor = estimator.train(dataset)
  
      predictor_input = hts.to_dataset(feat_dynamic_real=features_df)
      forecasts = list(predictor.predict(predictor_input))
  
      assert len(forecasts) == len(dataset)
      assert all(
          [
              forecast.samples.shape
              == (100, PREDICTION_LENGTH, hts.num_ts)
              for forecast in forecasts
          ]
      )
  
file_path: gluonts/test/mx/model/deepvar_hierarchical/test_train_prediction_with_hts.py
imports: from typing import Optional
  import numpy
  import pandas
  import pytest
  from gluonts.dataset.hierarchical import HierarchicalTimeSeries
  from gluonts.mx.model.deepvar_hierarchical import DeepVARHierarchicalEstimator
  from gluonts.mx.trainer import Trainer
label_desc: Use image node_id 2 for calling a global function with example usage: test_train_prediction(features_df) without return types