Sage: Ticket #11845: Pickle python functions
https://trac.sagemath.org/ticket/11845
<p>
Simon King pointed out that, although python function objects are normally not guaranteed to be picklable, the marshal module is happy to serialize code objects (although portability of the result is not guaranteed across versions), see
</p>
<p>
<a class="ext-link" href="http://groups.google.com/group/sage-devel/browse_thread/thread/f1a213d1cac0719c"><span class="icon"></span>sage-devel thread</a>
</p>
<p>
Since sage pickles are supposed to be highly portable, we should probably not enable the feature by default, but the feature can be extremely useful when, for instance, distributing jobs across multiple worker nodes.
</p>
<p>
Some work is needed to work properly with closures, so having a debugged and well-maintained interface for pickling python functions is desirable. I have no idea whether it would be appropriate to stuff somewhere in the sage library, so for now this ticket can serve as a repository.
</p>
<hr />
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/11845
Trac 1.1.6nbruinSun, 25 Sep 2011 02:30:40 GMTattachment set
https://trac.sagemath.org/ticket/11845
https://trac.sagemath.org/ticket/11845
<ul>
<li><strong>attachment</strong>
set to <em>picklefunc.py</em>
</li>
</ul>
<p>
implementation of a <a class="missing wiki">PickleableFunction?</a> class (not a patch!)
</p>
TicketburcinSun, 25 Sep 2011 09:35:29 GMT
https://trac.sagemath.org/ticket/11845#comment:1
https://trac.sagemath.org/ticket/11845#comment:1
<p>
Note that there is already some code in the library for this in <code>sage.misc.fpickle</code>. It is used at least in <code>@parallel</code> and pickling of symbolic functions with user defined evaluation, derivation, etc. methods. Now that I read the thread on sage-devel, I realize that we might have problems unpickling these symbolic functions if this pickle format is not compatible between Python versions.
</p>
TicketnbruinMon, 26 Sep 2011 01:07:45 GMT
https://trac.sagemath.org/ticket/11845#comment:2
https://trac.sagemath.org/ticket/11845#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/11845#comment:1" title="Comment 1">burcin</a>:
</p>
<blockquote class="citation">
<p>
Note that there is already some code in the library for this in <code>sage.misc.fpickle</code>. It is used at least in <code>@parallel</code> and pickling of symbolic functions with user defined evaluation, derivation, etc. methods.
</p>
</blockquote>
<p>
Are those pickles doctested? In that case, sage's picklejar would already be tainted. Incidentally, if @parallel uses this to distribute code & data over workers, then supporting closures is probably a very welcome improvement. Creating a closure for each job is a virtually ideal way of wrapping code&data together for distribution.
</p>
Ticket