コード例 #1
0
ファイル: test_space.py プロジェクト: bigbigQI/streamlitapp
    def test_is_valid(self):
        x1 = WorkflowListTask(is_ordered=False,
                              name="x1",
                              tasks=["x1__p1", "x1__p2"])
        x2 = WorkflowListTask(is_ordered=True,
                              name="x2",
                              tasks=["x2__p1", "x2__p2", "x2__p3"])

        start = WorkflowChoiceScenario(name="Model", scenarios=[x1, x2])

        sampler = {
            "x1__p1": Parameter("x1__p1", [0, 1], "uniform", "float"),
            "x1__p2": Parameter("x1__p2", [1, 2, 3, 4, 5, 6, 7], "choice",
                                "int"),
            "x2__p1": Parameter("x2__p1", ["a", "b", "c", "d"], "choice",
                                "string"),
            "x2__p2": Parameter("x2__p2", [10, 11, 12], "choice", "int"),
            "x2__p3": Parameter("x2__p3", "lol", "constant", "string"),
        }
        rules = [
            ChildRule(applied_to=["x2__p2"], parent="x2__p1", value=["a"])
        ]

        space = Space(scenario=start, sampler=sampler, rules=rules)
        assert (space.next_params(history=[("Model",
                                            None), ("x2", None), ("x2__p1",
                                                                  "a")])[0]
                in ["x2__p2", "x2__p3"])
        assert (space.has_finite_child(
            history=[("Model", None), ("x2", None), ("x2__p1", "b")])[1] == 0)
        assert (space.has_finite_child(
            history=[("Model", None), ("x2", None), ("x2__p1", "a")])[1] > 0)
コード例 #2
0
ファイル: test_rules.py プロジェクト: bigbigQI/streamlitapp
    def test_value_rules(self):
        x1 = WorkflowListTask(is_ordered=False,
                              name="x1",
                              tasks=["x1__p1", "x1__p2"])
        x2 = WorkflowListTask(is_ordered=True,
                              name="x2",
                              tasks=["x2__p1", "x2__p2"])

        start = WorkflowChoiceScenario(name="Model", scenarios=[x1, x2])

        sampler = {
            "x1__p1": Parameter("x1__p1", [0, 1], "uniform", "float"),
            "x1__p2": Parameter("x1__p2", [1, 2, 3, 4, 5, 6, 7], "choice",
                                "int"),
            "x2__p1": Parameter("x2__p1", ["a", "b", "c", "d"], "choice",
                                "string"),
            "x2__p2": Parameter("x2__p2", [10, 11, 12], "choice", "int")
        }

        rules = [
            ChildRule(applied_to=["x2__p2"], parent="x2__p1", value=["a"]),
            ValueRule(constraints=[("x1__p1", 0.5), ("x1__p2", 7)]),
            ValueRule(constraints=[("x1__p1", 0.9), ("x1__p2", 6)])
        ]

        space = Space(scenario=start, sampler=sampler, rules=rules)
        assert (space.next_params(
            history=[("Model", None), ("x2", None), ("x2__p1",
                                                     "a")])[0] == "x2__p2")
        assert (space.has_finite_child(
            history=[("Model", None), ("x2", None), ("x2__p1", "b")])[1] == 0)
        assert (space.has_finite_child(
            history=[("Model", None), ("x2", None), ("x2__p1", "a")])[1] > 0)

        for i in range(10):
            assert (space.next_params(
                history=[("Model", None), ("x1", None), ("x1__p1", 0.3)]) !=
                    ("x1__p2", 7, True))
            assert (space.next_params(
                history=[("Model", None), ("x1", None), ("x1__p1",
                                                         0.5)]) == ("x1__p2",
                                                                    7, True))
            assert (space.next_params(
                history=[("Model", None), ("x1", None), ("x1__p1", 0.8)]) !=
                    ("x1__p2", 7, True))
            assert (space.next_params(
                history=[("Model", None), ("x1", None), ("x1__p1", 0.9)]) !=
                    ("x1__p2", 7, True))
            assert (space.next_params(
                history=[("Model", None), ("x1", None), ("x1__p1",
                                                         0.9)]) == ("x1__p2",
                                                                    6, True))
コード例 #3
0
ファイル: test_space.py プロジェクト: bigbigQI/streamlitapp
    def test_has_finite_child(self):
        def a_func():
            return 0

        def b_func():
            return 0

        def c_func():
            return 0

        x1 = WorkflowListTask(is_ordered=False,
                              name="x1",
                              tasks=["x1__p1", "x1__p2"])
        x2 = WorkflowListTask(is_ordered=True,
                              name="x2",
                              tasks=["x2__p1", "x2__p2"])

        start = WorkflowChoiceScenario(name="Model", scenarios=[x1, x2])

        sampler = {
            "x1__p1":
            Parameter("x1__p1", [0, 1], "uniform", "float"),
            "x1__p2":
            Parameter("x1__p2", [1, 2, 3, 4, 5, 6, 7], "choice", "int"),
            "x2__p1":
            Parameter("x2__p1", ["a", "b", "c", "d"], "choice", "string"),
            "x2__p2":
            Parameter("x2__p2", [a_func, b_func, c_func], "choice", "func"),
        }

        space = Space(scenario=start, sampler=sampler)

        assert (space.has_finite_child(history=[("Model", None)]) == (False,
                                                                      2))
        assert (space.has_finite_child(history=[("Model",
                                                 None), ("x1",
                                                         None)]) == (False,
                                                                     17))
        assert (space.has_finite_child(
            history=[("Model", None), ("x1", None), ("x1__p1",
                                                     0.5)]) == (False, 7))
        assert (space.has_finite_child(
            history=[("Model", None), ("x1", None), ("x1__p1",
                                                     0.5), ("x1__p2",
                                                            1)]) == (False, 0))
        assert (space.has_finite_child(history=[("Model",
                                                 None), ("x2",
                                                         None)]) == (False, 4))
        assert (space.has_finite_child(
            history=[("Model", None), ("x2", None), ("x2__p1",
                                                     "a")]) == (False, 3))
        assert (space.has_finite_child(
            history=[("Model", None), ("x2",
                                       None), ("x2__p1",
                                               "c"), ("x2__p2",
                                                      c_func)]) == (False, 0))