I've got the following issue while trying to make scheme Hom sets unique, though nothing is specific to schemes in the following. Really, consider the following structure:
1. Some Python class of objects 2. Morphisms of objects 3. Parents of morphisms 4. Such that objects contain a morphism as Python attribute (e.g. a scheme has its structure morphism as attribute). The object contains a circular reference; it is also the domain of the contained morphism. This breaks unpickling, because the unpickler first creates the uninitialized object, then tries to unpickle the morphism, and only then sets the remaining data attributes of the object. But unpickling the morphism is bound to fail because uniqueness of the parent can't be established: the domain object is not initialized yet. Technically, it will fail when looking for the domain in the UniqueFactory's cache because the __hash__() method ends up accessing not-yet-initialized data attributes and throw an AttributeError. The problem is that unpickling is always done in a one-step process; The unpickler reconstructs the dict (result of __reduce__()) as much as possible and then sets the state of the object. But if you have circular references then you necessarily have incomplete objects. Which wouldn't be too bad if we could set everything except the Parents in the first step, and then recreate all the parents in a second step. But thats not how cPickle works. This problem isn't new, see for example: http://stackoverflow.com/questions/4425472/attributeerror-edge-instance-has-no-attribute-vto http://stackoverflow.com/questions/4132132/python-pickle-how-does-it-break/4133603#4133603 Has anybody encountered this before and/or any suggestions for how to deal with this issue? -- To post to this group, send an email to [email protected] To unsubscribe from this group, send an email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
