code: def test_trace_smoke(Model, batch_shape, t_obs, obs_dim, cov_dim):
      model = Model()
      data = torch.randn(batch_shape + (t_obs, obs_dim))
      covariates = torch.randn(batch_shape + (t_obs, cov_dim))
      forecaster = Forecaster(
          model, data, covariates, num_steps=2, log_every=1
      )
      hmc_forecaster = HMCForecaster(
          model,
          data,
          covariates,
          max_tree_depth=1,
          num_warmup=1,
          num_samples=1,
          jit_compile=False,
      )
  
      # This is the desired syntax for recording posterior latent samples.
      num_samples = 5
      with poutine.trace() as svi:
          forecaster(data, covariates, num_samples)
      with poutine.trace() as hmc:
          hmc_forecaster(data, covariates, num_samples)
  
      # Check they match the equivalent poutine version.
      dim = -1 - forecaster.max_plate_nesting
      with torch.no_grad():
          with poutine.trace() as tr:
              with pyro.plate("particles", num_samples, dim=dim):
                  forecaster.guide(data, covariates)
          with poutine.trace() as expected:
              with poutine.replay(trace=tr.trace):
                  with pyro.plate("particles", num_samples, dim=dim):
                      model(data, covariates)
      for actual, engine in zip([svi, hmc], ["svi", "hmc"]):
          for name, site in expected.trace.nodes.items():
              expected_fn = site["fn"]
              if type(expected_fn).__name__ == "_Subsample":
                  continue
              actual_fn = actual.trace.nodes[name]["fn"]
              assert name in actual.trace.nodes, engine
              assert (
                  actual_fn.event_shape == expected_fn.event_shape
              ), engine
  
imports: import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.contrib.forecast import Forecaster, ForecastingModel, HMCForecaster
  from pyro.infer.autoguide import AutoDelta
  from pyro.infer.reparam import LinearHMMReparam, StableReparam
  from pyro.optim import Adam
label_desc: Use image node_id 2 for calling a global function with example usage: test_trace_smoke(Model, batch_shape, t_obs, obs_dim, cov_dim) without return types