Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in pickling quotient module over pid #7516

Closed
williamstein opened this issue Nov 23, 2009 · 12 comments
Closed

bug in pickling quotient module over pid #7516

williamstein opened this issue Nov 23, 2009 · 12 comments

Comments

@williamstein
Copy link
Contributor

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'

Component: linear algebra

Author: Simon Brandhorst

Branch/Commit: ea6a00b

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/7516

@williamstein williamstein added this to the sage-5.11 milestone Nov 23, 2009
@williamstein williamstein self-assigned this Nov 23, 2009
@williamstein
Copy link
Contributor Author

comment:1

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)

@williamstein
Copy link
Contributor Author

Attachment: trac_7516.patch.gz

@simon-king-jena
Copy link
Member

comment:3

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?

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@simonbrandhorst
Copy link

comment:8
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?

@tscrim
Copy link
Collaborator

tscrim commented Oct 9, 2017

comment:9

Replying to @simonbrandhorst:

Works for me. Add a doctest and close?

Yep. Addendum - Also works for me.

@simonbrandhorst
Copy link

@simonbrandhorst
Copy link

New commits:

ea6a00bAdded a doctest for pickling.

@simonbrandhorst
Copy link

Commit: ea6a00b

@tscrim
Copy link
Collaborator

tscrim commented Oct 9, 2017

comment:12

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

@tscrim
Copy link
Collaborator

tscrim commented Oct 9, 2017

Reviewer: Travis Scrimshaw

@tscrim tscrim modified the milestones: sage-6.4, sage-8.1 Oct 9, 2017
@simonbrandhorst
Copy link

Author: Simon Brandhorst

@vbraun
Copy link
Member

vbraun commented Oct 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants