Opened 8 months ago

Closed 4 months ago

#15050 closed defect (fixed)

Bug in pickling of toric varieties

Reported by: vbraun Owned by:
Priority: major Milestone: sage-6.1
Component: algebraic geometry Keywords: toric
Cc: novoselt, jkeitel Merged in:
Authors: Volker Braun Reviewers: Andrey Novoseltsev
Report Upstream: N/A Work issues:
Branch: u/vbraun/toric_pickling (Commits) Commit: 0be2c23dc1a7c5a9a903f4fa8ecd4674cb591891
Dependencies: Stopgaps:

Description

sage: variety = toric_varieties.P(1)
sage: variety.cohomology_ring()
Rational cohomology ring of a 1-d CPR-Fano toric variety covered by 2 affine patches
sage: pickle = dumps(variety)
sage: loads(pickle)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-41fbbbe8d1ed> in <module>()
----> 1 loads(pickle)

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.loads (sage/structure/sage_object.c:11044)()

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/structure/unique_representation.pyc in unreduce(cls, args, keywords)
    599 
    600     """
--> 601     return cls(*args, **keywords)
    602 
    603 

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/misc/classcall_metaclass.so in sage.misc.classcall_metaclass.ClasscallMetaclass.__call__ (sage/misc/classcall_metaclass.c:1224)()

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/misc/cachefunc.so in sage.misc.cachefunc.WeakCachedFunction.__call__ (sage/misc/cachefunc.c:5347)()

/home/vbraun/Code/sage.git/local/lib/python/weakref.pyc in __getitem__(self, key)
     54 
     55     def __getitem__(self, key):
---> 56         o = self.data[key]()
     57         if o is None:
     58             raise KeyError, key

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/structure/category_object.so in sage.structure.category_object.CategoryObject.__hash__ (sage/structure/category_object.c:8312)()

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/structure/sage_object.so in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1921)()

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/schemes/toric/fano_variety.pyc in _repr_(self)
    746         """
    747         return ("%d-d CPR-Fano toric variety covered by %d affine patches"
--> 748                 % (self.dimension_relative(), self.fan().ngenerating_cones()))
    749 
    750     def anticanonical_hypersurface(self, **kwds):

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/schemes/generic/ambient_space.pyc in dimension_relative(self)
    393             2
    394         """
--> 395         return self._dimension_relative

/home/vbraun/Code/sage.git/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:6736)()

<type 'str'>: (<type 'exceptions.AttributeError'>, AttributeError('CPRFanoToricVariety_field_with_category' object has no attribute '_dimension_relative',))

Analysis:

  • There is a circular reference between the ToricVariety and the CohomologyRing.
  • The unpickler therefore must work with half-constructed objects and only later fill in the attributes.
  • The CohomologyRing inherits from UniqueRepresentation, so it will try to look in the unique representation cache
  • For that, we need __hash__() of the toric variety which is provided by CategoryObject
  • The hash depends on __repr__() which accesses attributes of the toric variety that are not yet filled in.

Change History (9)

comment:1 Changed 8 months ago by vbraun

  • Branch set to /u/vbraun/toric_pickling
  • Commit set to 0be2c23dc1a7c5a9a903f4fa8ecd4674cb591891

I think the best solution is to just not pickle caches, especially since the ToricVariety is likely to have lots of caches. If you want to store results then you are probably going to do so explicitly already.

comment:2 Changed 8 months ago by vbraun

  • Authors set to Volker Braun
  • Branch changed from /u/vbraun/toric_pickling to u/vbraun/toric_pickling
  • Status changed from new to needs_review

comment:3 Changed 8 months ago by novoselt

  • Keywords toric added
  • Reviewers set to Andrey Novoseltsev
  • Status changed from needs_review to positive_review

Agreed!

comment:4 Changed 8 months ago by jdemeyer

  • Milestone changed from sage-5.12 to sage-6.0

comment:5 Changed 8 months ago by jkeitel

Hi Volker, hi Andrey,

while this patch fixes the issue with the CohomologyRing?, there are several other internally cached objects that give rise to the same problem, namely those generated after calling

Todd_class, Chern_class, Chern_character, Kaehler_cone, Mori_cone

These bugs can be fixed analogously to what you did for the methods above (tried it sucessfully on my local version), but I'm not sure how to get git to make a new patch. (Hopefully that'll change in three weeks in Oxford.)

Cheers, Jan

comment:6 Changed 8 months ago by jkeitel

  • Cc jkeitel added
  • Status changed from positive_review to needs_work

comment:7 Changed 8 months ago by vbraun

  • Status changed from needs_work to positive_review

Don't reopen reviewed tickets. You should make a new follow-up ticket.

comment:8 Changed 4 months ago by vbraun_spam

  • Milestone changed from sage-6.0 to sage-6.1

comment:9 Changed 4 months ago by vbraun

  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.