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())
示例#2
0
    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())
示例#3
0
 def setUp(self):
     self.t = Tables.get()
     self.t.clear()
示例#4
0
if len(sys.argv) != 5 and len(sys.argv) != 6:
    sys.stderr.write(str(sys.argv))
    sys.stderr.write("invalid number of argument\n")
    args = ["num_jobs", "alpha", "min", "max", "[num_stub_cpus]"]
    sys.stderr.write("Usage: python %s %s\n" % (__file__, " ".join(args)))
    raise RuntimeError("invalid number of arguments")

if len(sys.argv) == 5:
    with Server.start():
        se = PowerLawSleep(int(sys.argv[1]), float(sys.argv[2]),
                           float(sys.argv[3]), float(sys.argv[4]))
        se.create_initial_runs()
else:
    from caravan.server_stub import start_stub

    def stub_sim(t):
        t = float(t.command.split()[1])
        results = (1.0, )
        return results, t

    with start_stub(stub_sim, num_proc=int(sys.argv[5])):
        se = PowerLawSleep(int(sys.argv[1]), float(sys.argv[2]),
                           float(sys.argv[3]), float(sys.argv[4]))
        se.create_initial_runs()

if all([t.is_finished() for t in Task.all()]):
    sys.stderr.write("DONE\n")
else:
    Tables.dump("table.pickle")
示例#5
0
 def setUp(self):
     self.t = Tables.get()
     self.t.clear()
     self.sim = Simulator.create("echo")
示例#6
0
    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")
示例#7
0
 def setUp(self):
     self.t = Tables.get()
     self.t.clear()
     self.sim = Simulator.create("~/my_simulator")
     self.ps = self.sim.find_or_create_parameter_set({"p1": 1})
 def setUp(self):
     self.t = Tables.get()
     self.t.clear()
     self.dump_path = "test.pkl"
     self._clean()
 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)