It’s hard to say exactly what’s causing the problem without seeing your code.
This is the main problem. You need to make the logp return a theano tensor. I don’t know what you’re doing now but I suppose you wrote a small extension module that communicates with the c++ compiled library. In order to get this to work with theano, you need to either write a custom Op or wrap your present function with the as_op decorator. The former is the hard way as it gives you finer grained control on the implementation while the latter is easier but sacrifices control and potential optimizations.