changeset 598:e763711472a5

merged
author james@X40
date Tue, 13 Jan 2009 16:00:36 -0500
parents c4579524baa6 (current diff) 605ab704abc3 (diff)
children bd777e960c7c
files pylearn/dbdict/newstuff.py
diffstat 2 files changed, 92 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/algorithms/aa.py	Tue Jan 13 16:00:24 2009 -0500
+++ b/pylearn/algorithms/aa.py	Tue Jan 13 16:00:36 2009 -0500
@@ -4,7 +4,7 @@
 from theano.tensor import nnet as NN
 import numpy as N
 
-class AutoEncoder(theano.FancyModule):
+class AutoEncoder(theano.Module):
 
     def __init__(self, input = None, regularize = True, tie_weights = True):
         super(AutoEncoder, self).__init__()
@@ -64,7 +64,7 @@
 
     def _instance_initialize(self, obj, input_size = None, hidden_size = None, seed = None, **init):
         if (input_size is None) ^ (hidden_size is None):
-            raise ValueError("Must specify hidden_size and target_size or neither.")
+            raise ValueError("Must specify hidden_size and input_size or neither.")
         super(AutoEncoder, self)._instance_initialize(obj, **init)
         if seed is not None:
             R = N.random.RandomState(seed)
--- a/pylearn/dbdict/newstuff.py	Tue Jan 13 16:00:24 2009 -0500
+++ b/pylearn/dbdict/newstuff.py	Tue Jan 13 16:00:36 2009 -0500
@@ -58,7 +58,7 @@
     """nested dictionary -> flat dictionary with '.' notation """
     d = {}
     def helper(d, prefix, obj):
-        if isinstance(obj, (str, int, float)):
+        if isinstance(obj, (str, int, float, list, tuple)):
             d[prefix] = obj #convert(obj)
         else:
             if isinstance(obj, dict):
@@ -513,6 +513,8 @@
                           help = 'redirect stdout and stderr to the workdir/stdout and workdir/stderr files')
 parser_cmdline.add_option('-w', '--workdir', action = 'store', dest = 'workdir', default = None,
                           help = 'the working directory in which to run the experiment')
+parser_cmdline.add_option('-n', '--dry-run', action = 'store_true', dest = 'dry_run', default = False,
+                          help = 'use this option to run the whole experiment in a temporary working directory (cleaned after use)')
 
 def runner_cmdline(options, experiment, *strings):
     """
@@ -533,14 +535,98 @@
     state = expand(parse(*strings))
     state.setdefault('dbdict', DD()).experiment = experiment
     experiment = resolve(experiment)
-    workdir = options.workdir or format_d(state, sep=',', space = False)
+    if options.workdir and options.dry_run:
+        raise UsageError('Please use only one of: --workdir, --dry-run.')
+    if options.workdir:
+        workdir = options.workdir
+    elif options.dry_run:
+        workdir = tempfile.mkdtemp()
+    else:
+        workdir = format_d(state, sep=',', space = False)
     channel = StandardChannel(workdir,
                               experiment, state,
                               redirect_stdout = options.redirect or options.redirect_stdout,
                               redirect_stderr = options.redirect or options.redirect_stderr)
     channel.run(force = options.force)
+    if options.dry_run:
+        shutil.rmtree(workdir, ignore_errors=True)
+        
+runner_registry['cmdline'] = (parser_cmdline, runner_cmdline)
 
-runner_registry['cmdline'] = (parser_cmdline, runner_cmdline)
+
+
+
+parser_filemerge = OptionParser(usage = '%prog filemerge [options] <experiment> <file> <file2> ...')
+parser_filemerge.add_option('-f', '--force', action = 'store_true', dest = 'force', default = False,
+                          help = 'force running the experiment even if it is already running or completed')
+parser_filemerge.add_option('--redirect-stdout', action = 'store_true', dest = 'redirect_stdout', default = False,
+                          help = 'redirect stdout to the workdir/stdout file')
+parser_filemerge.add_option('--redirect-stderr', action = 'store_true', dest = 'redirect_stderr', default = False,
+                          help = 'redirect stderr to the workdir/stdout file')
+parser_filemerge.add_option('-r', '--redirect', action = 'store_true', dest = 'redirect', default = False,
+                          help = 'redirect stdout and stderr to the workdir/stdout and workdir/stderr files')
+parser_filemerge.add_option('-w', '--workdir', action = 'store', dest = 'workdir', default = None,
+                          help = 'the working directory in which to run the experiment')
+parser_filemerge.add_option('-n', '--dry-run', action = 'store_true', dest = 'dry_run', default = False,
+                          help = 'use this option to run the whole experiment in a temporary working directory (cleaned after use)')
+
+def runner_filemerge(options, experiment, mainfile, *other_files):
+    """
+    Start an experiment with parameters given in files.
+
+    Usage: filemerge [options] <experiment> <file> <file2> ...
+
+    Run an experiment with parameters provided in plain text files.
+    A single experiment will be run with the union of all the
+    parameters listed in the files.
+
+    Example:
+    <in file blah1.txt>
+    text.first = "hello"
+    text.second = "world"
+
+    <in file blah2.txt>
+    number = 12
+    numbers.a = 55
+    numbers.b = 56
+
+    Given these files, the following command using filemerge:
+    $ dbdict-run filemerge mymodule.my_experiment blah1.txt blah2.txt
+
+    is equivalent to this one using cmdline:
+    $ dbdict-run cmdline mymodule.my_experiment \\
+        text.first=hello text.second=world \\
+        number=12 numbers.a=55 numbers.b=56
+    """
+    with open(mainfile) as f:
+        _state = parse(*map(str.strip, f.readlines()))
+    for file in other_files:
+        if '=' in file:
+            _state.update(parse(file))
+        else:
+            with open(file) as f:
+                _state.update(parse(*map(str.strip, f.readlines())))
+    state = expand(_state)
+    state.setdefault('dbdict', DD()).experiment = experiment
+    experiment = resolve(experiment)
+    if options.workdir and options.dry_run:
+        raise UsageError('Please use only one of: --workdir, --dry-run.')
+    if options.workdir:
+        workdir = options.workdir
+    elif options.dry_run:
+        workdir = tempfile.mkdtemp()
+    else:
+        workdir = format_d(state, sep=',', space = False)
+    channel = StandardChannel(workdir,
+                              experiment, state,
+                              redirect_stdout = options.redirect or options.redirect_stdout,
+                              redirect_stderr = options.redirect or options.redirect_stderr)
+    channel.run(force = options.force)
+    if options.dry_run:
+        shutil.rmtree(workdir, ignore_errors=True)
+        
+runner_registry['filemerge'] = (parser_filemerge, runner_filemerge)
+
 
 
 
@@ -686,7 +772,7 @@
         print 'parameters     How to list the parameters for an experiment.'
         print
         print bold('Available commands: (use help <command> for more info)')
-        for name, command in sorted(runner_registry.iteritems()):
+        for name, (parser, command) in sorted(runner_registry.iteritems()):
             print name.ljust(20), format_help(command).split('\n')[0]
         return
     elif topic == 'experiment':