code: def mc_extend(
      trace: "Trace", msg: "Message", num_samples: Optional[int] = None
  ) -> List["Trace"]:
      """
      :param trace: a partial trace
      :param msg: the message at a Pyro primitive site
      :param num_samples: maximum number of extended traces to return.
      :returns: a list of traces, copies of input trace with one extra site
  
      Utility function to copy and extend a trace with sites based on the input site
      whose values are sampled from the input site's function.
  
      Used for Monte Carlo marginalization of individual sample sites.
      """
      if num_samples is None:
          num_samples = 1
  
      extended_traces = []
      for i in range(num_samples):
          msg_copy = msg.copy()
          msg_copy["value"] = msg_copy["fn"](
              *msg_copy["args"], **msg_copy["kwargs"]
          )
          tr_cp = trace.copy()
          assert msg_copy["name"] is not None
          tr_cp.add_node(msg_copy["name"], **msg_copy)
          extended_traces.append(tr_cp)
      return extended_traces
  
file_path: pyro/pyro/poutine/util.py
imports: from typing import TYPE_CHECKING, List, Optional
  from pyro import settings
label_desc: Use image node_id 7 for calling a global function with example usage: mc_extend(trace, msg, num_samples) and returns: extended_traces