コード例 #1
0
ファイル: test_dag.py プロジェクト: matthewfeickert/dagger
    def test_state_lazy_load(self, tmpdir):
        exp = Experiment(directory=tmpdir, state_class=EmptyState)
        s = EmptyState(experiment_object=exp)
        exp.root = s
        s.save()
        # Generate a new child state from state `s`
        r = EmptyState.new_state(s)
        r.save()
        exp.save()

        # Reload the two-state experiment
        # By default, slim=True
        exp = Experiment.restore(directory=tmpdir)

        for node, state in exp.graph.node_map.items():
            assert state.slim_loaded  # deflated
            with state.lazy_load():
                assert not state.slim_loaded  # fully loaded
            assert state.slim_loaded  # deflated

        # Check behavior change as slim is set to False when exp is restored
        exp = Experiment.restore(directory=tmpdir, slim=False)

        for node, state in exp.graph.node_map.items():
            assert not state.slim_loaded  # deflated
            with state.lazy_load():
                assert not state.slim_loaded  # fully loaded
            # Note: lazy_load deflates the state even if it was initially
            # fully loaded!
            assert state.slim_loaded  # deflated
コード例 #2
0
ファイル: test_dag.py プロジェクト: matthewfeickert/dagger
    def test_new_state(self, tmpdir):
        """Generating a new state from a previous one using new_state should
        generate the right connection between the two states, which can be
        inspected through the setting of a parent_sha and then in the way
        the experiment graph is drawn when the StaticExperimentTree is
        reloaded.
        """
        exp = Experiment(directory=tmpdir, state_class=EmptyState)
        s = EmptyState(experiment_object=exp)
        # Set it as the root of the experiment
        exp.root = s
        s.save()

        # Generate a new child state from state `s`
        r = EmptyState.new_state(s)
        assert r.parent_sha == s.sha()
        assert r.experiment_object == exp

        r.save()
        exp.save()
        exp = Experiment.restore(directory=tmpdir)  # reload experiment

        # Test that the graph looks as expected with the connection
        assert len(exp.graph.nodes) == 2
        assert exp.graph.edge_map[s.sha()] == set([r.sha()])