Need help with handling ODE model. Error: unhashable type: 'slice'

It seems the problem is that solve_ivp, unlike odeint, returns a results object instead of a numpy array. You need your pytensor_forward_model_matrix function to return an array, so you can make the following change:

@as_op(itypes=[pt.dvector], otypes=[pt.dmatrix])
def pytensor_forward_model_matrix(theta):
    answer = solve_ivp(fun=rhs, t_span = [0, 1080], y0=y0_data, t_eval=time, args=(theta,), method='Radau')
    return answer.y

In general when you hit an error, make sure you check the type and shape of everything in your model. The .eval() method is very useful here. I uncovered the problem by doing ode_solution.eval() and seeing that it was not an array.

1 Like