Core name and syntax changes
Based on a discussion with @vkmvkmvkmvkm:
-
change
AssignmenttoTrie. -
change
get_assmttoget_choices. It will return aTrie. -
change
DistributiontoUnboxedGenerativeFunction(or something similar)
Also see https://github.com/probcomp/Gen/issues/19
Other name changes:
-
consider changing
@addr(<call>, <addr>)to@trace(<call>, <addr>), and change@splice(<call>)to@trace(<call>). This resolves the suggestion in https://github.com/probcomp/Gen/issues/48, and also makes more sense regarding automatic differentiation. -
consider changing
Gen.initializetoGen.trace -
consider changing
Gen.backprop_paramstoGen.backprop_params!. This makes it more explicit that some state associated with the generative function (the gradient accumulators for trainable parameters) is being mutated.
consider changing Gen.initialize to Gen.trace
I think Gen.trace can be confusing if we are going to use it as both a noun ad a verb. In Gen we commonly have the trace data structure lying around (which is a noun, representing the execution trace), as well as, according the proposal, the verb Gen.trace which is telling Gen to trace the function and then return the execution trace. Also namespace collisions will arise if Gen has a trace function.
Maybe Gen.get_trace?
Other options:
-
Gen.generate_trace. -
Gen.traced_exec
I thought about renaming the initialize method in the Gen function interface.
The proposed new name is generate_trace. This has the word "trace" in it. It also has the word "generate", which is appropriate since a generative function is precisely one that has this method.
(trace, weight) = generate_trace(gen_fn, args)
Return a trace of the generative function.
(trace, weight) = generate_trace(gen_fn, args, constraints)
Return a trace of the generative function that is consistent with the given constraints on the random choices.
The name initialize is not ideal, because "initializing" assumes the trace is going to be changed later, which is not always the case, so the current name only makes sense for certain usages that update the trace. it also doesn't have the word "trace" in it, which is the essential difference between the behavior here and the behavior of just calling the generative function in regular Julia usage, e.g. gen_fn(args...).
I also considered but these imply that the generating process is forward simulation, which isn't always the case, and also describe the method from an internal perspective, not from what the user wants to do with the function (like generate_trace):
-
traced_apply -
traced_exec -
traced_call
get_trace makes it sound lke the trace already exists and this is a "getter" method (like all the other usages of get_X in Gen).
These changes were made in https://github.com/probcomp/Gen/pull/67
Actually, except for renaming distributions to a type of generative function. That has not been changed yet. Reopening.
@marcoct is this closed by #274 / #282 ?