def clean_invalid_experiments(cfg, experiments): valid_folders = [] for experiment in experiments: folder = core.get_folder(cfg, experiment) valid_folders.append(folder) raw_folder = core.get_raw_folder(cfg) meta_file = raw_folder + '/' + dimensions.META_FILE folders = glob.glob(raw_folder + '/*') folders = [f for f in folders if f not in valid_folders and f != meta_file] if len(folders) == 0: print "no invalid expfolders" return print "Removing following folders: " for folder in folders: print "\t", folder r = 'y' print "sure? [y/N]" r = utils.getch() if r == 'y': for folder in folders: shutil.rmtree(folder)
def filter_one(cfg, experiments, filter, invert, only_ran): """ """ wd = os.getcwd() filtered_experiments = [] for experiment in experiments: if only_ran and core.experiment_ran(cfg, experiment): folder = core.get_folder(cfg, experiment) os.chdir(folder) outf = open(core.outputFile) #outf.readline() ret = filter(experiment, outf) if not invert and ret: filtered_experiments.append(experiment) if invert and not ret: filtered_experiments.append(experiment) outf.close() os.chdir(wd) elif not only_ran: folder = core.get_folder(cfg, experiment) if os.path.exists(folder): os.chdir(folder) if os.path.exists(core.outputFile): outf = open(core.outputFile) #outf.readline() else: outf = None ret = filter(experiment, outf) if not invert and ret: filtered_experiments.append(experiment) if invert and not ret: filtered_experiments.append(experiment) if outf: outf.close() os.chdir(wd) else: ret = filter(experiment, None) if not invert and ret: filtered_experiments.append(experiment) if invert and not ret: filtered_experiments.append(experiment) return filtered_experiments
def print_status(cfg, experiments): name = cfg.name if hasattr(cfg, 'name') else os.getcwd() print HEAD2 print 'Experiment set:', name print LINE total_runs = len(experiments) #missing_runs = total_runs - core.success_count(cfg, experiments) success = core.success_count(cfg, experiments) failed = len(core.get_failed(cfg, experiments, False)) missing = len(core.get_failed(cfg, experiments, True)) print 'Statistics:' print ' Total : %d' % (total_runs) print ' Finished : %d' % (success + failed) print ' Pending : %d' % (missing - failed) print ' Failed : %d' % (failed) print 'Running:' for e in experiments: v = core.experiment_running(cfg, e) if v: print '%10d : %s' % (v, core.get_folder(cfg, e)) print HEAD2 print
sys.stderr = sys.__stderr__ print "Interrupted on prepare_global()" sys.exit(1) finally: if f: f.close() sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ if not options.global_only: # execution loop for experiment in experiments: # One more run actual_runs += 1 # get dir name and create if necessary folder = core.get_folder(cfg, experiment, True) # show experiment info info.show_exp_info(cfg, experiment, folder, executed_runs + 1, missing_runs, total_runs) # Execute the measurement exp_cpy = experiment.copy() (executed, status, etime) = execute_isolated(cfg, exp_cpy, folder, options.show_output) if executed: info.print_run(actual_runs, status, etime) executed_runs += 1 else:
def visit_cmd_experiments(cfg, experiments, cmd): for experiment in experiments: folder = core.get_folder(cfg, experiment) if os.path.exists(folder): print "Executing \"%s\" in %s" % (cmd, folder) visit_cmd_experiment(folder, cmd)
def update(cfg): ''' updates dimensions when a change in the definition of dimensions is detected ''' saved_meta_data = read_meta(cfg) if saved_meta_data is not None: cfg.optspace.keys().sort() additional_dimensions = list_difference( cfg.optspace.keys(), saved_meta_data.optspace.keys()) removed_dimensions = list_difference(saved_meta_data.optspace.keys(), cfg.optspace.keys()) if len(additional_dimensions) > 0 or len(removed_dimensions) > 0: add_default_values = {} if len(additional_dimensions) > 0: # an additional dimension is detected print 'the following dimensions are detected to be added:', \ str(additional_dimensions) old_experiments = core.get_experiments(saved_meta_data) add_default_values = \ read_default(cfg, additional_dimensions, 'default value for newly detected dimension') rem_default_values = {} if len(removed_dimensions) > 0: # a dimension removal is detected print 'the following dimensions are detected to be removed:', \ str(removed_dimensions) old_experiments = core.get_experiments(saved_meta_data) rem_default_values = \ read_default(saved_meta_data, removed_dimensions, 'default value for removed dimension') exp_to_clean = [] old_experiments = core.get_experiments(saved_meta_data) for old_experiment in old_experiments: old_name = core.get_folder(saved_meta_data, old_experiment) new_experiment = old_experiment.copy() # delete dimensions for rem_dim in removed_dimensions: del (new_experiment[rem_dim]) if should_del_exp(old_experiment, rem_default_values): exp_to_clean.append(old_experiment) continue # add dimensions new_experiment.update(add_default_values) new_name = core.get_folder(cfg, new_experiment) os.rename(old_name, new_name) clean.clean_experiments(saved_meta_data, exp_to_clean) MetaData(cfg).save(core.get_raw_folder(cfg))
def main(cargs): # folder from where dude is called cfolder = os.getcwd() # parse command line (options, cargs) = parser.parse_args(cargs) # check if a command has been given if cargs == []: parser.print_help() sys.exit() # create requires no Dudefile, so we deal with it right here if cargs[0] == "create": if len(cargs) < 2: expgen.create() else: expgen.create(cargs[1]) sys.exit(0) # all other commands require a Dudefile, so we first load it (in "cfg") cfg = None # use a given dudefile in options if options.expfile != None: try: cfg = imp.load_source('', options.expfile) except IOError: print >> sys.stderr, 'ERROR: Loading', options.expfile, 'failed' parser.print_help() sys.exit(1) else: # try default file names current = os.getcwd() max_folder = 10 # arbitrary number of parent directories i = 0 while i < max_folder: for f in ['desc.py', 'dudefile', 'Dudefile', 'dudefile.py']: try: if os.path.exists(f) and i > 0: print "Opening Dudefile: ", os.path.abspath(f) cfg = imp.load_source('', f) break except IOError: pass if cfg != None: break else: i += 1 parent, last = os.path.split(current) os.chdir(parent) current = parent if cfg == None: print >> sys.stderr, 'ERROR: no dudefile found' parser.print_help() sys.exit(1) # add to actual folder as root in cfg cfg.root = os.getcwd() # check if cfg can be used for core functions core.check_cfg(cfg) # check if cfg can be used for summaries summary.check_cfg(cfg) # parse arguments to module if options.margs: margs = args.parse(";".join(options.margs)) print "Passing arguments:", margs args.set_args(cfg, margs) if hasattr(cfg, 'dude_version') and cfg.dude_version >= 3: dimensions.update(cfg) # collect filters filters = [] if options.filter and options.filter != []: for fi in options.filter: for f in fi.split(','): filters.append(cfg.filters[f]) if options.filter_inline and options.filter_inline != []: filters += filt.create_inline_filter(cfg, options.filter_inline) if options.filter_path: current = os.getcwd() if current != cfolder: # this assumes Dudefile is in the root of the experiment folder os.chdir(cfolder) path = os.path.abspath(options.filter_path) os.chdir(current) path = os.path.relpath(path) # get raw_output_dir/exp_... format else: path = options.filter_path filters += filt.filter_path(cfg, path) # get experiments experiments = core.get_experiments(cfg) # select the set of experiments to be considered (successful, # failed or pending) if (options.success and options.failed and options.pending) or\ not (options.success or options.failed or options.pending): pass else: failed, pending = core.get_failed_pending_exp(cfg, experiments) expin = [] expout = [] if options.failed: expin += failed else: expout += failed if options.pending: expin += pending else: expout += pending if options.success: experiments = [exp for exp in experiments if exp not in expout] else: experiments = expin # apply filters if filters != []: experiments = filt.filter_experiments(cfg, filters, options.invert, False, experiments) cmd = cargs[0] if cmd == 'run': if options.force: clean.clean_experiments(cfg, experiments) execute.run(cfg, experiments, options) elif cmd == 'run-once': assert len(experiments) == 1 optpt = experiments[0] folder = "once" utils.checkFolder(folder) # create if necessary if options.force: clean.clean_experiment(folder) execute.execute_isolated(cfg, optpt, folder, options.show_output) elif cmd == 'sum': summary.summarize(cfg, experiments, cargs[1:], options.backend, options.ignore_status) elif cmd == 'list': for experiment in experiments: if options.dict: print "experiment:", experiment else: print core.get_folder(cfg, experiment) elif cmd == 'failed': failed = core.get_failed(cfg, experiments, False) for ffile in failed: print ffile elif cmd == 'missing': failed = core.get_failed(cfg, experiments, True) for exp in failed: print exp elif cmd == 'clean': if options.invalid: clean.clean_invalid_experiments(cfg, experiments) else: # TODO if no filter applied, ask if that's really what the # user wants. r = 'y' if options.filter == None and \ options.filter_inline == None: print "sure to wanna delete everything? [y/N]" r = utils.getch() #raw_input("Skip, quit, or continue? #[s/q/c]") if r == 'y': clean.clean_experiments(cfg, experiments) elif cmd == 'visit': if len(cargs) < 2: print "Specify a bash command after visit" sys.exit(1) elif len(cargs) > 2: print "Surround multi-term bash commands with \"\"." print "e.g., \"%s\"" % ' '.join(cargs[1:]) sys.exit(1) visit.visit_cmd_experiments(cfg, experiments, cargs[1]) elif cmd == 'info': info.show_info(cfg, experiments) elif cmd == 'status': info.print_status(cfg, experiments) else: print >> sys.stderr, "ERROR: wrong command. %s" % cargs[0] parser.print_help()
def foo(optpt, outf): if core.get_folder(cfg, optpt) == path: return True else: return False
def clean_experiments(cfg, experiments): for experiment in experiments: folder = core.get_folder(cfg, experiment) print "Cleaning", folder if os.path.exists(folder): shutil.rmtree(folder)