code: def test_poisson(
      train_window,
      min_train_window,
      test_window,
      min_test_window,
      stride,
      engine,
  ):
      duration = 30
      obs_dim = 2
      covariates = torch.zeros(duration, 0)
      rate = torch.randn(duration, obs_dim) + 4
      counts = dist.Poisson(rate).sample()
  
      # Transform count data to log domain.
      data = counts.log1p()
  
      def transform(pred, truth):
          pred = dist.Poisson(pred.clamp(min=1e-4).expm1()).sample()
          truth = truth.expm1()
          return pred, truth
  
      if engine == "svi":
          forecaster_fn = Forecaster
          forecaster_options = {"num_steps": 2}
      else:
          forecaster_fn = HMCForecaster
          forecaster_options = {"num_warmup": 1, "num_samples": 1}
  
      windows = backtest(
          data,
          covariates,
          Model,
          forecaster_fn=forecaster_fn,
          transform=transform,
          train_window=train_window,
          min_train_window=min_train_window,
          test_window=test_window,
          min_test_window=min_test_window,
          stride=stride,
          forecaster_options=forecaster_options,
      )
  
      assert any(window["t0"] == 0 for window in windows)
      if stride == 1:
          assert any(window["t0"] == 0 for window in windows)
          assert any(window["t2"] == duration for window in windows)
      for name in DEFAULT_METRICS:
          for window in windows:
              assert name in window
              assert 0 < window[name] < math.inf
  
file_path: pyro/tests/contrib/forecast/test_evaluate.py
imports: import math
  import pytest
  import torch
  import pyro
  import pyro.distributions
  from pyro.contrib.forecast import Forecaster, ForecastingModel, HMCForecaster, backtest
  from pyro.contrib.forecast.evaluate import DEFAULT_METRICS
  from pyro.util import optional
label_desc: Use image node_id 2 for calling a global function with example usage: test_poisson(train_window, min_train_window, test_window, min_test_window, stride, engine) and returns: pred,  truth