Porting PyMC code to run on PyMC3 how to create a stochastic subclass distribution?

I’m trying to get my head round PyMC3 in order to port some existing code written (and working) for PyMC. I need to create a custom distribution that is a stochastic subclass.

The original PyMC code used functions such as pymc.valuewrapper() and pymc.new_dist_class(). Here is a summary of the PyMC code:

def a_logp(...):
   return something 

def a_random(...):
    return something

dtype = np.float64
docstr = "mydist"
parent_names = ["a", "b"]
parents_default = {"a": 0, "b": 1, "value": 0.5}
wrapped_logp_partial_gradients = {}
logp = pymc.valuewrapper(a_logp)
mv = False

UniformNonzero = pymc.new_dist_class(

My questions are, does PyMC3 support equivalent functionality to do this? I see PyMC3 supports a function called DensityDist() for creating custom distributions using logp() and random() functions. But how do I define the parent information etc? Or is it I have to dig deeper, e.g. into Theano? I would be very grateful if someone could just point in the right direction.

Yes you will use DensityDist for this. The conditional (i.e., parent information) could be coded in the logp function directly, or feeded using a dict in observed={…}

You can have a look at How to set up a custom likelihood function for two variables for more information.