def test_parse_dispatcher_config(self): raw_strings = [ # true flag ({ 'true_flag': [True] }, [" --true_flag"]), # flase flag ({ 'false_flag': [False] }, [""]), # flase flag followed by true flag ({ 'false_flag': [False], 'true_flag': [True] }, [" --true_flag"]), # Different options ({ 'flag': ["opt1", "opt2"] }, [" --flag opt1", " --flag opt2"]), # val ({ "val_flag": [5] }, [" --val_flag 5"]), # list of vals ({ "list_flag": [['t1/a=v', 't2/b=w']] }, [" --list_flag t1/a=v t2/b=w"]) ] for config, expected in raw_strings: wrapped_config = {"search_space": config} output, _ = parsing.parse_dispatcher_config(wrapped_config) self.assertCountEqual(output, expected)
def test_experimental_axies(self): raw_strings = [ ({ 'experimented_flag': [True, False], 'const_flag': [False] }, "experimented_flag"), ] for config, expected in raw_strings: wrapped_config = {"search_space": config} _, output = parsing.parse_dispatcher_config(wrapped_config) self.assertEqual(output[0], expected)
def test_invalid_config(self): raw_strings = [ ({ 'flag1': [True, False], 'flag2': [] }, 'flag2'), ({ 'flag1': [] }, 'flag1'), ({ 'flag1': [True], 'flag2': "value", }, 'flag2'), ] for config, flag in raw_strings: wrapped_config = {"search_space": config} with self.assertRaises(Exception) as context: parsing.parse_dispatcher_config(wrapped_config) self.assertTrue( self.err_msg.format(flag, config[flag]) in str(context.exception))
if __name__ == "__main__": args = parser.parse_args() if not os.path.exists(args.experiment_config_path): print( CONFIG_NOT_FOUND_MSG.format("experiment", args.experiment_config_path)) sys.exit(1) experiment_config = json.load(open(args.experiment_config_path, 'r')) if 'results_path' in experiment_config['search_space']: print(RESULTS_PATH_APPEAR_ERR) sys.exit(1) job_list, experiment_axies = parsing.parse_dispatcher_config( experiment_config) job_queue = multiprocessing.Queue() done_queue = multiprocessing.Queue() for job in job_list: job_queue.put(job) print("Launching Dispatcher with {} jobs!".format(len(job_list))) print() for gpu in experiment_config['available_gpus']: print("Start gpu worker {}".format(gpu)) multiprocessing.Process(target=worker, args=(gpu, job_queue, done_queue)).start() print() summary = [] result_keys = []