code: def test_enumeration(model, data, var, history, use_replay):
      pyro.clear_param_store()
  
      with pyro_backend("contrib.funsor"):
          with handlers.enum():
              enum_model = infer.config_enumerate(
                  model, default="parallel"
              )
              # sequential trace
              trace = handlers.trace(enum_model).get_trace(
                  data, history, False
              )
              # vectorized trace
              if use_replay:
                  guide_trace = handlers.trace(
                      _guide_from_model(model)
                  ).get_trace(data, history, True)
                  vectorized_trace = handlers.trace(
                      handlers.replay(model, trace=guide_trace)
                  ).get_trace(data, history, True)
              else:
                  vectorized_trace = handlers.trace(
                      enum_model
                  ).get_trace(data, history, True)
  
          # sequential factors
          factors = list()
          for i in range(data.shape[-2]):
              for v in var:
                  factors.append(
                      trace.nodes["{}_{}".format(v, i)]["funsor"][
                          "log_prob"
                      ]
                  )
  
          # vectorized factors
          vectorized_factors = list()
          for i in range(history):
              for v in var:
                  vectorized_factors.append(
                      vectorized_trace.nodes["{}_{}".format(v, i)][
                          "funsor"
                      ]["log_prob"]
                  )
          for i in range(history, data.shape[-2]):
              for v in var:
                  vectorized_factors.append(
                      vectorized_trace.nodes[
                          "{}_{}".format(
                              v, slice(history, data.shape[-2])
                          )
                      ]["funsor"]["log_prob"](
                          **{"time": i - history},
                          **{
                              "{}_{}".format(
                                  k,
                                  slice(
                                      history - j, data.shape[-2] - j
                                  ),
                              ): "{}_{}".format(k, i - j)
                              for j in range(history + 1)
                              for k in var
                          },
                      )
                  )
  
          # assert correct factors
          for f1, f2 in zip(factors, vectorized_factors):
              assert_close(f2, f1.align(tuple(f2.inputs)))
  
          # assert correct step
          actual_step = vectorized_trace.nodes["time"]["value"]
          # expected step: assume that all but the last var is markov
          expected_step = frozenset()
          expected_measure_vars = frozenset()
          for v in var[:-1]:
              v_step = tuple(
                  "{}_{}".format(v, i) for i in range(history)
              ) + tuple(
                  "{}_{}".format(
                      v, slice(j, data.shape[-2] - history + j)
                  )
                  for j in range(history + 1)
              )
              expected_step |= frozenset({v_step})
              # grab measure_vars, found only at sites that are not replayed
              if not use_replay:
                  expected_measure_vars |= frozenset(v_step)
          assert actual_step == expected_step
  
          # check measure_vars
          actual_measure_vars = terms_from_trace(vectorized_trace)[
              "measure_vars"
          ]
          assert actual_measure_vars == expected_measure_vars
  
imports: import pytest
  import torch
  from pyroapi import pyro_backend
  from torch.distributions import constraints
  from pyro.ops.indexing import Vindex
label_desc: Use image node_id 10 for calling a global function with example usage: test_enumeration(model, data, var, history, use_replay) without return types