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: sage-8.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:

Status badges

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/sage-4.2-linux-Ubuntu_9.04-i686-Linux/local/lib/python2.6/site-packages/sage/structure/sage_object.so
in sage.structure.sage_object.loads
(sage/structure/sage_object.c:8769)()

/home/bosman/sage-4.2-linux-Ubuntu_9.04-i686-Linux/local/lib/python2.6/site-packages/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)

trac_7516.patch (1.4 KB) - added by William Stein 13 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 13 years ago by William Stein

NOTE: This bug does not happen for Free modules over ZZ. It's only over a field where the issue happens.

sage: V = FreeModule(ZZ, 2)
sage: W = V.submodule([V([1,1])])
sage: Z = W.submodule([])
sage: WmodZ = W / Z
sage: loads(dumps(WmodZ))
Finitely generated module V/W over Integer Ring with invariants (0)
sage: WmodZ(W(0))
(0)
sage: loads(dumps(WmodZ))
Finitely generated module V/W over Integer Ring with invariants (0)

Changed 13 years ago by William Stein

Attachment: trac_7516.patch added

comment:2 Changed 13 years ago by William Stein

Status: newneeds_review

comment:3 Changed 13 years ago by Simon King

Status: needs_reviewneeds_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 Jeroen Demeyer

Milestone: sage-5.11sage-5.12

comment:5 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:6 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:7 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:8 Changed 5 years ago by Simon Brandhorst

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 in reply to:  8 Changed 5 years ago by Travis Scrimshaw

Replying to sbrandhorst:

Works for me. Add a doctest and close?

Yep. Addendum - Also works for me.

Last edited 5 years ago by Travis Scrimshaw (previous) (diff)

comment:10 Changed 5 years ago by Simon Brandhorst

Branch: u/sbrandhorst/bug_in_pickling_quotient_module_over_pid

comment:11 Changed 5 years ago by Simon Brandhorst

Commit: ea6a00ba4750d97546755784041b5d3cee2f2de9
Status: needs_infoneeds_review

New commits:

ea6a00bAdded a doctest for pickling.

comment:12 Changed 5 years ago by Travis Scrimshaw

Milestone: sage-6.4sage-8.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 Simon Brandhorst

Authors: Simon Brandhorst
Status: needs_reviewpositive_review

comment:14 Changed 5 years ago by Volker Braun

Branch: u/sbrandhorst/bug_in_pickling_quotient_module_over_pidea6a00ba4750d97546755784041b5d3cee2f2de9
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.