One simple improvement is to use Ref to store values inside NamedTupe. It does not influence type stability and keep the overall design intact. For example:
# support mutation for stochastic variables
m[@varname s2] = 5.0
# this should result in an error since we can't mutate logical variables (and hyperparameters)
m[@varname μ] = 2.0
Note that we only need to change the internal model constructor and accessor functions and keep the user-facing Model constructor the same.
Our current
GraphInfo
storesGraphInfo.value
in aNamedTuple
which prevents mutation.https://github.com/TuringLang/AbstractPPL.jl/blob/469252618fd6ea85dc911b0999b4614fcca45f2f/src/graphinfo.jl#L25
One simple improvement is to use
Ref
to store values insideNamedTupe
. It does not influence type stability and keep the overall design intact. For example:becomes
Then we can do
Note that we only need to change the internal model constructor and accessor functions and keep the user-facing
Model
constructor the same.