Ejemplo n.º 1
0
 def test_find_or_create(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     self.assertEqual(ps.id, 0)
     self.assertEqual(ps.params, (0, 1, 2, 3))
     self.assertEqual(len(ParameterSet.all()), 1)
     ps2 = ParameterSet.find_or_create(3, 4, 5, 6)
     self.assertEqual(len(ParameterSet.all()), 2)
Ejemplo n.º 2
0
 def test_all(self):
     ps = ParameterSet.find_or_create((0, 1, 2, 3))
     runs = ps.create_runs_upto(3)
     self.assertEqual(Run.all(), runs)
     ps2 = ParameterSet.find_or_create((0, 1, 2, 4))
     runs2 = ps2.create_runs_upto(3)
     self.assertEqual(len(Run.all()), 6)
Ejemplo n.º 3
0
 def test_create_runs(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     runs = ps.create_runs_upto(3)
     self.assertEqual([r.id for r in runs], [0, 1, 2])
     self.assertEqual([r.seed for r in runs], [0, 1, 2])
     ps2 = ParameterSet.find_or_create(0, 1, 3, 4)
     runs = ps2.create_runs_upto(3)
     self.assertEqual([r.id for r in runs], [3, 4, 5])
     self.assertEqual([r.seed for r in runs], [0, 1, 2])
Ejemplo n.º 4
0
 def test_average_results(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     runs = ps.create_runs_upto(3)
     self.assertEqual(ps.average_results(), ())
     for (i, r) in enumerate(runs):
         r.store_result([1.0 + i, 2.0 + i, 3.0 + 1], 0, 3, 111, 222)
     self.assertEqual(ps.average_results(), (2.0, 3.0, 4.0))
Ejemplo n.º 5
0
 def test_is_finished(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     self.assertEqual(ps.is_finished(), True)
     runs = ps.create_runs_upto(1)
     self.assertFalse(ps.is_finished())
     self.assertEqual(len(ps.finished_runs()), 0)
     runs[0].store_result([1.0, 2.0, 3.0], 0, 3, 111, 222)
     self.assertTrue(ps.is_finished())
     self.assertEqual(len(ps.finished_runs()), 1)
    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())
Ejemplo n.º 7
0
 def test_find(self):
     ps = ParameterSet.find_or_create((0, 1, 2, 3))
     runs = ps.create_runs_upto(3)
     rid = runs[1].id
     self.assertEqual(rid, 1)
     self.assertEqual(Run.find(rid), runs[1])
Ejemplo n.º 8
0
 def test_find(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     ps2 = ParameterSet.find_or_create(0, 1, 2, 4)
     pid = ps2.id
     self.assertEqual(pid, 1)
     self.assertEqual(ParameterSet.find(1), ps2)
Ejemplo n.º 9
0
 def test_all(self):
     ps = ParameterSet.find_or_create(0, 1, 2, 3)
     self.assertEqual(ParameterSet.all(), [ps])
     ps2 = ParameterSet.find_or_create(0, 1, 2, 4)
     self.assertEqual(ParameterSet.all(), [ps, ps2])
     self.assertEqual(len(ParameterSet.all()), 2)
Ejemplo n.º 10
0
 def test_find_or_create(self):
     ps1 = ParameterSet.find_or_create(0, 1, 2, 3)
     ps2 = ParameterSet.find_or_create(0, 1, 2, 3)
     self.assertEqual(ps1, ps2)
     self.assertEqual(len(ParameterSet.all()), 1)