示例#1
0
    def test_add_duplicate(self):
        lineages = Lineages()
        assert len(lineages) == 0
        lineage = lineages.add(TrialStub(id="stub"))
        assert len(lineages) == 1

        new_lineage = lineages.add(TrialStub(id="stub"))
        assert new_lineage is lineage
        assert len(lineages) == 1
示例#2
0
    def test_set_jump_existing_trial(self):
        lineages = Lineages()
        root_1 = TrialStub(id="root-1")
        lineage_1 = lineages.add(root_1)
        root_2 = TrialStub(id="root-2")
        lineage_2 = lineages.add(root_2)
        child_trial = TrialStub(id="child")
        child_lineage = lineages.fork(root_1, child_trial)
        lineages.set_jump(root_2, child_trial)

        assert child_lineage.base is lineage_2
        assert lineage_2.jumps == [child_lineage]
        assert child_lineage.jumps == []
        assert lineage_2.base is None
        assert lineage_1.jumps == []
        assert lineage_1.base is None
示例#3
0
 def test_add_new_trial(self):
     lineages = Lineages()
     assert len(lineages) == 0
     lineage = lineages.add(TrialStub(id="stub"))
     assert len(lineages) == 1
     assert lineages._lineage_roots[0] is lineage
     assert lineages._trial_to_lineages["stub"] is lineage
示例#4
0
    def test_register_existing_trial(self):
        lineages = Lineages()
        trial = TrialStub(id="my-id")
        lineage = lineages.add(trial)
        assert lineages._lineage_roots == [lineage]
        assert lineage.item.objective is None

        trial.objective = ObjectiveStub(1)
        assert lineages.register(trial) is lineage
        assert lineages._lineage_roots == [lineage]
        assert lineage.item.objective.value == 1
示例#5
0
 def test_fork_existing_trial(self, tmp_path):
     lineages = Lineages()
     trial = TrialStub(id="stub", working_dir=os.path.join(tmp_path, "stub"))
     os.makedirs(trial.working_dir)
     lineage = lineages.add(trial)
     assert len(lineages) == 1
     new_trial = TrialStub(id="fork", working_dir=os.path.join(tmp_path, "fork"))
     new_lineage = lineages.fork(trial, new_trial)
     assert len(lineages) == 1
     assert lineages._lineage_roots[0].children[0] is new_lineage
     assert lineages._trial_to_lineages["fork"] is new_lineage
示例#6
0
    def test_get_lineage_existing_node_trial(self):
        lineages = Lineages()
        for root_index in range(2):

            trial = TrialStub(id=f"lineage-{root_index}-0")
            lineage = lineages.add(trial)
            for depth in range(1, 10):
                new_trial = TrialStub(id=f"lineage-{root_index}-{depth}")
                lineage = lineages.fork(trial, new_trial)
                trial = new_trial

        lineage = lineages.get_lineage(TrialStub(id="lineage-0-2"))
        assert lineage.root is lineages._lineage_roots[0]
        assert lineage.node_depth == 2

        lineage = lineages.get_lineage(TrialStub(id="lineage-1-5"))
        assert lineage.root is lineages._lineage_roots[1]
        assert lineage.node_depth == 5
示例#7
0
 def test_get_elites_none_completed(self):
     lineages = Lineages()
     lineages.add(TrialStub(id="1"))
     lineages.add(TrialStub(id="2"))
     lineages.add(TrialStub(id="3"))
     assert lineages.get_elites() == []
示例#8
0
 def test_set_jump_non_existing_new_trial(self):
     lineages = Lineages()
     trial = TrialStub(id="exists")
     lineages.add(trial)
     with pytest.raises(KeyError, match="'newtrialdontexist'"):
         lineages.set_jump(trial, TrialStub(id="newtrialdontexist"))
示例#9
0
 def test_get_lineage_existing_root_trial(self):
     lineages = Lineages()
     trial = TrialStub(id="stub")
     lineage = lineages.add(trial)
     assert lineages.get_lineage(trial) is lineage