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())
Exemple #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())
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")
 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)