Exemple #1
0
    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
Exemple #2
0
    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()])
Exemple #3
0
    def test_state_root_inheritance(self, tmpdir):
        """Test that a state that is instatiated within an experiment that
        has a root will correctly inherit the pointer to the root to be able
        to refer back to it when needed (e.g. for weight resetting).
        """
        exp = Experiment(directory=tmpdir, state_class=EmptyState)

        root = EmptyState(experiment_object=exp)
        exp.root = root  # manually set it to the root of the experiment

        # Ideally this should also be set to True, but this is not used here
        # and root setting should never happen manually anyways, so this is
        # internally handled when a new tree is spawned.
        # root.root_state = True

        s = EmptyState(experiment_object=exp)
        assert s.root == root