Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

pickle Lambdify only works with backend='llvm' and not with backend='lambda #294

Open
raphaelquast opened this issue Aug 8, 2019 · 5 comments

Comments

@raphaelquast
Copy link

raphaelquast commented Aug 8, 2019

I've just noticed that pickling of symengine Lambdify functions fails with the default 'lambda' backend, but works fine with the 'llvm' backend...
is there any particular reason for that? (or in other words... will I run into problems when I use the 'llvm' backend?)

maybe the fixes of #213 need to be repeated?

import symengine as seng
import pickle
x, y = seng.var("x, y")
f1 = seng.Lambdify([x, y], x+y, backend='llvm')
f2 = seng.Lambdify([x, y], x+y, backend='lambda')

_ = pickle.dumps(f1)
>>> works perfect

_ = pickle.dumps(f2)
>>>TypeError: self.lambda_double,self.lambda_double_complex cannot be converted to a Python object for pickling
@bjodah
Copy link
Contributor

bjodah commented Aug 8, 2019

The problem is bigger than that. We would need to serialize the function objects. C++, which (unbelievably) still lacks proper reflection makes serialization a hassle (essentially forcing projects to do their own code generation, see e.g. Qt's moc, google's protobuf etc.). xref: symengine/symengine#1394

EDIT: On that note, I've been looking into using libclang to parse the ast of a project of mine and generate serialization/deserialization functions during the build process (I've seen some talks on the subject, some also use annotations, but I haven't found a well established and maintained tool for this)

@raphaelquast
Copy link
Author

OK, thanks for the quick reply!
...i already thought that the actual issue might lie a bit deeper...

will I run into any (expected) problems if I use the 'llvm' backend instead?

@isuruf
Copy link
Member

isuruf commented Aug 8, 2019

@raphaelquast, the pickle file for llvm backend is platform dependent. You won't be able to save in linux and load in macos

@bjodah
Copy link
Contributor

bjodah commented Aug 8, 2019

As long as you pickle and unpickle on a machines with the same instruction set there shouldn't be any issues (barring any unknown bugs of course). (and OS as @isuruf points out)

@raphaelquast
Copy link
Author

Perfect, thanks!
(the platform-dependency is fortunately only a minor issue for me)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants