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

Value of cached methods should not always be pickled #15692

Closed
simon-king-jena opened this issue Jan 18, 2014 · 78 comments
Closed

Value of cached methods should not always be pickled #15692

simon-king-jena opened this issue Jan 18, 2014 · 78 comments

Comments

@simon-king-jena
Copy link
Member

In #15278, the hash of graphs was turned into a @cached_method. If a cached method is pickled, then the cached value is pickled as well. In the case of a hash value, this is not always what we want, since the hash value might depend on the memory address of an object, or worse: The hash function might change in future implementations.

That's to say: If you save object O now, together with hash value 123, and later load it, then hash(O) will still be 123, even if a newly constructed object P with O==P might have hash(P)==456, because of a change in the hash function.

This obviously is a problem. There is something called sage.misc.cachefunc.ClearCacheOnPickle, but I don't know if this would really help in this case. Also, this would clear all cache values at once. Also, I don't know if it works for cached methods that do not take arguments (beside self).

I suggest that we should instead have an optional parameter for sage.misc.cachefunc.CachedMethodCallerNoArgs that determines whether or not the cached value is preserved, and use it on graphs (and future applications of cached method on __hash__).

Depends on #16337

CC: @nathanncohen @vbraun @nbruin @novoselt @sagetrac-jkeitel @nthiery

Component: pickling

Keywords: hash, cache, days71

Author: Julian Rüth

Branch: a18cbf5

Reviewer: Vincent Delecroix, David Roe

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

@simon-king-jena simon-king-jena added this to the sage-6.1 milestone Jan 18, 2014
@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
@saraedum
Copy link
Member

comment:3

In #15149 it was proposed that caches should be 'opt-in and not opt-out' (#15149 comment:6). Imho most caches are not used for things that are horribly expensive to compute, they are just too expensive to be computed again all the time.

Would somebody mind if I implemented it that way, i.e., the default for a cache would be that it is not pickled?

@saraedum
Copy link
Member

Branch: u/saraedum/ticket/15692

@saraedum
Copy link
Member

Dependencies: #16337

@saraedum
Copy link
Member

Author: Julian Rueth

@novoselt
Copy link
Member

comment:7

I'm in support of this although I am not the right person to review the changes.


New commits:

ce27b84Removed sage.misc.cachefunc.ClearCacheOnPickle
e27e316Propagate key of a @cached_method correctly
94fcddbMerge branch 'u/saraedum/ticket/16337' of git://trac.sagemath.org/sage into ticket/15692
72fce8bAdded a pickle parameter for @cached_method
0717849Enable pickling of the cache for groebner_basis()

@novoselt
Copy link
Member

Commit: 0717849

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2014

Changed commit from 0717849 to 9eab84b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 23, 2014

Branch pushed to git repo; I updated commit sha1. New commits:

9eab84bMerge branch 'develop' into ticket/15692

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@fchapoton
Copy link
Contributor

comment:10

does not apply, needs rebase

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 8, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

13b4e4cMerge branch 'develop' into t/15692/ticket/15692

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 8, 2015

Changed commit from 9eab84b to 13b4e4c

@fchapoton
Copy link
Contributor

comment:13

one failing doctest, see patchbot report

@saraedum
Copy link
Member

comment:59

The dirichlet.py doctests pass now. Let's see what the patchbot thinks about the rest.

@saraedum
Copy link
Member

saraedum commented Jul 1, 2016

Work Issues: pickle jar

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 7, 2016

Changed commit from a152dc4 to 141af2e

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 7, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

141af2eUnpickle legacy dirichlet characters

@saraedum
Copy link
Member

saraedum commented Jul 7, 2016

Changed work issues from pickle jar to none

@kiwifb
Copy link
Member

kiwifb commented Jul 7, 2016

comment:63

Looks like your last commit needs a tiny little bit more work

sage -t --long src/sage/modular/dirichlet.py
**********************************************************************
File "src/sage/modular/dirichlet.py", line 1760, in sage.modular.dirichlet.DirichletCharacter.__setstate__
Failed example:
    loads(dumps(e)) == e
Expected nothing
Got:
    True

From the bot.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2016

Changed commit from 141af2e to a18cbf5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 8, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

a18cbf5Fixed doctest for element of DirichletGroup

@saraedum
Copy link
Member

saraedum commented Jul 8, 2016

comment:65

Sorry, that was dumb. I hope it's better now :)


New commits:

a18cbf5Fixed doctest for element of DirichletGroup

@kiwifb
Copy link
Member

kiwifb commented Jul 9, 2016

comment:67

Bot happy, I am putting this back to positive.

@vbraun
Copy link
Member

vbraun commented Jul 9, 2016

Changed branch from u/saraedum/ticket/15692 to a18cbf5

@jdemeyer
Copy link

Changed commit from a18cbf5 to none

@jdemeyer
Copy link

Changed author from Julian Rueth to Julian Rüth

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

10 participants