def main(unused): ## change config = BasicConfig().load(unused[1]) config.to_flags(FLAGS) ## val = rosenbrock(FLAGS.x, FLAGS.y) print_result(val)
def test_init(self): data = BasicConfig(**self.d) self.assertDictEqual(data, self.d) data = BasicConfig(a=1) self.assertDictEqual(data, self.d) self.assertRaises(ValueError, data.load, "wrong.data")
class CPUResourceManagerTestCase(unittest.TestCase): n_parallel = 1 auppath = os.path.join("tests", "data", ".aup") job = Job("test_Job.py", BasicConfig(), "./tests/EE") job_fail = Job("task1.py", BasicConfig(), "./tests/data") job_fail2 = Job("task2.py", BasicConfig(), "./tests/data") job_fail3 = Job("task3.py", BasicConfig(), "./tests/data") ori_db = os.path.join(auppath, "sqlite3.db") bk_db = os.path.join(auppath, "bk.db") val = 0 def setUp(self): copyfile(self.ori_db, self.bk_db) self.connector = get_default_connector(self.auppath) self.rm = CPUResourceManager(self.connector, self.n_parallel) def tearDown(self): copyfile(self.bk_db, self.ori_db) os.remove(self.bk_db) def test_get_resource(self): self.assertIsInstance(self.rm.get_available("test", "cpu"), int) # !IMPORTANT - currently, there is no user authentication. self.assertIsInstance(self.rm.get_available("test2", "cpu"), int) def test_run(self): def callback(*args): self.val = -1 self.rm.run(self.job, self.rm.get_available("test", "cpu"), {}, callback) self.rm.executor.shutdown(wait=True) self.assertEqual(self.val, -1) def test_fail_run(self): def callback(*args): raise ChildProcessError self.rm.run(self.job_fail, self.rm.get_available("test", "cpu"), {}, callback) self.rm.run(self.job_fail2, self.rm.get_available("test", "cpu"), {}, callback) self.rm.run(self.job_fail3, self.rm.get_available("test", "cpu"), {}, callback) def test_full_run(self): def callback(*args): pass self.rm.run_job(self.job, self.rm.get_available("test", "cpu"), {}, callback) self.rm.finish_job(self.job.jid, 2.0) self.rm.executor.shutdown(wait=True) self.assertListEqual([1, 0.1], self.rm.finish(1)) def test_finish(self): self.rm.suspend() self.assertListEqual([1, 0.1], self.rm.finish(1))
def test_pkl(self): data = BasicConfig() data.load(self.pkl_read) self.assertDictEqual(self.d, data) data["b"] = 2 data.c = 3 data.save(self.pkl_write) data = BasicConfig().load(self.pkl_write) self.assertEqual(data.b, 2) self.assertEqual(data["c"], 3)
class GPUResourceManagerTestCase(unittest.TestCase): n_parallel = 1 auppath = os.path.join("tests", "data", ".aup") connector = get_default_connector(auppath) val = 0 ori_db = os.path.join(auppath, "sqlite3.db") bk_db = os.path.join(auppath, "bk.db") job = Job("test_Job.py", BasicConfig(), "./tests/EE") def setUp(self): copyfile(self.ori_db, self.bk_db) self.connector = get_default_connector(self.auppath) self.rm = GPUResourceManager(self.connector, self.n_parallel, auppath=self.auppath) def tearDown(self): copyfile(self.bk_db, self.ori_db) os.remove(self.bk_db) def test_run(self): def callback(*args): self.val = -1 self.rm.run(self.job, self.rm.get_available("test", "gpu"), {}, callback) sleep(3) # wait till subprocess finished - handled by rm.finish() self.assertEqual(self.val, -1)
def test_run_through(self): exp = Experiment(BasicConfig().load(self.path), username="******", auppath=self.auppath) exp.start() exp.finish() self.assertDictEqual(exp.pending_jobs, {})
def test_job_retries(self): exp = Experiment(BasicConfig().load( os.path.join("tests", "data", "exp6.json")), username="******", auppath=os.path.join("tests", "data", ".aup")) exp.start() jid, val = exp.finish() self.assertDictEqual(exp.pending_jobs, {}) self.assertEqual(jid, 10)
class PassiveRMTestCase(unittest.TestCase): auppath = os.path.join("tests", "data", ".aup") job = Job("task1.py", BasicConfig(), "./tests/EE") ori_db = os.path.join(auppath, "sqlite3.db") bk_db = os.path.join(auppath, "bk.db") val = 0 def setUp(self): copyfile(self.ori_db, self.bk_db) self.connector = get_default_connector(self.auppath) self.rm = PassiveResourceManager(self.connector) def tearDown(self): copyfile(self.bk_db, self.ori_db) os.remove(self.bk_db) def test_get_available(self): self.assertEqual(10, self.rm.get_available("test", "passive")) self.connector.take_available_resource(10) self.assertEqual(None, self.rm.get_available("test", "passive")) self.rm.running = True self.assertEqual(None, self.rm.get_available("test", "passive"))
#!/usr/bin/env python3 """ Job will fail when sleep time is 1 ============================================ .. Copyright (c) 2018 LG Electronics Inc. SPDX-License-Identifier: GPL-3.0-or-later """ import sys from time import sleep from aup import BasicConfig, print_result if __name__ == "__main__": if len(sys.argv) != 2: print("config file required") exit(1) config = BasicConfig().load(sys.argv[1]) sleep(1 + config.time / 10.) if config.time == 3: exit(1) print_result(config.time)
def test_ssh_session(self): pkey = pkg_resources.resource_filename("mockssh", 'server-key') data_folder = pkg_resources.resource_filename(__name__, 'data') users = { "mockuser": pkey, } scores = {} mutex = Lock() config = { 'workingdir': data_folder, 'n_parallel': 2, 'resource': 'node', 'proposer': 'random', 'script': os.path.join(data_folder, "script", "rosenbrock_hpo.py"), 'n_samples': 10, 'random_seed': 10, 'parameter_config': [{ 'name': 'x', 'type': 'float', 'range': [-5, 5] }, { 'name': 'y', 'type': 'float', 'range': [-5, 5] }], "runtime_args": { "prescript": "export CUDA_VISIBLE_DEVICES=-1", "postscript": "echo $CUDA_VISIBLE_DEVICES", "overwrite": 'true' } } m = rp.RandomProposer(config) def callback_fun(score, jid): mutex.acquire() scores[jid] = score mutex.release() with mockssh.Server(users) as server1, mockssh.Server( users) as server2: mngr = SSHResourceManager(None, config['n_parallel'], auppath=data_folder, reconn_wait_time=3, max_retries=3) mngr.mapping[1] = "[email protected]:" + str( server1.port) + " " + pkey mngr.mapping[2] = "[email protected]:" + str( server2.port) + " " + pkey for i in range(0, config['n_samples'], 2): proposal = m.get() job1 = Job(config['script'], BasicConfig(**proposal), config['workingdir']) job1.jid = i mngr.run(job1, 1, None, callback_fun, overwrite=True) proposal = m.get() job2 = Job(config['script'], BasicConfig(**proposal), config['workingdir']) job2.jid = i + 1 mngr.run(job2, 2, None, callback_fun, overwrite=True) mngr.executor.shutdown(wait=True) for key in scores: self.assertTrue(scores[key] != "ERROR")
print("config file required") exit(1) parser = argparse.ArgumentParser() parser.add_argument('--dropout', type=float, default=0.2, help='drop probability for training dropout.') parser.add_argument('--textlstm', type=int, default=256, help='text LSTM layer size.') parser.add_argument('--speechlstm', type=int, default=128, help='speech layer size.') parser.add_argument('--finalfc', type=int, default=256, help='final FC layer size.') parser.add_argument('--adamlr', type=float, default=0.001, help='adam lr') FLAGS, unparsed = parser.parse_known_args() config = BasicConfig(**FLAGS.__dict__).load(sys.argv[1]) FLAGS.__dict__.update(config) val = train() print(str(val)) print_result(val)
def main(): print("Starting Client") config = BasicConfig().load(sys.argv[1]) run(config["expdir"])
def test_hash(self): a = {"a": 1} b = BasicConfig(a=1) self.assertDictEqual(a, b)
def test_type(self): data = BasicConfig() self.assertRaises(TypeError, data.load, self.wrong_read)
def test_compare(self): data = BasicConfig(**self.d) self.assertTrue(data == self.d)
def test_access(self): data = BasicConfig(**self.d) del data.a self.assertFalse('a' in data)