save/pickle data of cached_method (used in ideals and groebner_basis)

16 views
Skip to first unread message

Daniel Krenn

unread,
Aug 12, 2017, 4:29:16 AM8/12/17
to sage-s...@googlegroups.com
I have an ideal and computed its Groebner basis (6 hours). Now I want to
store this result, which is not the problem itself, but when loading
this data, it seems not possible to reconstruct the ideal (meaning
create it with the original generators and "bootstrap" the groebner
basis found earlier).

As the Groebner basis is cached somewhere via cached_method: Is there an
option, so that the data stored by cached_method is saved as well when
saving e.g. the whole ideal?

Any ideas how to do this (nicely)?

[I ask for "nicely", as, of course, I can create the ideal of the
original generators, and then access the cache of groebner_basis
manually and push the stored data somehow into it.

Volker Braun

unread,
Aug 12, 2017, 5:14:08 AM8/12/17
to sage-support
Caches from @cached_method are pickled by default, but the class can opt-out of this. Sometimes this is necessary to make pickling work (not every Cython object is pickle-able).

Daniel Krenn

unread,
Aug 12, 2017, 6:10:51 AM8/12/17
to sage-s...@googlegroups.com
On 2017-08-12 11:14, Volker Braun wrote:
> Caches from @cached_method are pickled by default, but the class can
> opt-out of this. Sometimes this is necessary to make pickling work (not
> every Cython object is pickle-able).

Hmmm....shouldn't the below work then?

sage: class A(SageObject):
....: @cached_method
....: def a(self):
....: print('oo')
....: return 42
....:
sage: a = A()
sage: a.a()
oo
42
sage: a.a()
42
sage: save(a, 'a.sobj')
sage: b = load('a.sobj')
sage: b.a() # again "computes" 42
oo
42

Daniel Krenn

unread,
Aug 12, 2017, 7:19:59 AM8/12/17
to sage-s...@googlegroups.com
Indeed there is
@cached_method(do_pickle=True)
...and this is used for Groebner basis in the ideal. So all my problems
are solved :)



Reply all
Reply to author
Forward
0 new messages