[sage-devel] Re: A question on pickling cached methods

2019-07-02 Thread Kwankyu Lee


On Thursday, June 27, 2019 at 9:45:42 PM UTC+9, Simon King wrote:
>
>
> I think if pickling doesn't preserve the content of the cached method 
> then it is a bug. 
>

UniqueRepresentation objects do not preserve the content of the cached 
method with do_pickle=True.

This problem is solved in https://trac.sagemath.org/ticket/28096 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/e7dc1423-609c-4007-bd7c-9b6ca1359974%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: A question on pickling cached methods

2019-06-27 Thread Kwankyu Lee

>
> From the code, I learned that there is "do_pickle" option. With 
> "do_pickle=True", the content of the cached method is indeed preserved with 
> an experimental class. I will check again with my production code.
>

I applied "do_pickle=True" option to F.weierstrass_points() with global 
function field F. It doesn't work. 

I think pickling should always work with objects with cached methods; 
otherwise saving objects makes little sense.

Anyway, thanks for all comments.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/3ee90675-9244-4c25-8ead-5698c3cc9557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: A question on pickling cached methods

2019-06-27 Thread Kwankyu Lee


On Thursday, June 27, 2019 at 10:20:55 PM UTC+9, Volker Braun wrote:
>
> There is the do_pickle argument, e.g. from TFM:
>
> sage: class C:
> : @cached_method(do_pickle=True)
> : def __hash__(self):
> : return id(self)
>
>
> Note that it can cause the following problem: Not every circularly 
> dependent collection of cython objects can be pickled. Cached values can 
> make the difference between what can and cannot be pickled. So whether or 
> not pickling works can't reliably be tested in that case. 
>

I see. Thanks. 

I would wish "do_pickle=True" is the default. But I guess this would 
degrade the performance...

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/b69edb56-9bc9-4c28-b110-ba307af98e94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: A question on pickling cached methods

2019-06-27 Thread Kwankyu Lee


On Thursday, June 27, 2019 at 9:45:42 PM UTC+9, Simon King wrote:
>
> Hi! 
>
> Is it a Python object? 
>

Yes.
 

> A cached method (if that hasn't changed since I last looked at the code) 
> stores the cached values in some dict stored as an attribute, and when 
> you pickle the object (at least when no __reduce__ method interferes), 
> it should automatically store that attribute. 
>
> But you say that the method is called "genus". So, probably it has not 
> function arguments, right? It could be that the cache is stored 
> differently in that case. 
>
> I think if pickling doesn't preserve the content of the cached method 
> then it is a bug. 
>

>From the code, I learned that there is "do_pickle" option. With 
"do_pickle=True", the content of the cached method is indeed preserved with 
an experimental class. I will check again with my production code.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/5ac2b641-f212-42d4-b15a-061083463fcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: A question on pickling cached methods

2019-06-27 Thread Volker Braun
There is the do_pickle argument, e.g. from TFM:

sage: class C:
: @cached_method(do_pickle=True)
: def __hash__(self):
: return id(self)


Note that it can cause the following problem: Not every circularly 
dependent collection of cython objects can be pickled. Cached values can 
make the difference between what can an cannot be pickled. So whether or 
not pickling works can't reliably be tested in that case. 


On Thursday, June 27, 2019 at 5:07:04 AM UTC+2, Kwankyu Lee wrote:
>
> Hi,
>
> Suppose I have an object X. I computed X.genus(), which took a long time. 
> The method genus() is a cached method. So it gives the result quickly next 
> time. Then I saved the object X. After loading X in a new session, I want 
> X.genus() to give the cached result rather than computing it again.
>
> Is it possible to implement genus() to behave in such a way? Is there some 
> option to @cached_method decorator for that purpose?
>
> I am reading the code for cached methods, but you answer will help me. 
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/9b2c316e-b601-4e14-af28-0eef2cb4d189%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: A question on pickling cached methods

2019-06-27 Thread Simon King
Hi!

Is it a Python object?

A cached method (if that hasn't changed since I last looked at the code)
stores the cached values in some dict stored as an attribute, and when
you pickle the object (at least when no __reduce__ method interferes),
it should automatically store that attribute.

But you say that the method is called "genus". So, probably it has not
function arguments, right? It could be that the cache is stored
differently in that case.

I think if pickling doesn't preserve the content of the cached method
then it is a bug.

Best regards,
Simon

On 2019-06-27, Kwankyu Lee  wrote:
>
>
> On Thursday, June 27, 2019 at 4:41:30 PM UTC+9, John Cremona wrote:
>>
>> I think this is one disadvantage of using the cached_method decorator, 
>> instead of the clumsier way of actually storing the result in the object, 
>> eg. by setting X._genus.  In your example I cannot think of a reason why we 
>> would not want to store the genus as an attribute after computing it.
>>
>
> I thought the same. I expected the cached_method decorator could make a 
> (pseudo) attribute attached to the object magically somehow if I cast the 
> right spell...
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/qf2dpe%247rp9%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.