예제 #1
0
    def test_experiment_tags(self, tmpdir):
        """Test that the tags context manager is working as designed by
        adding tags to the experiment when inside the corresponding with
        statement."""
        exp = Experiment(directory=tmpdir, state_class=ExperimentState)
        assert not exp.tags

        with exp.tag("test_tag"):
            assert exp.tags == ["test_tag"]

        assert not exp.tags

        with exp.tag("test_tag"):
            with exp.tag("second_tag"):
                assert exp.tags == ["test_tag", "second_tag"]
            assert exp.tags == ["test_tag"]
예제 #2
0
    def test_tag_filtering(self, tmpdir):
        exp = Experiment(directory=tmpdir, state_class=EmptyState)
        exp_args = {"a": 1.0, "B": 2.0, "c": 3.0}
        root = exp.spawn_new_tree(**exp_args)
        op_add = OpRecipe(add, 1.2)
        with exp.tag("ops"):
            with exp.tag("phase:mul"):
                x1 = OpRecipe(mul, 0.4)(root)
                x2 = OpRecipe(mul, 0.5)(root)
            with exp.tag("phase:add"):
                y1 = op_add(x1)
                y2 = op_add(x2)
        exp.run()
        exp = Experiment.restore(directory=tmpdir, state_class=EmptyState)
        assert len(exp.graph.nodes.filter("op*")) == 4
        assert (
            len(
                exp.graph.nodes.filter("phase:mul")
                | exp.graph.nodes.filter("phase:add")
            )
            == 4
        )
        assert len(exp.graph.nodes.filter("!phase:mul")) == 3
        assert (
            len(
                exp.graph.nodes.filter("ops")
                & exp.graph.nodes.filter("!phase:add")
            )
            == 2
        )

        # Cannot compose other objects with a nodeset
        with pytest.raises(TypeError):
            exp.graph.nodes.filter("phase:mul") | "hi"
        with pytest.raises(TypeError):
            exp.graph.nodes.filter("phase:*") & "!hi"