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

matrices cache their hash, which causes subtle bugs when moving objects between 32/64 bit #5624

Open
williamstein opened this issue Mar 28, 2009 · 1 comment

Comments

@williamstein
Copy link
Contributor

On Sat, Mar 28, 2009 at 6:26 AM, Jason Bandlow <...> wrote:
>> I'm guessing this is a subtle 32 versus 64-bit issue involving
>> pickling and assumptions made somewhere in the combinat or other sage
>> code involving 32/64-bit.  The notebook is 64-bit and I bet your
>> computer is 32-bit.
>>
>> By the way, this works on the notebook in the context of your session above:
>>
>> for a, b in M.iteritems():
>>     if a == key: print b
>>
>
> Thanks William!  This does seem likely to be the problem.  I'll do more
> investigation when I get a chance and see if I can find out precisely
> where the problem is.

I know of one place in sage where objects cache their hash for efficiency reasons (e.g., I think Sage matrices do). I hadn't thought about the fact that pickling, moving to an object to a platform where the hashes are different, and unpickling, would result in the subtle issue above, but that makes sense.   Here is an example:

On a 32-bit platform do this:

sage: a = matrix(ZZ,2,[1,-2,4,1993938292]); a.set_immutable(); b = {a:5}; save(b,'/Users/wstein/b.sobj')

Then load b on a 64-bit platform (e.g. ,sage.math):

sage: a = matrix(ZZ,2,[1,-2,4,1993938292]); a.set_immutable(); b = load('b.sobj'); b[a]
boom! KeyError ...
sage: sage: b.keys()[0] == a
True

The fix here is that right before pickling the cached hash of the matrix should be deleted.

I don't know any other places in Sage that do the above.  

Component: misc

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

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Mar 28, 2009

comment:1

CombinatorialObject (and hence also its many subclasses) does this; see __hash__ at line 769 of sage/combinat/combinat.py

@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
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
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

3 participants