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

Fix do_pickle of cached_in_parent_method #22035

Closed
saraedum opened this issue Dec 7, 2016 · 15 comments
Closed

Fix do_pickle of cached_in_parent_method #22035

saraedum opened this issue Dec 7, 2016 · 15 comments

Comments

@saraedum
Copy link
Member

saraedum commented Dec 7, 2016

The do_pickle parameter was not properly passed on in CachedInParentMethod so that parameter actually never worked (the default was used instead which meant no pickling of caches.)
The doctest did not catch it since the parent was not pickled and unpickled because _parent of the class had been assigned, not of the instance.

Component: misc

Keywords: days85

Author: Julian Rüth

Branch/Commit: 7ea68d7

Reviewer: Florent Hivert

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

@saraedum saraedum added this to the sage-7.5 milestone Dec 7, 2016
@saraedum
Copy link
Member Author

saraedum commented Dec 7, 2016

@saraedum
Copy link
Member Author

saraedum commented Dec 7, 2016

Changed branch from u/saraedum/introduce__cached_in_argument_method to none

@saraedum
Copy link
Member Author

saraedum commented Dec 7, 2016

@saraedum
Copy link
Member Author

saraedum commented Dec 7, 2016

New commits:

7162b73Forward do_pickle to CachedFunction's constructor

@saraedum
Copy link
Member Author

saraedum commented Dec 7, 2016

Commit: 7162b73

@sagetrac-msaaltink
Copy link
Mannequin

sagetrac-msaaltink mannequin commented Dec 17, 2016

comment:4

This seems like an obvious change and looks like the right thing to do.

There is a small anomaly: because the cache is in the parent, and the parent can be shared my many instances, the do_pickle parameter does not always apply as hoped. Admittedly this is in corner cases, like this one

SP_parent = MyParent()

class SP_pickle(object):
     def parent(self): return SP_parent
     @cached_in_parent_method(do_pickle=True)
     def f(self, x):
          return x

class SP_no_pickle(object):
     def parent(self): return SP_parent
     @cached_in_parent_method(do_pickle=False)
     def f(self, x):
          return x

Here, if instances of SP_pickle and of SP_no_pickle are created, whether the cache is pickled or not depends on which instance's f was called first. I'm not quite sure whether this is a problem, and if so, whether it is bad enough to bother fixing.

@hivert
Copy link

hivert commented Mar 14, 2017

Reviewer: Florent Hivert,

@hivert
Copy link

hivert commented Mar 14, 2017

comment:5

Replying to @sagetrac-msaaltink:

There is a small anomaly: because the cache is in the parent, and the parent can be shared my many instances, the do_pickle parameter does not always apply as hoped. Admittedly this is in corner cases, like this one

Here, if instances of SP_pickle and of SP_no_pickle are created, whether the cache is pickled or not depends on which instance's f was called first. I'm not quite sure whether this is a problem, and if so, whether it is bad enough to bother fixing.

In my opinion, the fact that the cache should be pickled or not is a choice that should be made made by the parent. Due to the way we write the cached_in_parent decorator, it appears syntactically to be a choice of the element, but I think it really belongs to the parent. As a consequence I won't bother taking care of this very corner case. Actually, I would consider it broken.

Anyway, IHMO the winning argument is that, we don't have that much use cases for cached_in_parent (all of them being related to root systems, by the way...) and even less use cases for parent with two different classes of elements.

So I'm giving a positive review after fixing the merge.

@hivert
Copy link

hivert commented Mar 14, 2017

@hivert
Copy link

hivert commented Mar 14, 2017

Changed commit from 7162b73 to 7ea68d7

@hivert
Copy link

hivert commented Mar 14, 2017

New commits:

7ea68d7Merge branch 'develop' into t/22035/introduce__cached_in_argument_method

@tscrim
Copy link
Collaborator

tscrim commented Mar 17, 2017

Changed keywords from none to days85

@tscrim tscrim modified the milestones: sage-7.5, sage-8.0 Mar 17, 2017
@vbraun
Copy link
Member

vbraun commented Mar 25, 2017

comment:9

Reviewer name ends with a comma, is that intended? ;-)

@tscrim
Copy link
Collaborator

tscrim commented Mar 25, 2017

Changed reviewer from Florent Hivert, to Florent Hivert

@vbraun
Copy link
Member

vbraun commented Mar 27, 2017

Changed branch from u/hivert/introduce__cached_in_argument_method to 7ea68d7

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

4 participants