Fix new Gibbs sampler for cases where only some variables need to be linked
See https://github.com/TuringLang/Turing.jl/blob/7d6a98333acfbdf0c62811f4ed4ab6fe1cec35e7/src/mcmc/gibbs.jl#L567 for description of the problem and a possible solution.
This relies on DynamicPPL gaining a method for link!! and invlink!! that takes a VarName rather than a sampler or a space.
The bug that this causes is only hit when doing things that the old Gibbs sampler never allowed in the first place, so I don't think implementing this should hold back merging #2328.
This relies on DynamicPPL gaining a method for link!! and invlink!! that takes a VarName rather than a sampler or a space.
Is this meant to link only that particular variable and return the linked value or is it meant to link only that subset of the varinfo? Because the latter we sort of want to avoid as this requires runtime checks + it was only really needed currently because of the way we implemented the Gibbs sampler.
IIUC we can just have the global varinfo in #2328 always be constrained, and then we just invlink the linked varialbes in the local varinfo before updating the global one?
The idea was that this would BangBang modify the VarInfo, changing the linkage status of a variable, not just return the value. Can you help me understand in more detail why this is undesirable?
IIUC we can just have the global varinfo in https://github.com/TuringLang/Turing.jl/pull/2328 always be constrained, and then we just invlink the linked varialbes in the local varinfo before updating the global one?
That would work as well, yes. I thought matching the linkage status between previous and new VarInfo was cleaner and more robust (e.g. some weird future sampler wants to have some variables linked and others not linked, no problem) than having to do unnecessary link/invlink at every iteration. But if that is problematic then indeed this can be used instead.