mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-02 00:46:36 +08:00
Progressing with pickling. Pickling of PropModels doesn't work which cause
many classes that use it not to pickle.
This commit is contained in:
+30
-2
@@ -22,6 +22,34 @@ class BaseProblem(object):
|
||||
|
||||
PropMap = None #: A SimPEG PropertyMap class.
|
||||
|
||||
# Pickleing support methods
|
||||
def __getstate__(self):
|
||||
'''
|
||||
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||
|
||||
Used when doing:
|
||||
pickle.dump(pickleFile,object)
|
||||
'''
|
||||
odict = self.__dict__.copy()
|
||||
# Remove fields that are not needed
|
||||
del odict['hook']
|
||||
del odict['setKwargs']
|
||||
# Return the dict
|
||||
return odict
|
||||
|
||||
def __setstate__(self,odict):
|
||||
'''
|
||||
Function that sets a pickle dictionary in to an object.
|
||||
|
||||
Used when doing:
|
||||
object = pickle.load(pickleFile)
|
||||
'''
|
||||
# Update the dict
|
||||
self.__dict__.update(odict)
|
||||
# Re-hook the methods to the object
|
||||
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||
|
||||
@property
|
||||
def mapping(self):
|
||||
"A SimPEG.Map instance or a property map is PropMap is not None"
|
||||
@@ -32,8 +60,8 @@ class BaseProblem(object):
|
||||
val._assertMatchesPair(self.mapPair)
|
||||
self._mapping = val
|
||||
else:
|
||||
self._mapping = self.PropMap(val)
|
||||
|
||||
self._mapping = self.PropMap(val)
|
||||
|
||||
def __init__(self, mesh, mapping=None, **kwargs):
|
||||
Utils.setKwargs(self, **kwargs)
|
||||
assert isinstance(mesh, Mesh.BaseMesh), "mesh must be a SimPEG.Mesh object."
|
||||
|
||||
Reference in New Issue
Block a user