Sampling crashes with "The derivative of RV [whatever] is zero" when using a custom likelihood defined with pm.Potential

Oh wow, I wasn’t expecting you to fix the whole thing. Thank you so much!

If it isn’t too much trouble, could you explain why your version has a working gradient and mine doesn’t? I’m not that familiar with theano and how it works under the hood. I intend to eventually expand the model to incorporate disease dynamics that depend on covariate information (e.g. pairwise properties like “lives in the same household”) and it will involve adding a bunch more similar terms to the model, and I want to be confident enough to do it properly.

From reading it, it seems to have something to do with the log(qxus^changes) term, but I don’t know the significance of the subtensors in your implementation.