Exemple #1
0
    def test_go_and_get_individuals(self):
        # load random values for the simulation
        self._load_random_values()

        # Execute a simulation
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION)
        mlc.open_experiment("test_go_and_check")
        mlc.go("test_go_and_check", 2)

        # obtain individuals
        individuals = mlc.get_individuals("test_go_and_check")

        # check number of individuals
        self.assertEqual(len(individuals), 11)

        # TODO: Check individual values
        for indiv_id, indiv_data in individuals.items():
            self.assertIsInstance(indiv_data, IndividualData)

        # Test Update Individual Cost in all generations
        mlc.update_individual_cost("test_go_and_check", 2, 1000, 1001)

        indiv_data = mlc.get_individuals("test_go_and_check")[2]
        self.assertEqual(indiv_data.get_appearances(), 2)
        self.assertEqual(indiv_data.get_cost_history(), {1: [(1000.0, 1001)], 2: [(1000.0, 1001)]})
        mlc.close_experiment("test_go_and_check")
        mlc.delete_experiment("test_go_and_check")
Exemple #2
0
    def test_update_board_configuration(self):
        try:
            mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
            mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT, MLCWorkspaceTest.NEW_CONFIGURATION)
            mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

            board_configuration, serial_connection = mlc.get_board_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)

            new_board_config = ProtocolConfig(None, report_mode=12, read_count=10, read_delay=11, board_type=boards.Leonardo, analog_resolution=13)
            new_connection = SerialConnectionConfig("/dev/ttyACM1", baudrate=5000, parity="P", stopbits=2, bytesize=6)
            mlc.save_board_configuration(MLCWorkspaceTest.NEW_EXPERIMENT, new_board_config, new_connection)

            loaded_board_configuration, loaded_connection = mlc.get_board_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)


            self.assertEqual(loaded_board_configuration.board_type, boards.Leonardo)
            self.assertEqual(loaded_board_configuration.read_count, 10)
            self.assertEqual(loaded_board_configuration.read_delay, 11)
            self.assertEqual(loaded_board_configuration.report_mode, 12)
            self.assertEqual(loaded_board_configuration.analog_resolution, 13)

            self.assertEqual(loaded_connection.port, "/dev/ttyACM1")
            self.assertEqual(loaded_connection.baudrate, 5000)
            self.assertEqual(loaded_connection.parity, "P")
            self.assertEqual(loaded_connection.stopbits, 2)
            self.assertEqual(loaded_connection.bytesize, 6)

        finally:
            # FIXME: use Setup/TearDown testcase
            mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
Exemple #3
0
    def test_import_non_existent_experiment(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)

        import_experiment_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                              "test4.mlc")
        mlc.import_experiment(import_experiment_path)
        self.assertTrue("test4" in mlc.get_workspace_experiments())
        mlc.delete_experiment("test4")
Exemple #4
0
 def test_import_experiment_with_erroneous_path(self):
     mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
     import_experiment_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                           "test5.mlc")
     try:
         mlc.import_experiment(import_experiment_path)
         self.assertTrue(False)
         mlc.delete_experiment("test5")
     except MLC.api.mlc.ImportExperimentPathNotExistException:
         self.assertTrue(True)
         self.assertFalse("test5" in mlc.get_workspace_experiments())
Exemple #5
0
    def test_get_info_empty_simulation(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.open_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        info = mlc.get_experiment_info(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)

        self._assert_key_value(info, "name", MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        self._assert_key_value(info, "generations", 0)
        self._assert_key_value(info, "individuals", 0)
        self._assert_key_value(info, "individuals_per_generation", 10)

        mlc.close_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        mlc.delete_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
Exemple #6
0
    def test_import_existent_experiment(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment("test4", MLCWorkspaceTest.ORIGINAL_CONFIGURATION)

        import_experiment_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                              "test4.mlc")
        try:
            mlc.import_experiment(import_experiment_path)
            self.assertTrue(False)
        except MLC.api.mlc.DuplicatedExperimentError:
            self.assertTrue(True)
        finally:
            mlc.delete_experiment("test4")
Exemple #7
0
    def test_delete_experiment(self):
        # delete an experiment that not exists
        try:
            mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
            mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
            self.assertTrue(False)
        except MLC.api.mlc.ExperimentNotExistException:
            self.assertTrue(True)

        mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT,
                           MLCWorkspaceTest.NEW_CONFIGURATION)
        mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        self.assertFalse(os.path.exists(os.path.join(MLCWorkspaceTest.WORKSPACE_DIR,
                                                     MLCWorkspaceTest.NEW_EXPERIMENT)))
Exemple #8
0
    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")
Exemple #9
0
    def test_go_and_check_simulation_info(self):
        # load random values for the simulation
        self._load_random_values()

        # Execute a simulation
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION)
        mlc.open_experiment("test_go_and_check")
        mlc.go("test_go_and_check", 2)

        # check simulation info
        info = mlc.get_experiment_info("test_go_and_check")
        self._assert_key_value(info, "name", "test_go_and_check")
        self._assert_key_value(info, "generations", 2)
        self._assert_key_value(info, "individuals", 11)
        self._assert_key_value(info, "individuals_per_generation", 10)

        mlc.close_experiment("test_go_and_check")
        mlc.delete_experiment("test_go_and_check")
Exemple #10
0
    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")
Exemple #11
0
    def test_get_default_board_configuration(self):
        try:
            mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
            mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT,
                               MLCWorkspaceTest.NEW_CONFIGURATION)
            mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

            board_configuration, serial_connection = mlc.get_board_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)

            self.assertEqual(board_configuration.board_type, boards.Due)
            self.assertEqual(board_configuration.read_count, 2)
            self.assertEqual(board_configuration.read_delay, 0)
            self.assertEqual(board_configuration.report_mode, 0)
            self.assertEqual(board_configuration.analog_resolution, 12)

            self.assertEqual(serial_connection.port, "/dev/ttyACM0")
            self.assertEqual(serial_connection.baudrate, 115200)
            self.assertEqual(serial_connection.parity, "N")
            self.assertEqual(serial_connection.stopbits, 1)
            self.assertEqual(serial_connection.bytesize, 8)

        finally:
            # FIXME: use Setup/TearDown testcase
            mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)