class_docstr: Preconditioning interpretation for adjoint computations.
  
  This interpretation is intended to be used once, followed by a call to
  :meth:`combine_subs` as follows::
  
      # Lazily build a factor graph.
      with reflect:
          log_joint = Gaussian(...) + ... + Gaussian(...)
          log_Z = log_joint.reduce(ops.logaddexp)
  
      # Run a backward sampling under the precondition interpretation.
      with Precondition() as p:
          marginals = adjoint(
              ops.logaddexp, ops.add, log_Z, batch_vars=p.sample_vars
          )
      combine_subs = p.combine_subs()
  
      # Extract samples from Delta distributions.
      samples = {
          k: v(**combine_subs)
          for name, delta in marginals.items()
          for k, v in funsor.montecarlo.extract_samples(delta).items()
      }
  
  See :func:`~funsor.recipes.forward_filter_backward_precondition` for
  complete usage.
  
  :param str aux_name: Name of the auxiliary variable containing white noise.
class_docstr_tok: ["Preconditioning","interpretation","for","adjoint","computations",".","This","interpretation","is","intended","to","be","used","once",",","followed","by","a","call","to",":","meth",":","`","combine_subs","`","as","follows",":",":","#","Lazily","build","a","factor","graph",".","with","reflect",":","log_joint","=","Gaussian","(","...",")","+","...","+","Gaussian","(","...",")","log_Z","=","log_joint.reduce","(","ops.logaddexp",")","#","Run","a","backward","sampling","under","the","precondition","interpretation",".","with","Precondition","(",")","as","p",":","marginals","=","adjoint","(","ops.logaddexp",",","ops.add",",","log_Z",",","batch_vars=p.sample_vars",")","combine_subs","=","p.combine_subs","(",")","#","Extract","samples","from","Delta","distributions",".","samples","=","{","k",":","v","(","*","*","combine_subs",")","for","name",",","delta","in","marginals.items","(",")","for","k",",","v","in","funsor.montecarlo.extract_samples","(","delta",")",".items","(",")","}","See",":","func",":","`","~funsor.recipes.forward_filter_backward_precondition","`","for","complete","usage",".",":","param","str","aux_name",":","Name","of","the","auxiliary","variable","containing","white","noise","."]
docstr: Method to create a combining substitution after preconditioning is
  complete. The returned substitution replaces per-factor auxiliary
  variables with slices into a single combined auxiliary variable.
  
  :returns: A substitution indexing each factor-wise auxiliary variable
      into a single global auxiliary variable.
  :rtype: dict
docstr_tok: ["Method","to","create","a","combining","substitution","after","preconditioning","is","complete",".","The","returned","substitution","replaces","per-factor","auxiliary","variables","with","slices","into","a","single","combined","auxiliary","variable",".",":","returns",":","A","substitution","indexing","each","factor-wise","auxiliary","variable","into","a","single","global","auxiliary","variable",".",":","rtype",":","dict"]
code: def combine_subs(self):
      """
      Method to create a combining substitution after preconditioning is
      complete. The returned substitution replaces per-factor auxiliary
      variables with slices into a single combined auxiliary variable.
  
      :returns: A substitution indexing each factor-wise auxiliary variable
          into a single global auxiliary variable.
      :rtype: dict
      """
      total_size = sum(
          v.num_elements for v in self.sample_inputs.values()
      )
      aux = Variable(self.aux_name, Reals[total_size])
      subs = {}
      start = 0
      for k, v in self.sample_inputs.items():
          stop = start + v.num_elements
          subs[k] = aux[start:stop].reshape(v.shape)
          start = stop
      return subs
  
file_path: funsor/funsor/precondition.py
imports: from collections import OrderedDict
  from .None import ops
  from .cnf import Contraction, GaussianMixture
  from .domains import Reals
  from .gaussian import Gaussian
  from .interpretations import StatefulInterpretation
  from .terms import Approximate, Funsor, Subs, Variable
label_desc: Use image node_id 2 for calling the Precondition obj's underlying member method code with example usage: obj.combine_subs() and returns: subs