This module provides some objects to simplify some basic operations. The two main features are mmf.objects.Archivable and mmf.objects.StateVars which provides a mechanism for automatic attribute processing and documentation.
By inheriting from mmf.objects.Archivable, users can make classes that can be archived to a string of executable python code. This includes all needed imports etc. and is human readable. Thus, it may be used like the pickle module. However, unlike pickle, the representation is easy to read and edit. A big advantage is that by a few simple edits of the import section, one can change the location of objects and ensure that they are not irretrievably lost across version changes, module reorganizations etc.
Note
The archive mechanism is likely to be less efficient in terms of space and time than pickle.
To allow archiving, objects can:
By inheriting from mmf.objects.StateVars, an object is setup with machinery to aid in construction and attribute definition. The basic idea is to define the class attributes via a list _state_vars and then call mmf.objects.process_vars() which modifies the class documentation and provides a default constructor that accepts attributes and automatically assigns them.
The role of __init__() changes somewhat. Instead of just constructing the object, it be comes the calculator. One of the options for attributes defined through _state_vars is mmf.objects.Computed. These attributes must be computed in __init__(). To facilitate this role, when properties are assigned, __init__() is called (by mmf.objects.StateVars.__setattr__) with the changed property included in the keyword arguments. Thus, the user can streamline the calculation, only recomputing the required components. (At first, just recompute everything, then profile and optimize!)
mmf.objects.Container is basically the same as mmf.objects.StateVars, but has the mmf.objects.StateVars._dynamic set to True which allows attributes to be added dynamically. Thus, these act as a generic “container” with nice archival and construction features.