Issue33

Title Fields and their elements cannot be pickled
Type wish Status chatting
Importance
Superseder Nosy List mg
Assigned To mg Keywords

Created on 2008-04-11.16:07:48 by mg, last changed 2008-09-23.17:40:33 by mg.

Messages
msg151 (view) Author: mg Date: 2008-07-30.00:14:53
This is very similar to what we do now, except that the classes are
defined as proper subclasses instead of being new unrelated classes.

It will also pull out the main Field class instead of having it
"hidden" inside the GF function -- the advantage will be that doctests
will start working again and Epydoc can see the class.
msg150 (view) Author: mg Date: 2008-07-30.00:12:50
My idea is this: we create the classes representing fields dynamically
and make sure to put them in the viff.field module namespace (file
field.py):

class Field(object):
    def __init__(self, value):
        self.value = value

    def __add__(self, other):
        return self.field((self.value + other.value) % self.modulus)

def GF(modulus):
    g = globals()
    name = 'Z%dElement' % modulus
    if not name in g:
        F = type(name, (Field,), dict(modulus=modulus))
        F.field = F
        g[name] = F
        print "Created", F
    return g[name]

This ensures that the pickle module can find them (in another file):


# Create type using GF.
from field import GF
Z19 = GF(19)
x = Z19(7)

# Create type and import it.
GF(23)
from field import Z23Element as Z23
y = Z23(5)

# Testing dumping and loading.
from pickle import dumps, loads
p = dumps(x)
print p

z = loads(p)
print x, z
msg84 (view) Author: mg Date: 2008-04-11.16:07:48
We cannot pickle (serialize) fields if they are generated by
viff.field.GF. This is because the classes returned are not top-level.

Field elements can therefore also not be serialized. I think I have an
idea that will solve this -- I'm just putting this here to track it
since it also affects Issue 3.
History
Date User Action Args
2008-09-23 17:40:33mgsettype: feature -> wish
2008-09-23 16:22:05tpjsettype: feature
2008-07-30 00:14:54mgsetpriority: 3
messages: + msg151
2008-07-30 00:12:50mgsetstatus: unread -> chatting
messages: + msg150
2008-04-11 16:07:48mgcreate
Note:
The indicated property no longer exists