Accessing value of Deterministic variable inside a custom step method

Hello all,

I’m interested in writing a custom step method that can make use of variables which are represented as pm.Deterministic somewhere in the model definition. Currently, I only see how to do this for free RVs which are handled in the point object passed around behind the scenes. For example, see below:

class MyStep(BlockedStep):
    def __init__(self, var):
       # Some important initialization stuff here....
    def step(self, point):
        # Here, I'd like to make use of the values of a Deterministic variable,
        # but they don't appear as key:value pairs in `point`.
        return point

Any ideas on how to tackle this are appreciated! For context, I am using this to do Gibbs sampling for discrete variables in a hybrid Bayesian network + latent Markov random field model. In this scenario, there are difficulties that prevent me from using the CategoricalGibbsMetropolis stepper.

For lack of anything better, I came up with a hack to work around this. Essentially, I create a new random variable which is uniformly distributed around the desired quantity within a tiny interval. This way there is an entry in the point object manipulated by the step functions, but this entry is essentially the same as the original value we wanted. We would also need to disable transforms from the uniform random variable so that it we can access y_duplicate instead of y_duplicate_interval__ in point. Since the acceptance ratio for the Metropolis proposal should be 1 every time, the proposal should always be accepted and thus y_duplicate is always the same as y.

eps = 1e-6
with pm.Model() as pm:
    x = pm.Normal('x')
    y = pm.Deterministic('y', complicated_func(x))
    y_duplicate = pm.Uniform('y_duplicate', lower=y-eps, upper=y+eps, transform=None)
    trace = pm.sample(step=[pm.Metropolis(y_duplicate)])