Opened 13 years ago
Closed 5 years ago
#7516 closed defect (fixed)
bug in pickling quotient module over pid
Reported by:  William Stein  Owned by:  William Stein 

Priority:  major  Milestone:  sage8.1 
Component:  linear algebra  Keywords:  
Cc:  Merged in:  
Authors:  Simon Brandhorst  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  ea6a00b (Commits, GitHub, GitLab)  Commit:  ea6a00ba4750d97546755784041b5d3cee2f2de9 
Dependencies:  Stopgaps: 
Description
This is from the "report a problem" link in the notebook:
If you have a vector space, that is a quotient of a subspace of another vector space, then after coercing elements into it, something goes wrong in (un)pickling it.
sage: V = VectorSpace(QQ, 2) sage: W = V.subspace([V([1,1])]) sage: Z = W.subspace([]) sage: WmodZ = W / Z sage: WmodZ(W(0)) (0) sage: loads(dumps(WmodZ))  AttributeError Traceback (most recent call last) /home/bosman/sage/<ipython console> in <module>() /home/bosman/sage4.2linuxUbuntu_9.04i686Linux/local/lib/python2.6/sitepackages/sage/structure/sage_object.so in sage.structure.sage_object.loads (sage/structure/sage_object.c:8769)() /home/bosman/sage4.2linuxUbuntu_9.04i686Linux/local/lib/python2.6/sitepackages/sage/modules/free_module.pyc in __hash__(self) 4576 True 4577 """ > 4578 return hash(self.__basis) 4579 4580 def construction(self): AttributeError: 'FreeModule_submodule_field' object has no attribute '_FreeModule_submodule_with_basis_pid__basis'
Attachments (1)
Change History (15)
comment:1 Changed 13 years ago by
Changed 13 years ago by
Attachment:  trac_7516.patch added 

comment:2 Changed 13 years ago by
Status:  new → needs_review 

comment:3 Changed 13 years ago by
Status:  needs_review → needs_info 

If I understand the patch correctly, it violates a very essential assumption about hash codes: The hash has to be the same for objects that are equal. But with the patch, it may be possible that during unpickling the hash "0" is returned, while afterwards a completely different value is returned for the same object.
This is giving me headache. Isn't it be possible that things are put in the wrong hash bucket?
Wouldn't it be a cleaner solution to ensure that self.__basis is defined during unpickling before the hash is requested?
Could you explain why your solution is correct?
comment:4 Changed 9 years ago by
Milestone:  sage5.11 → sage5.12 

comment:5 Changed 9 years ago by
Milestone:  sage6.1 → sage6.2 

comment:6 Changed 9 years ago by
Milestone:  sage6.2 → sage6.3 

comment:7 Changed 8 years ago by
Milestone:  sage6.3 → sage6.4 

comment:8 followup: 9 Changed 5 years ago by
sage: V = VectorSpace(QQ, 2) sage: W = V.subspace([V([1,1])]) sage: Z = W.subspace([]) sage: WmodZ = W / Z sage: WmodZ(W(0)) (0) sage: loads(dumps(WmodZ)) Vector space quotient V/W of dimension 1 over Rational Field where V: Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [1 1] W: Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: []
Works for me. Add a doctest and close?
comment:9 Changed 5 years ago by
comment:10 Changed 5 years ago by
Branch:  → u/sbrandhorst/bug_in_pickling_quotient_module_over_pid 

comment:11 Changed 5 years ago by
Commit:  → ea6a00ba4750d97546755784041b5d3cee2f2de9 

Status:  needs_info → needs_review 
New commits:
ea6a00b  Added a doctest for pickling.

comment:12 Changed 5 years ago by
Milestone:  sage6.4 → sage8.1 

Reviewers:  → Travis Scrimshaw 
Once you put your real name as author, you can set a positive review.
comment:13 Changed 5 years ago by
Authors:  → Simon Brandhorst 

Status:  needs_review → positive_review 
comment:14 Changed 5 years ago by
Branch:  u/sbrandhorst/bug_in_pickling_quotient_module_over_pid → ea6a00ba4750d97546755784041b5d3cee2f2de9 

Resolution:  → fixed 
Status:  positive_review → closed 
NOTE: This bug does not happen for Free modules over ZZ. It's only over a field where the issue happens.