-
Notifications
You must be signed in to change notification settings - Fork 67
Support pickling of Basic objects #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This should be ready for a review. Failing test is a network issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good to me.
This is super useful! |
In pycalphad, we used to subclass sympy Self-contained example: import pickle
from symengine import Add, Symbol
class StateVariable(Symbol):
def __init__(self, name):
super().__init__(name.upper())
def __reduce__(self):
return self.__class__, (self.name,)
T = StateVariable('T')
loaded_T = pickle.loads(pickle.dumps(T))
assert isinstance(loaded_T, StateVariable), f"Got type {type(loaded_T)}" # passes
loaded_Add_T = list(pickle.loads(pickle.dumps(Add(T, 1))).free_symbols)[0]
assert isinstance(loaded_Add_T, StateVariable), f"Got type {type(loaded_Add_T)}" # fails AssertionError Traceback (most recent call last)
<ipython-input-1-ff0882030409> in <module>
15
16 loaded_Add_T = list(pickle.loads(pickle.dumps(Add(T, 1))).free_symbols)[0]
---> 17 assert isinstance(loaded_Add_T, StateVariable), f"Got type {type(loaded_Add_T)}" # fails
AssertionError: Got type <class 'symengine.lib.symengine_wrapper.Symbol'> Are there any changes here or in our code that we can make to have our subclasses survive a round trip through |
Thank you, @isuruf! The changes here and upstream in SymEngine work well and solve our problem. |
No description provided.