Ejemplo n.º 1
0
    def test_ps(self):
        param = {"p1": 1, "p2": 2}
        ps = self.sim.find_or_create_parameter_set(param)
        self.assertEqual(ps.id(), 0)
        self.assertEqual(ps.v(), param)
        self.assertEqual(ps.runs(), [])
        self.assertEqual(ps.simulator(), self.sim)
        self.assertEqual(ParameterSet.all(), [ps])
        self.assertEqual(ParameterSet.find(0), ps)
        self.assertEqual(self.sim.find_parameter_set(param), ps)
        self.assertEqual(ps.to_dict(), {
            "id": 0,
            "sim_id": 0,
            "params": param,
            "run_ids": []
        })

        # second PS
        param2 = {"p1": 2, "p2": 3}
        ps2 = self.sim.find_or_create_parameter_set(param2)
        self.assertEqual(ps2.id(), 1)
        self.assertEqual(ps2.v(), param2)
        self.assertEqual(ParameterSet.all(), [ps, ps2])

        # duplicate PS
        self.assertEqual(self.sim.find_or_create_parameter_set(param), ps)
        self.assertEqual(len(ParameterSet.all()), 2)
Ejemplo n.º 2
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.º 3
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())
Ejemplo n.º 4
0
 def test_find(self):
     sim2 = Simulator.create("echo")
     self.assertEqual(sim2.id(), 1)
     ps1 = self.sim.find_or_create_parameter_set({"foo": "bar"})
     self.assertEqual(self.sim.parameter_sets(), [ps1])
     ps1.create_runs_upto(2)
     ps2 = sim2.find_or_create_parameter_set({"foo": "bar"})
     self.assertEqual(sim2.parameter_sets(), [ps2])
     ps2.create_runs_upto(2)
     self.assertEqual([r.id() for r in ps1.runs()], [0, 1])
     self.assertEqual([r.id() for r in ps2.runs()], [2, 3])
     self.assertEqual([r.id() for r in ParameterSet.all()], [0, 1])
     self.assertEqual(ParameterSet.find(1), ps2)
Ejemplo n.º 5
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.º 6
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)