aeppl.rewriting.construct_ir_fgraph(rv_values, ir_rewriter=None)[source]#

Construct a FunctionGraph in measurable IR form for the keys in rv_values.

A custom IR rewriter can be specified. By default, logprob_rewrites_db.query(RewriteDatabaseQuery(include=["basic"])) is used.

Our measurable IR takes the form of an Aesara graph that is more-or-less equivalent to a given Aesara graph (i.e. the keys of rv_values) but contains Op`s that are subclasses of the `MeasurableVariable type in place of ones that do not inherit from MeasurableVariable in the original graph but are nevertheless measurable.

MeasurableVariables are mapped to log-probabilities, so this IR is how non-trivial log-probabilities are constructed, especially when the “measurability” of a term depends on the measurability of its inputs (e.g. a mixture).

In some cases, entire sub-graphs in the original graph are replaced with a single measurable node. In other cases, the relevant nodes are already measurable and there is no difference between the resulting measurable IR graph and the original. In general, some changes will be present, because–at the very least–canonicalization is always performed and the measurable IR includes manipulations that are not applicable to outside of the context of measurability/log-probabilities.

For instance, some Op`s will be lifted through `MeasurableVariables in this IR, and the resulting graphs will not be computationally sound, because they wouldn’t produce independent samples when the original graph would. See

Return type

Tuple[FunctionGraph, Dict[Variable, Variable], Dict[Variable, Variable]]


  • A FunctionGraph of the measurable IR, a copy of rv_values containing

  • the new, cloned versions of the original variables in rv_values, and

  • a dict mapping all the original variables to their cloned values in

  • FunctionGraph.