Example #1
0
    def test_resume(self):
        # TODO

        self.cntr = []
        self.experiment.train = lambda epoch: self.cntr.append(0)
        self.experiment.run()
        self.assertTrue(
            len(self.cntr) == 10,
            "Did not call train for the right number of epochs")

        exp2 = PytorchExperiment(name="test-exp2",
                                 base_dir=self.test_dir,
                                 resume=self.experiment.elog.work_dir)
        exp3 = PytorchExperiment(name="test-exp2",
                                 base_dir=self.test_dir,
                                 resume=self.experiment.elog.work_dir,
                                 resume_reset_epochs=False)

        exp2.prepare_resume()
        exp3.prepare_resume()

        self.assertTrue(exp2.exp_name == 'test_experiment',
                        "Did not restore exp_name")
        self.assertTrue(exp2._epoch_idx == 0, "Did not reset epochs")
        self.assertTrue(exp3._epoch_idx == 10, "Did reset epochs")

        exp2.train = lambda epoch: self.cntr.append(0)
        exp3.train = lambda epoch: self.cntr.append(0)
        exp2.run()
        self.assertTrue(len(self.cntr) == 20, "Did call not train for exp2")
        exp3.run()
        self.assertTrue(len(self.cntr) == 20, "Did call train for exp3")

        exp2._exp_state = "Ended"
        exp3._exp_state = "Ended"
Example #2
0
 def setUp(self):
     self.test_dir = tempfile.gettempdir()
     self.experiment = PytorchExperiment(name="test_experiment",
                                         base_dir=self.test_dir,
                                         n_epochs=10)