code: def test_forecasts(
      sine7,
      method_name,
      fmethod,
      nonnegative,
      level,
      covariance,
      algorithm,
  ):
      train_datasets = sine7(nonnegative=nonnegative)
      prediction_length = 10
  
      (train_dataset, test_dataset, metadata) = (
          train_datasets.train,
          train_datasets.test,
          train_datasets.metadata,
      )
  
      freq = metadata.freq
      nodes = metadata.nodes
      target_dim, num_bottom_ts = train_datasets.metadata.S.shape
  
      params = dict(
          freq=freq,
          prediction_length=prediction_length,
          is_hts=True,
          target_dim=target_dim,
          num_bottom_ts=num_bottom_ts,
          nodes=nodes,
          method_name=method_name,
          fmethod=fmethod,
          nonnegative=nonnegative,
          covariance=covariance,
          algorithm=algorithm,
          level=level,
      )
  
      predictor = RHierarchicalForecastPredictor(**params)
      predictions = list(predictor.predict(train_dataset))
  
      assert all(
          isinstance(prediction, SampleForecast)
          for prediction in predictions
      )
  
      assert all(prediction.freq == freq for prediction in predictions)
  
      assert all(
          prediction.prediction_length == prediction_length
          for prediction in predictions
      )
  
      assert all(
          prediction.start_date == forecast_start(data)
          for data, prediction in zip(train_dataset, predictions)
      )
  
      agg_metrics, item_metrics = backtest_metrics(
          test_dataset=test_dataset,
          predictor=predictor,
          evaluator=MultivariateEvaluator(
              quantiles=(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
          ),
      )
  
      assert agg_metrics["mean_wQuantileLoss"] < TOLERANCE
      assert agg_metrics["NRMSE"] < TOLERANCE
      assert agg_metrics["RMSE"] < TOLERANCE
  
file_path: gluonts/test/ext/r_forecast/test_r_hierarchical_predictor.py
imports: from typing import List, Tuple, Union
  import itertools
  import pytest
  from gluonts.core import serde
  from gluonts.dataset.util import forecast_start
  from gluonts.evaluation import MultivariateEvaluator, backtest_metrics
  from gluonts.model import SampleForecast
  from gluonts.ext.r_forecast import RHierarchicalForecastPredictor, R_IS_INSTALLED, RPY2_IS_INSTALLED, SUPPORTED_HIERARCHICAL_METHODS
label_desc: Use image node_id 2 for calling a global function with example usage: test_forecasts(sine7, method_name, fmethod, nonnegative, level, covariance, algorithm) without return types