def test_dump(self): ps = ParameterSet.find_or_create((0, 1, 2, 3)) runs = ps.create_runs_upto(3) runs[0].store_result([1.0, 2.0, 3.0], 0, 3, 111, 222) ps = ParameterSet.find_or_create((4, 5, 6, 7)) self.assertEqual(len(self.t.ps_table), 2) runs = ps.create_runs_upto(3) runs[2].store_result([1.0, 2.0, 3.0], 0, 3, 111, 222) self.assertEqual(len(self.t.tasks_table), 6) path = self.dump_path Tables.dump(path) self.assertTrue(os.path.exists(path)) self.t.clear() Tables.load(path) self.t = Tables.get() self.assertEqual(len(self.t.ps_table), 2) self.assertEqual(len(self.t.tasks_table), 6) self.assertTrue(self.t.tasks_table[0].is_finished()) self.assertTrue(self.t.tasks_table[5].is_finished())
def test_dump(self): sim = Simulator.create("~/my_simulator") ps = sim.find_or_create_parameter_set({"p1": 0, "p2": 1}) runs = ps.create_runs_upto(3) runs[0]._store_result([1.0, 2.0, 3.0], 0, 3, 111, 222) ps2 = sim.find_or_create_parameter_set({"p1": 2, "p2": 3}) self.assertEqual(len(ParameterSet.all()), 2) runs = ps2.create_runs_upto(3) runs[2]._store_result([1.0, 2.0, 3.0], 0, 3, 111, 222) self.assertEqual(len(self.t.tasks_table), 6) path = self.dump_path Tables.dump(path) self.assertTrue(os.path.exists(path)) self.t.clear() Tables.load(path) self.t = Tables.get() self.assertEqual(len(ParameterSet.all()), 2) self.assertEqual(len(Task.all()), 6) self.assertTrue(Task.find(0).is_finished()) self.assertTrue(Task.find(5).is_finished())
args = [ "num_static_jobs", "num_dynamic_jobs", "job_gen_prob", "num_jobs_per_gen", "sleep_mu", "sleep_sigma", "[table.pickle]" ] sys.stderr.write("Usage: python %s %s\n" % (__file__, " ".join(args))) raise RuntimeError("invalid number of arguments") num_static_jobs = int(sys.argv[1]) num_dynamic_jobs = int(sys.argv[2]) job_gen_prob = float(sys.argv[3]) num_jobs_per_gen = int(sys.argv[4]) sleep_mu = float(sys.argv[5]) sleep_sigma = float(sys.argv[6]) with Server.start(): se = BenchSearcher(num_static_jobs, num_dynamic_jobs, job_gen_prob, num_jobs_per_gen, sleep_mu, sleep_sigma) if len(sys.argv) == 7: print("starting") se.create_initial_runs() else: print("restarting") Tables.load(sys.argv[7]) se.restart() if all([t.is_finished() for t in Task.all()]): print("DONE\n") else: print("There are unfinished tasks. Writing data to table.pickle\n") Tables.dump("table.pickle")
def test_dump_empty(self): path = self.dump_path Tables.dump(path) self.assertTrue(os.path.exists(path)) Tables.load(path) self.assertEqual(len(self.t.ps_table), 0)