code: def config_enumerate(
      guide=None,
      default="parallel",
      expand=False,
      num_samples=None,
      tmc="diagonal",
  ):
      """
      Configures enumeration for all relevant sites in a guide. This is mainly
      used in conjunction with :class:`~pyro.infer.traceenum_elbo.TraceEnum_ELBO`.
  
      When configuring for exhaustive enumeration of discrete variables, this
      configures all sample sites whose distribution satisfies
      ``.has_enumerate_support == True``.
      When configuring for local parallel Monte Carlo sampling via
      ``default="parallel", num_samples=n``, this configures all sample sites.
      This does not overwrite existing annotations ``infer={"enumerate": ...}``.
  
      This can be used as either a function::
  
          guide = config_enumerate(guide)
  
      or as a decorator::
  
          @config_enumerate
          def guide1(*args, **kwargs):
              ...
  
          @config_enumerate(default="sequential", expand=True)
          def guide2(*args, **kwargs):
              ...
  
      :param callable guide: a pyro model that will be used as a guide in
          :class:`~pyro.infer.svi.SVI`.
      :param str default: Which enumerate strategy to use, one of
          "sequential", "parallel", or None. Defaults to "parallel".
      :param bool expand: Whether to expand enumerated sample values. See
          :meth:`~pyro.distributions.Distribution.enumerate_support` for details.
          This only applies to exhaustive enumeration, where ``num_samples=None``.
          If ``num_samples`` is not ``None``, then this samples will always be
          expanded.
      :param num_samples: if not ``None``, use local Monte Carlo sampling rather
          than exhaustive enumeration. This makes sense for both continuous and
          discrete distributions.
      :type num_samples: int or None
      :param tmc: "mixture" or "diagonal" strategies to use in Tensor Monte Carlo
      :type tmc: string or None
      :return: an annotated guide
      :rtype: callable
      """
      if default not in ["sequential", "parallel", "flat", None]:
          raise ValueError(
              "Invalid default value. Expected 'sequential', 'parallel', or None, but got {}".format(
                  repr(default)
              )
          )
      if expand not in [True, False]:
          raise ValueError(
              "Invalid expand value. Expected True or False, but got {}".format(
                  repr(expand)
              )
          )
      if num_samples is not None:
          if not (
              isinstance(num_samples, numbers.Number)
              and num_samples > 0
          ):
              raise ValueError(
                  "Invalid num_samples, expected None or positive integer, but got {}".format(
                      repr(num_samples)
                  )
              )
          if default == "sequential":
              raise ValueError(
                  'Local sampling does not support "sequential" sampling; '
                  'use "parallel" sampling instead.'
              )
      if tmc == "full" and num_samples is not None and num_samples > 1:
          # tmc strategies validated elsewhere (within enum handler)
          expand = True
  
      # Support usage as a decorator:
      if guide is None:
          return lambda guide: config_enumerate(
              guide,
              default=default,
              expand=expand,
              num_samples=num_samples,
              tmc=tmc,
          )
  
      return poutine.infer_config(
          guide,
          config_fn=_config_enumerate(
              default, expand, num_samples, tmc
          ),
      )
  
file_path: pyro/pyro/infer/enum.py
imports: import numbers
  from functools import partial
  from queue import LifoQueue
  from pyro import poutine
  from pyro.infer.util import is_validation_enabled
  from pyro.poutine import Trace
  from pyro.poutine.enum_messenger import enumerate_site
  from pyro.poutine.util import prune_subsample_sites
  from pyro.util import check_model_guide_match, check_site_shape, ignore_jit_warnings
label_desc: Use image node_id 7 for calling a global function with example usage: config_enumerate(guide, default, expand, num_samples, tmc) and returns: poutine, function