def test_obtain_configuration_from_a_closed_experiment(self): try: mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.get_experiment_configuration(MLCWorkspaceTest.ORIGINAL_EXPERIMENT) self.assertTrue(False, "Configuration from a closed experiment should not be obtained") except MLC.api.mlc.ClosedExperimentException: self.assertTrue(True)
def test_obtain_configuration(self): mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.open_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT) configuration = mlc.get_experiment_configuration(MLCWorkspaceTest.ORIGINAL_EXPERIMENT) mlc.close_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT) # check configuration structure self.assertIsInstance(configuration, dict) self.assertTrue(configuration.has_key("BEHAVIOUR")) self.assertIsInstance(configuration["BEHAVIOUR"], dict) self.assertTrue(configuration["BEHAVIOUR"].has_key("showeveryitbest")) self.assertEqual(configuration["BEHAVIOUR"]["showeveryitbest"], "true")
def test_set_configuration(self): mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) # check original configuration mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT, MLCWorkspaceTest.NEW_CONFIGURATION) mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) original_config = mlc.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT) self.assertEqual(original_config["PARAMS"]["test_param"], "test_value") # chage paramenter value mlc.set_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT, {"PARAMS": {"test_param": "new_value"}}) mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) # reload mlc_workspace mlc_reloaded = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc_reloaded.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) original_config = mlc_reloaded.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT) self.assertEqual(original_config["PARAMS"]["test_param"], "new_value") mlc_reloaded.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) # set specific parameter mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) mlc.set_experiment_configuration_parameter(MLCWorkspaceTest.NEW_EXPERIMENT, "another_section", "another_param", "another_value") mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) # reload mlc_workspace mlc_reloaded = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc_reloaded.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) config = mlc_reloaded.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT) mlc_reloaded.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) self.assertEqual(config["PARAMS"]["test_param"], "new_value") self.assertIn("another_section", config) self.assertIn("another_param", config["another_section"]) self.assertEqual(config["another_section"]["another_param"], "another_value")
def test_create_experiment_and_obtain_configuration(self): mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT, MLCWorkspaceTest.NEW_CONFIGURATION) mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) configuration = mlc.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT) mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT) # check configuration structure self.assertIsInstance(configuration, dict) self.assertTrue(configuration.has_key("PARAMS")) self.assertIsInstance(configuration["PARAMS"], dict) self.assertTrue(configuration["PARAMS"].has_key("test_param")) self.assertEqual(configuration["PARAMS"]["test_param"], "test_value")