On Sat, 28 Jan 2023 at 16:38, Thomas Ligon <thomassli...@gmail.com> wrote:
>
> Should pickle work for Function and Derivative? I found Sympy issue #4297 and 
> the answer seems to be no.
> Nevertheless, here is what I have:
> I have a private dictionary containing expressions of symbols, and everything 
> works fine.
> Then I created a new private dictionary that includes Function and 
> Derivative, and I can't pickle it. Here are some code snippets:
>
>     q1S, q2S = symbols('q1, q2')
>     q1F = Function('q1')
> ...
>     varX = globals()['CuspData']
>     fileName = os.path.join(config.pickle_dir, 'CuspData.pckl')
>     f = open(fileName, "wb")
>     varX = {'q1d0': q1F(tS), 'q1d1': Derivative(q1F(tS), tS)} # test
>     #with evaluate(False): pickle.dump(varX, f)
>     pickle.dump(varX, f)
>     f.close()
> The error is "Can't pickle q1: attribute lookup q1 on __main__ failed"

You need to call the variable the same name as the function:

q1 = Function('q1')

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxRBbKHCLGZBjZCxg6h5XqthYDeW2UZqJ0xfmd2twX7dyw%40mail.gmail.com.

Reply via email to