kkumer/gepard

hubDict cannot be unpickled in py3

kkumer opened this issue · 1 comments

Namely, while unpickling, __setitem_ is called before __init__ or __setstate__ and then self.d1 is still undefined. To resolve, see here but it may involve another one-time transcoding of database in python2 code.

What finally worked was unpickling with old hubDict, and then copying parameters into newly defined hubDictNew which additionally had

    def __reduce__(self):                                                                                                                          
        return (hubDictNew, (), self.__getstate__())                                               
                                                                                                
    def __getstate__(self):                                                                                                                         
        return self.__dict__                                                                    
                                                                                                
    def __setstate__(self, d):                                                                                                                  
        self.__dict__ = d                                                                       
        self.d1 = d['d1']                                                                       
        self.d2 = d['d2'] 

Copying (th.m.parameters is hubDict instance):

th.m.parameters = utils.hubDictNew(th.m.parameters.d1, th.m.parameters.d2)

And then pickling again. After this, I was able to remove the three additional methods specified above (so there is now no difference between hubDict and hubDictNew and everything works.