code: def substitute_aux(samples, log_prob, num_samples):
      assert all("aux" in v.inputs for v in samples.values())
      assert set(log_prob.inputs) == {"aux"}
  
      # Substitute noise for the aux value, as would happen each SVI step.
      aux_numel = log_prob.inputs["aux"].num_elements
      noise = Tensor(randn(num_samples, aux_numel))["particle"]
      with memoize():
          samples = {k: v(aux=noise) for k, v in samples.items()}
          log_prob = log_prob(aux=noise)
  
      return samples, log_prob
  
imports: from collections import OrderedDict
  from typing import Dict, Tuple
  import numpy
  import pytest
  import funsor.ops
  from funsor.domains import Bint, Real, Reals
  from funsor.interpretations import memoize
  from funsor.montecarlo import extract_samples
  from funsor.recipes import forward_filter_backward_precondition, forward_filter_backward_rsample
  from funsor.terms import Lambda, Variable
  from funsor.testing import Tensor, assert_close, randn, random_gaussian
  from funsor.util import get_backend
label_desc: Use image node_id 3 for calling a global function with example usage: substitute_aux(samples, log_prob, num_samples) and returns: samples,  log_prob