def run_hyper_config(hyper_config, hypersearch_config, num_trials): hyper_dir = hyper_config['output_params'][ 'results_dir'] + hyper_config['trial_name'] + '/' if not os.path.exists(hyper_dir): os.makedirs(hyper_dir) hyper_json = json.dumps(hyper_config, indent=4) f = open(hyper_dir + 'hyperpoint.json', 'w') f.write(hyper_json) f.close() for trial in range(num_trials): print('> trial_', str(trial)) p = subprocess.Popen([ 'python', 'run_trial.py', 'train', json.dumps(hyper_config), str(trial) ]) utils.log_process( p, hypersearch_config['output_params']['hyper_dir'] + 'process_log.txt') p.communicate()
def check_hyperpoints(hypersearch_config, hyper_configs): hyperpass = True count = 0 print('Testing...') train_ds_path = hypersearch_config['dataset_params']['train_ds_path'] for hyper_config in hyper_configs: count += 1 print('\rTesting ' + str(count) + '/' + str(len(hyper_configs)) + ': ' + hyper_config['trial_name'], end='') p = subprocess.Popen([ 'python', 'run_trial.py', 'check', json.dumps(hyper_config), train_ds_path ]) utils.log_process( p, hypersearch_config['output_params']['hyper_dir'] + 'process_log.txt') p.communicate() return_code = p.returncode hyperpass = hyperpass and return_code == 0 return hyperpass
def copydir(src, dst): try: shutil.copytree(src, dst) except OSError as exc: pass json_file = sys.argv[1] if len(sys.argv) == 3: os.chdir(os.path.dirname(os.path.abspath(__file__))) print(os.getcwd()) import helpers hypersearcher = helpers.HyperSearcher() hypersearcher.run_hypersearch(json_file) elif len(sys.argv) == 2: with open(json_file) as json_data: hyperconfig = json.load(json_data) script_dir = os.path.realpath('') + '/' script_copy_dir = hyperconfig['output_params']['hyper_dir'] + 'code/' copydir(script_dir, script_copy_dir) p1 = subprocess.Popen(['python', 'mibi_pickle.py', json_file]) p1.communicate() utils.log_process(p1, hyperconfig['output_params']['hyper_dir'] + 'process_log.txt') p2 = subprocess.Popen(['python', script_copy_dir + 'hypersearch.py', json_file, 'copy']) p2.communicate() utils.log_process(p2, hyperconfig['output_params']['hyper_dir'] + 'process_log.txt') else: print('Incorrect number of arguments passed')