@@ -177,13 +177,12 @@ function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
177177        #  Fall back to the default behavior.
178178        DynamicPPL. tilde_assume (child_context, right, vn, vi)
179179    elseif  has_conditioned_gibbs (context, vn)
180-         #  Short-circuit the tilde assume if `vn` is present in `context`.
181-         #  TODO (mhauru) Fix accumulation here. In this branch anything that gets
182-         #  accumulated just gets discarded with `_`.
183-         value, _ =  DynamicPPL. tilde_assume (
184-             child_context, right, vn, get_global_varinfo (context)
185-         )
186-         value, vi
180+         #  TODO (DPPL0.37/penelopeysm): Unsure if this is bad for SMC as it
181+         #  will trigger resampling. We may need to do a special kind of observe
182+         #  that does not trigger resampling.
183+         global_vi =  get_global_varinfo (context)
184+         val =  global_vi[vn]
185+         DynamicPPL. tilde_observe!! (child_context, right, val, vn, vi)
187186    else 
188187        #  If the varname has not been conditioned on, nor is it a target variable, its
189188        #  presumably a new variable that should be sampled from its prior. We need to add
@@ -210,13 +209,27 @@ function DynamicPPL.tilde_assume(
210209    vn, child_context =  DynamicPPL. prefix_and_strip_contexts (child_context, vn)
211210
212211    return  if  is_target_varname (context, vn)
212+         #  This branch means that that `sampler` is supposed to handle
213+         #  this variable. We can thus use its default behaviour, with
214+         #  the 'local' sampler-specific VarInfo.
213215        DynamicPPL. tilde_assume (rng, child_context, sampler, right, vn, vi)
214216    elseif  has_conditioned_gibbs (context, vn)
215-         value, _ =  DynamicPPL. tilde_assume (
216-             child_context, right, vn, get_global_varinfo (context)
217-         )
218-         value, vi
217+         #  This branch means that a different sampler is supposed to handle this
218+         #  variable. From the perspective of this sampler, this variable is
219+         #  conditioned on, so we can just treat it as an observation.
220+         #  The only catch is that the value that we need is to be obtained from
221+         #  the global VarInfo (since the local VarInfo has no knowledge of it).
222+         #  TODO (DPPL0.37/penelopeysm): Unsure if this is bad for SMC as it
223+         #  will trigger resampling. We may need to do a special kind of observe
224+         #  that does not trigger resampling.
225+         global_vi =  get_global_varinfo (context)
226+         val =  global_vi[vn]
227+         DynamicPPL. tilde_observe!! (child_context, right, val, vn, vi)
219228    else 
229+         #  If the varname has not been conditioned on, nor is it a target variable, its
230+         #  presumably a new variable that should be sampled from its prior. We need to add
231+         #  this new variable to the global `varinfo` of the context, but not to the local one
232+         #  being used by the current sampler.
220233        value, new_global_vi =  DynamicPPL. tilde_assume (
221234            rng,
222235            child_context,
0 commit comments