Pymc sum function returning zero

I have been having a problem where I can’t get the pymc.math.sum function to return non-zero answers. In the following code the numpy version works, but the pymc version prints Sum{axes=None}.0 (and generates -inf in a likelihood when ‘a’ is a variable).

import pymc as pm
import numpy as np

def combine(x,a,dx):
    weights = np.ones_like(x)
    weights[0] = 0.5; weights[-1] = 0.5
    return pm.math.sum(a*3*x**2*weights*dx)

x = np.linspace(0,1.0,num=101)
y = 3.6*x**3
err_y = y*0.1
dx = x[1]-x[0]
weights = np.ones_like(x)
weights[0] = 0.5; weights[-1] = 0.5
print(dx,combine(x,0.145,dx),np.sum(3*0.145*x**2*dx*weights),0.145*x[-1]**3)

You are not seeing the result. PyMC (PyTensor) functions are symbolic, what that zero means is that you are getting the first (and only) output of the sum operation. This is a placeholder for the actual value once evaluated.

You can get a numerical result by calling .eval(). This is just for debugging purposes, you don’t want to call .eval() within PyMC use. PyMC will evaluate the expressions when and where it needs it.

More details in PyMC and PyTensor — PyMC 5.25.1 documentation