Using Serialization to store then load a lambdified function?

pluie
Wed, 17 Aug 2022 18:20:31 +0000
General Usage

I have a lengthy symbolic expression that I find and lambdify in one function once. I hope to use this lambdified function repeatedly in a different function. It takes about a minute for lambdify to execute, so I do not want to have to solve for it repeatedly.

I am trying to lambdify and serialize the lambdified expression in one function (no issue there) and then deserialize it in another function. The function errors at the deserialize step: UndefVarError: ###274 not defined.

I have made a simple test setup for illustrative purposes.

Lambdify and serialize:

using Serialization
using SymPy

@syms a b c
func = a^2 + b^3-c/a
funky = lambdify(func,(a,b,c))
sol1 = funky(1,2,3)

fname = string("testSerial",".txt")
serialize(fname,funky)

Then, in a new instance of Julia

using Serialization
using SymPy
fname = "testSerial.txt"
tfunc = deserialize(fname)

sol2 = tfunc(1,2,3)

which errors at the deserialize step.

Does anyone have any insights into this issue? Or a proposed better way to accomplish my goal?

Thank you.

8 posts - 4 participants