Mercurial > pylearn
diff pylearn/dbdict/newstuff.py @ 589:6a7f3d83c72b
dbdict stuff
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Wed, 17 Dec 2008 15:39:30 -0500 |
parents | 5020b12e87ee |
children | f8d29730f146 |
line wrap: on
line diff
--- a/pylearn/dbdict/newstuff.py Wed Dec 17 15:38:37 2008 -0500 +++ b/pylearn/dbdict/newstuff.py Wed Dec 17 15:39:30 2008 -0500 @@ -11,7 +11,7 @@ ### misc ################################################################################ -class DD(defaultdict): +class DD(dict): def __getattr__(self, attr): return self[attr] def __setattr__(self, attr, value): @@ -43,6 +43,7 @@ return obj def flatten(obj): + """nested dictionary -> flat dictionary with '.' notation """ d = {} def helper(d, prefix, obj): if isinstance(obj, (str, int, float)): @@ -60,9 +61,10 @@ return d def expand(d): - def dd(): - return DD(dd) - struct = dd() + """inverse of flatten()""" + #def dd(): + #return DD(dd) + struct = DD() for k, v in d.iteritems(): if k == '': raise NotImplementedError() @@ -70,7 +72,7 @@ keys = k.split('.') current = struct for k2 in keys[:-1]: - current = current[k2] + current = current.setdefault(k2, DD()) current[keys[-1]] = v #convert(v) return struct @@ -157,15 +159,19 @@ class Channel(object): - COMPLETE = None - INCOMPLETE = True + COMPLETE = property(lambda s:None, + doc=("Experiments should return this value to " + "indicate that they are done (if not done, return `Incomplete`")) + INCOMPLETE = property(lambda s:True, + doc=("Experiments should return this value to indicate that " + "they are not done (if done return `COMPLETE`)")) - START = 0 - """dbdict.status == START means a experiment is ready to run""" - RUNNING = 1 - """dbdict.status == RUNNING means a experiment is running on dbdict_hostname""" - DONE = 2 - """dbdict.status == DONE means a experiment has completed (not necessarily successfully)""" + START = property(lambda s: 0, + doc="dbdict.status == START means a experiment is ready to run") + RUNNING = property(lambda s: 1, + doc="dbdict.status == RUNNING means a experiment is running on dbdict_hostname") + DONE = property(lambda s: 2, + doc="dbdict.status == DONE means a experiment has completed (not necessarily successfully)") # Methods to be used by the experiment to communicate with the channel @@ -504,7 +510,7 @@ lr=0.03 """ state = expand(parse(*strings)) - state.dbdict.experiment = experiment + state.setdefault('dbdict', DD()).experiment = experiment experiment = resolve(experiment) workdir = options.workdir or format_d(state, sep=',', space = False) channel = StandardChannel(workdir,