St.cache error on np.mgrid

Hi there. I am facing an error with @st.chache when using np.mgrid() in my function. The error is related to the number of steps in mgrid function that must be a complex number and says:
" Cannot hash object of type builtins.complex , found in the body of plotdata() ."

Could anyone be able to assist?

My function is

@st.cache
def plotdata():
    n1, n2 = 51, 51
    r11, phi11 = np.linspace(0, 4.8, n1), np.linspace(0, 2 * np.pi, n2)
    R1, P1 = np.mgrid[0:4.8:51j, 0:(2 * np.pi):51j] # perhaps the error comes from here
    x11 = R1 * np.cos(P1)
    y11 = R1 * np.sin(P1)
    z11 = (R1**2 - 1)**2
    return (x11, y11, z11)
data_for_3d = plotdata()
x11, y11, z11 = [data_for_3d[i] for i in range(len(data_for_3d))]

The error message is:

I would recommend you to use our latest caching primitive @st.experimental_memo instead of @st.cache here. From a quick try, it looks like it solves your issue. More on this in the docs!

2 Likes