def git_init(): # init repo try: check_output(['git', 'init']) except CalledProcessError as err: error("Error executing 'git init'. Error message:") print(err.output) raise SystemExit # add conf try: check_output(['git', 'add', 'abed_conf.py']) except CalledProcessError as err: error("Error executing 'git add abed_conf.py'. Error message:") print(err.output) raise SystemExit try: check_output(['git', 'add', 'abed_tasks.txt']) except CalledProcessError as err: error("Error executing 'git add abed_tasks.txt'. Error message:") print(err.output) raise SystemExit try: check_output(['git', 'add', 'abed_auto.txt']) except CalledProcessError as err: error("Error executing 'git add abed_auto.txt'. Error message:") print(err.output) raise SystemExit try: check_output(['git', 'commit', '-am', '"initialized abed skeleton"']) except CalledProcessError as err: error("Error executing initial commit. Error message:") print(err.output) raise SystemExit
def run(self): # this takes over master/worker if self.task_dict is None: error("No tasks defined before attempted run. Exiting") raise SystemExit mpi_start(self.task_dict) info("Finished with run command.")
def local(self): if self.task_dict is None: error("No tasks defined before attempted run. Exiting") raise SystemExit copy_local_files() mpi_start(self.task_dict, local=True) info("Finished with run command.")
def __getattr__(self, attr): if self.__dict__.has_key(attr): return getattr(self, attr) else: error("You probably Britta'd the settings file, " "I'm missing parameter %s" % attr) raise SystemExit
def git_add_auto(): try: check_output(['git', 'add', settings.AUTO_FILE]) except CalledProcessError as err: error("Error executing 'git add %s'. Error message:" % settings.AUTO_FILE) print(err.output) raise SystemExit
def git_ok(): try: check_output(['git', 'diff', '--exit-code']) except CalledProcessError as err: if err.returncode == 1: return False error("Error performing 'git diff --exit-code'. Error message:") print(err.output) raise SystemExit return True
def git_commit_auto(): try: check_output([ 'git', 'commit', '-m', 'automatic commit of auto log file', settings.AUTO_FILE ]) except CalledProcessError as err: error("Error performing autocommit for auto log file. Error message:") print(err.output) raise SystemExit info("Automatic auto log file commit")
def git_commit_tbd(): try: check_output([ 'git', 'commit', '-m', 'automatic commit of TBD task file', settings.TASK_FILE ]) except CalledProcessError as err: error("Error performing autocommit for TBD file. Error message:") print(err.output) raise SystemExit info("Automatic TBD file commit")
def _unpack_zip(zipfile, all_tasks): fpath = '%s%s%s' % (settings.ZIP_DIR, os.sep, zipfile) try: b = bz2file.BZ2File(fpath) tar = tarfile.open(fileobj=b) except tarfile.ReadError: error("Could not read tarfile: %s" % fpath) return mkdir(settings.STAGE_DIR) tar.extractall(settings.STAGE_DIR) tar.close() move_results(all_tasks) ziplog = settings.ZIP_DIR + os.sep + 'abed_unzipped.txt' with open(ziplog, 'a') as fid: fid.write(zipfile + '\n')
def reference_difference(table): """ Runs Holm's procedure for a reference classifier. """ # Sanity checks if settings.REFERENCE_METHOD is None: return None if (not table.is_summary) or (table.type != AbedTableTypes.RANKS): return None if not settings.REFERENCE_METHOD in settings.METHODS: error("Reference method %s not in list of methods." % settings.REFERENCE_METHOD) raise SystemExit # define constants N = float(len(settings.DATASETS)) k = float(len(settings.METHODS)) av_ranks = next((row for _id, row in table if _id == 'Average'), None) av_ranks = [float(x) for x in av_ranks] ref_idx = settings.METHODS.index(settings.REFERENCE_METHOD) others = [m for m in settings.METHODS if not m == settings.REFERENCE_METHOD] # Calculate the Z-scores compared to the reference method Z_scores = [0] * len(others) P_values = [0] * len(others) constant = sqrt((6.0*N)/(k*(k+1.0))) for j, method in enumerate(others): i = settings.METHODS.index(method) Z_scores[j] = (av_ranks[ref_idx] - av_ranks[i])*constant P_values[j] = norm_dist.cdf(Z_scores[j]) # Sort the p-values in ascending order sorted_pvals = sorted((p, i) for i, p in enumerate(P_values)) # Calculate significant differences following Holm's procedure significant_differences = [False]*len(others) CD_threshold = None for i in range(int(k-1)): threshold = settings.SIGNIFICANCE_LEVEL/float(k - (i+1)) pval, idx = sorted_pvals[i] significant_differences[idx] = pval < threshold if pval > threshold and CD_threshold is None: CD_threshold = threshold CD = -1*norm_dist.ppf(CD_threshold) / constant out = list(zip(others, Z_scores, P_values, significant_differences)) return out, CD
def dataset_completed(dsetfiles, dset, task_dict): if settings.TYPE == 'ASSESS': dset_tasks = { k: v for k, v in task_dict.iteritems() if v['dataset'] == dset } elif settings.TYPE == 'CV_TT': dset_tasks = { k: v for k, v in task_dict.iteritems() if (v['train_dataset'] == dset[0] and v['test_dataset'] == dset[1]) } else: error("Compressing data not supported for TYPE = %s" % settings.TYPE) raise SystemExit have_hashes = set([hash_from_filename(f) for f in dsetfiles]) need_hashes = set(dset_tasks.keys()) return have_hashes == need_hashes
def do_work(hsh, task, local=False): datadir = os.path.join(get_scratchdir(local), 'datasets') execdir = os.path.join(get_scratchdir(local), 'execs') if settings.TYPE == 'RAW': cmd = task.format(datadir=datadir, execdir=execdir) else: command = settings.COMMANDS[task['method']] task['datadir'] = datadir task['execdir'] = execdir cmd = command.format(**task) try: info("Executing: '%s'" % cmd, color_wrap=False) output = check_output(cmd, shell=True) except CalledProcessError as err: error("There was an error executing: '%s'. Here is the error: %s" % (cmd, err.output), color_wrap=False) return write_output(output, hsh) info("Finished with %s" % hsh, color_wrap=False)
def copy_worker(local): comm = MPI.COMM_WORLD status = MPI.Status() scratchdir = get_scratchdir(local) curdir = '%s/releases/current' % settings.REMOTE_DIR local_results = '%s/results/' % curdir scratch_results = '%s/results/' % scratchdir copy_task = ("rsync -avm --include='*.*' -f 'hide,! */' %s %s" % (scratch_results, local_results)) while True: if comm.Iprobe(source=0, tag=MPI.ANY_TAG): comm.recv(obj=None, source=0, tag=MPI.ANY_TAG, status=status) if status.Get_tag() == KILLTAG: break try: check_output(copy_task, shell=True) except CalledProcessError: error("There was an error in the copy task", color_wrap=False) time.sleep(settings.MW_COPY_SLEEP)
def main(): args = parse_arguments() skip_init = False if args.cmd == 'reload_tasks': skip_init = True if settings is None: if not args.cmd == 'init': error("No ABED configuration file found in this directory. " "Run 'abed init' to initialize one. Exiting.") raise SystemExit skip_init = True abed = Abed(skip_init=skip_init, skip_cache=args.skip_cache) info("Running abed command: %s" % args.cmd) try: getattr(abed, args.cmd)() except KeyboardInterrupt: info("Exiting.") pass
def compress_dataset(dset): dsetname = dataset_name(dset) dsetpath = os.path.join(settings.RESULT_DIR, dsetname) dsetpath = dsetpath.rstrip(os.sep) if settings.COMPRESSION == 'bzip2': extension = 'bz2' elif settings.COMPRESSION == 'gzip': extension = 'gz' elif settings.COMPRESSION == 'lzma': extension = 'xz' else: error("Unknown compression algorithm specified in " "COMPRESSION configuration. Please check the " "configuration file.") raise SystemExit output_filename = '%s.tar.%s' % (dsetpath, extension) # lzma will be available in tarfile when abed is ported to Python 3. On # posix systems we can try compressing with the tar command. if os.name == 'posix' and settings.COMPRESSION == 'lzma': try: cmd = ('XZ_OPT=-9 tar --directory=%s -Jcf %s %s' % (settings.RESULT_DIR, output_filename, dsetname)) check_output(cmd, stderr=STDOUT, shell=True) except CalledProcessError: error("There was an error executing '%s'.") raise SystemExit elif settings.COMPRESSION == 'lzma': error("lzma compression is not yet available for your platform.") raise SystemExit else: mode = 'w:%s' % extension with tarfile.open(output_filename, mode, compresslevel=9) as tar: tar.add(dsetpath, arcname=os.path.basename(dsetpath))
def init_config(): cur = os.getcwd() files = os.listdir(cur) conf_file = next((x for x in files if x.startswith('abed_conf')), None) if conf_file is None: return None configfile = os.path.realpath(conf_file) config = {} try: exec(open(configfile).read(), config) except NameError as err: error("You probably Britta'd the settings file, " "NameError: %s" % str(err)) except Exception as err: error("You probably Britta'd the settings file, " "an error occured parsing it: %s" % str(err)) keys = list(config.keys()) for key in keys: if not key.upper() == key: del config[key] parse_dirs(config, key) settings = Settings(**config) return settings
def push(self): if not git_ok(): error("Git repository has uncommitted changes, not pushing.") raise SystemExit info("Starting push") fab_push()
def check_size(): if not sys.maxsize == 9223372036854775807: error("Running on a non 64-bit system. This may cause problems with " "hashes.") raise SystemExit