Opened 11 years ago

Closed 4 years ago

#7516 closed defect (fixed)

bug in pickling quotient module over pid

Reported by: was Owned by: was
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 was 11 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 11 years ago by was

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 11 years ago by was

comment:2 Changed 11 years ago by was

  • Status changed from new to needs_review

comment:3 Changed 11 years ago by SimonKing

  • Status changed from needs_review to 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 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:5 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:6 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 follow-up: Changed 4 years ago by sbrandhorst

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 4 years ago by tscrim

Replying to sbrandhorst:

Works for me. Add a doctest and close?

Yep.

Version 0, edited 4 years ago by tscrim (next)

comment:10 Changed 4 years ago by sbrandhorst

  • Branch set to u/sbrandhorst/bug_in_pickling_quotient_module_over_pid

comment:11 Changed 4 years ago by sbrandhorst

  • Commit set to ea6a00ba4750d97546755784041b5d3cee2f2de9
  • Status changed from needs_info to needs_review

New commits:

ea6a00bAdded a doctest for pickling.

comment:12 Changed 4 years ago by tscrim

  • Milestone changed from sage-6.4 to sage-8.1
  • Reviewers set to Travis Scrimshaw

Once you put your real name as author, you can set a positive review.

comment:13 Changed 4 years ago by sbrandhorst

  • Authors set to Simon Brandhorst
  • Status changed from needs_review to positive_review

comment:14 Changed 4 years ago by vbraun

  • Branch changed from u/sbrandhorst/bug_in_pickling_quotient_module_over_pid to ea6a00ba4750d97546755784041b5d3cee2f2de9
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.