Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #15692: Value of cached methods should not always be pickled
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__`). URL: https://trac.sagemath.org/15692 Reported by: SimonKing Ticket author(s): Julian Rueth Reviewer(s): Vincent Delecroix, David Roe
- Loading branch information
Showing
8 changed files
with
420 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.