Funsor-based Pyro¶
Effect handlers¶
-
enum(fn=None, *args, **kwargs)¶ Convenient wrapper of
EnumMessengerThis version of EnumMessenger uses to_data to allocate a fresh enumeration dim for each discrete sample site.
-
markov(fn=None, *args, **kwargs)¶ Convenient wrapper of
MarkovMessengerHandler for converting to/from funsors consistent with Pyro’s positional batch dimensions.
Parameters: - history (int) – The number of previous contexts visible from the
current context. Defaults to 1. If zero, this is similar to
pyro.plate. - keep (bool) – If true, frames are replayable. This is important
when branching: if
keep=True, neighboring branches at the same level can depend on each other; ifkeep=False, neighboring branches are independent (conditioned on their shared ancestors).
- history (int) – The number of previous contexts visible from the
current context. Defaults to 1. If zero, this is similar to
-
named(fn=None, *args, **kwargs)¶ Convenient wrapper of
NamedMessengerBase effect handler class for the :func:~`pyro.contrib.funsor.to_funsor` and :func:~`pyro.contrib.funsor.to_data` primitives. Any effect handlers that invoke these primitives internally or wrap code that does should inherit from
NamedMessenger.This design ensures that the global name-dim mapping is reset upon handler exit rather than potentially persisting until the entire program terminates.
-
plate(fn=None, *args, **kwargs)¶ Convenient wrapper of
PlateMessengerCombines new IndepMessenger implementation with existing BroadcastMessenger. Should eventually be a drop-in replacement for pyro.plate.
-
replay(fn=None, *args, **kwargs)¶ Convenient wrapper of
ReplayMessengerThis version of ReplayMessenger is almost identical to the original version, except that it calls to_data on the replayed funsor values. This may result in different unpacked shapes, but should produce correct allocations.
-
trace(fn=None, *args, **kwargs)¶ Convenient wrapper of
TraceMessengerSetting
pack_online=Truepacks online instead of after the fact, converting all distributions and values to Funsors as soon as they are available.Setting
pack_online=Falsecomputes information necessary to do packing after execution. Each sample site is annotated with a “dim_to_name” dictionary, which can be passed directly to funsor.to_funsor.
-
class
NamedMessenger(first_available_dim=None)[source]¶ Bases:
pyro.poutine.reentrant_messenger.ReentrantMessengerBase effect handler class for the :func:~`pyro.contrib.funsor.to_funsor` and :func:~`pyro.contrib.funsor.to_data` primitives. Any effect handlers that invoke these primitives internally or wrap code that does should inherit from
NamedMessenger.This design ensures that the global name-dim mapping is reset upon handler exit rather than potentially persisting until the entire program terminates.
-
class
MarkovMessenger(history=1, keep=False)[source]¶ Bases:
pyro.contrib.funsor.handlers.named_messenger.NamedMessengerHandler for converting to/from funsors consistent with Pyro’s positional batch dimensions.
Parameters: - history (int) – The number of previous contexts visible from the
current context. Defaults to 1. If zero, this is similar to
pyro.plate. - keep (bool) – If true, frames are replayable. This is important
when branching: if
keep=True, neighboring branches at the same level can depend on each other; ifkeep=False, neighboring branches are independent (conditioned on their shared ancestors).
- history (int) – The number of previous contexts visible from the
current context. Defaults to 1. If zero, this is similar to
-
class
GlobalNamedMessenger(first_available_dim=None)[source]¶ Bases:
pyro.contrib.funsor.handlers.named_messenger.NamedMessengerBase class for any new effect handlers that use the :func:~`pyro.contrib.funsor.to_funsor` and :func:~`pyro.contrib.funsor.to_data` primitives to allocate DimType.GLOBAL or DimType.VISIBLE dimensions.
Serves as a manual “scope” for dimensions that should not be recycled by :class:~`MarkovMessenger`: global dimensions will be considered active until the innermost
GlobalNamedMessengerunder which they were initially allocated exits.
-
class
StackFrame(name_to_dim, dim_to_name, history=1, keep=False)[source]¶ Bases:
objectConsistent bidirectional mapping between integer positional dimensions and names. Can be queried like a dictionary (value = frame[key], frame[key] = value).
-
class
DimType[source]¶ Bases:
enum.EnumEnumerates the possible types of dimensions to allocate
-
LOCAL= 0¶
-
GLOBAL= 1¶
-
VISIBLE= 2¶
-
-
class
DimRequest(value, dim_type)¶ Bases:
tuple-
dim_type¶ Alias for field number 1
-
value¶ Alias for field number 0
-
-
class
DimStack[source]¶ Bases:
objectSingle piece of global state to keep track of the mapping between names and dimensions.
Replaces the plate DimAllocator, the enum EnumAllocator, the stack in MarkovMessenger, _param_dims and _value_dims in EnumMessenger, and dim_to_symbol in msg[‘infer’]
-
MAX_DIM= -25¶
-
DEFAULT_FIRST_DIM= -5¶
-
global_frame¶
-
local_frame¶
-
current_write_env¶
-
current_read_env¶ Collect all frames necessary to compute the full name <–> dim mapping and interpret Funsor inputs or batch shapes at any point in a computation.
-