Open axch opened 8 years ago
How about 'Invocation' or something instead of 'Args'? 'Args' suggest it contains arguments, but it does much more than that.
Separating magic and normal SPs sounds good to me. I don't like magic!
If we're going to rename the thing, I was thinking "Context" or "CallContext" or something. I balked at proposing that right away, because all the local variable names for it would need to be changed too.
In my Mite branch I have already elected to use the name "Context" for a different object... https://github.com/probcomp/Venturecxx/blob/mite-rev3/backend/mite/evaluator.py#L27
not that this isn't amenable to change.
Progress update:
Args
as IArgs
in psp.py
.MockArgs
in sp_use.py
, replacing BogusArgs
and ForeignArgs
.MockArgs
as the simulate
, logDensity
,
and gradientOfLogDensity
functions in sp_use.py
.ReplacingArgs
and RemappingArgs
in sp_use.py
, replacing
FixedValueArgs
and UnwrappingArgs
, respectively.Args
to TraceNodeArgs
.Justification for the remaining Args classes:
MockArgs
is an IArgs
that presumes no tracing context (and does
not supply argument identities).ReplacingArgs
and RemappingArgs
are IArgs
transformers that
preserve the context information.RequestArgs
and OutputArgs
are IArgs
that supply the tracing
context of the untraced evaluator. As such, they supply identities
for the arguments as untraced.Node
objects. There are two of them
as a stylistic choice, one for RequestPSP
s and one for
OutputPSP
s.TraceNodeArgs
is the IArgs
that started it all, supplying PET
tracing context. As such, it supplies identities for the arguments
as trace.Node
objects.Outstanding desiderata:
simulate
, logDensity
, and
gradientOfLogDensity
. This is impeded by needing to figure out
how to take an unknown number of arguments and a keyword argument in
Python.RequestArgs
and OutputArgs
do not supply spaux
or madeSPAux
fields. If we were to augment them to do this, which we want anyway
(#146), then they would be strictly more functional than MockArgs
(and could perhaps replace it).
The Venture source currently contains seven (!) Python classes whose name ends in the token
Args
:Args
, innode.py
, both defines (loosely) the interface of the object that Lite SPs expect passed in, and implements that interface as a "trace view".ForeignArgs
, inforeign.py
, is meant to be constructible byForeignLitePSP
from easily serialized information, as produced by Puma when calling Lite SPs.FixedValueArgs
, innode.py
, is a wrapper around an arbitraryArgs
that overrides itsoperandValues
(and, optionally,operandNodes
andspaux
) fields to report given values. This is used to implement theassess
SP and theDefaultVariationalLKernel
.UnwrappingArgs
, insp.py
, is a wrapper around an arbitraryArgs
that advises itsoperandValues
method, applying a given venture->Python value transformation. This is used to implementTypedPSP
.RequestArgs
, inbackend/untraced/evaluator.py
, is used by the untraced interpreter to call Lite RequestPSPs. It is also constructed from whole cloth, but withventure.untraced.Node
objects rather than venture values directly.OutputArgs
, inbackend/untraced/evaluator.py
, is used by the untraced interpreter to call Lite OutputPSPs. It is a subclass ofRequestArgs
that also includes results of evaluating any requests made by the SP.BogusArgs
, intest/randomized.py
, is used by the test suite to directly call methods of Lite OutputPSPs without creating any kind of trace or nodes at all. It is constructed directly from the values and aux that are to be passed in.One of the causes for this proliferation of Argh is that officially, the SP interface is supposed to permit SPs to obtain all sorts of information about their evaluation context from the interpreter:
lambda
and the maker corresponding tomem
)spaux
)madeSPAux
)fix
SP?)ESRRefOutputPSP
and nontrivially bymapv
andregress_mem
)fix
andregress_mem
?)lambda
,get_current_environment
, andfix
)Most SPs, however, only care about the actual arguments and the prng, with a reasonable minority that also cares about the
spaux
andmadeSPAux
. The other stuff is both rarely needed and not always (readily) available, hence the alternatives.The thing to do seems to be to
Args
interface as an interface, as part of the SP definition (as opposed to the Lite backend proper). Perhaps insp.py
?BogusArgs
,ForeignArgs
.Args
instance to the client at all, but convert a desired SP method to a Python function directly. Something likesp_simulate(sp) -> lambda *args, seed=None, spaux=None, madeSPAux=None: just do it
.Args
objects, supplantingUnwrappingArgs
andFixedValueArgs
.RequestArgs
andOutputArgs
, or should we leave those as is?Args
toTraceArgs
or something, emphasizing that this class is relatively heavy-weight, and specific to running SPs at locations in PETs.A somewhat higher-achiever intervention would consist of separating "normal" SPs from "magic" ones (what John Shutt called "operators" when specifying Kernel), and not even passing all the bizarre contextual information to "normal" SPs. Perhaps also disallowing "magic" SPs from being added to the system without patching the source. Besides simplifying the interface to "normal" SPs, this would have the added benefit that a future compiler can treat the set of "magic" SPs as closed and reason about each in depth, without having to be concerned about maintaining the ability to meet the "magic" interface for arbitrary user-addable SPs.
Thoughts?