def test_cartesian_product(self): """ Test the function which computes the cartesian product of a dictionary of lists. This one is used to explore the complete parameter space specifeid in a PED file. :return: """ def _dict_is_in_list(d, l): for d1 in l: if d1 == d: return True return False INPUT = {"x": [1, 2, 3], "y": ["value1", "value2"]} OUTPUT = [ {"x": 1, "y": "value1"}, {"x": 1, "y": "value2"}, {"x": 2, "y": "value1"}, {"x": 2, "y": "value2"}, {"x": 3, "y": "value1"}, {"x": 3, "y": "value2"} ] # calculate Cartesian product result = compute_cartesian_product(INPUT) # check if results are as expected self.assertEqual(len(result), len(OUTPUT)) for d in result: self.assertTrue(_dict_is_in_list(d, OUTPUT))
def populate(self): """ Search for parameter study macros and generate one run configuration for each parameter combination to be tested. """ # convert parameter macros from PED file to plain lists for rl in self.resource_limitations: rewrite_parameter_macros_to_lists(rl) # convert measurment points from PED file to plain lists for mp in self.measurement_points: rewrite_parameter_macros_to_lists(mp) # check for vnfs that need overload detection if hasattr(self, 'overload_detection'): for vnf_name in self.overload_detection: self.overload_vnf_list.append(vnf_name) # get the configuration that needs to be executed in the vnf before the test run. self.configuration_space_dict = self._get_configuration_space_as_dict() #LOG.info("configuration space:{0}".format(self.command_space_list)) # aggregate all commands to be used in the experiment to a flat dict for further processing command_dict, self.vnforder_list = self._get_command_space_as_dict() # explore entire command space by calculating the Cartesian product over the given dict self.command_space_list = compute_cartesian_product(command_dict) #LOG.info("command space:{0}".format(self.command_space_list)) # aggregate all parameters to used in the experiment to a flat dict for further processing resource_dict = self._get_resource_space_as_dict() # print(parameter_dict) # explore entire parameter space by calculating the Cartesian product over the given dict self.resource_space_list = compute_cartesian_product(resource_dict) # create a run configuration object for each calculated configuration to test for i in range(0, len(self.resource_space_list)): self.run_configurations.append( RunConfiguration(i, self.resource_space_list[i])) LOG.info( "Populated experiment specifications: %r with %d configurations to test." % (self.name, len(self.run_configurations)))
def populate(self): """ Search for parameter study macros and generate one run configuration for each parameter combination to be tested. """ # convert parameter macros from PED file to plain lists for rl in self.resource_limitations: rewrite_parameter_macros_to_lists(rl) # aggregate all parameters to used in the experiment to a flat dict for further processing parameter_dict = self._get_configuration_space_as_dict() # print(parameter_dict) # explore entire parameter space by calculating the Cartesian product over the given dict parameter_space_list = compute_cartesian_product(parameter_dict) # create a run configuration object for each calculated configuration to test for i in range(0, len(parameter_space_list)): self.run_configurations.append(RunConfiguration(i, parameter_space_list[i])) LOG.info("Populated experiment specifications: %r with %d configurations to test." % (self.name, len(self.run_configurations)))
def populate(self): """ Search for parameter study macros and generate one run configuration for each parameter combination to be tested. """ # convert parameter macros from PED file to plain lists for rl in self.resource_limitations: rewrite_parameter_macros_to_lists(rl) # convert measurment points from PED file to plain lists for mp in self.measurement_points: rewrite_parameter_macros_to_lists(mp) ######## IMEC # check for vnfs that need overload detection (imec mode) if hasattr(self, 'overload_detection') : for vnf_name in self.overload_detection: self.overload_vnf_list.append(vnf_name) # gather all configuration commands per VNF that need to be executed once before all tests start self.pre_configuration = self._get_pre_configuration_as_dict() ######## UPB # generate a single flat dict containing all the parameter study lists defined in the PED # this includes: header parameters (repetitions), measurement point commands (all), and # function resource limitations configuration_dict = dict() configuration_dict.update(self._get_experiment_header_space_as_dict()) configuration_dict.update(self._get_function_resource_space_as_dict()) configuration_dict.update(self._get_mp_space_as_dict()) LOG.debug("configuration space:{0}".format(configuration_dict)) # explore entire parameter space by calculating the Cartesian product over the given dict configuration_space_list = compute_cartesian_product(configuration_dict) # imec backward compatibility self.configuration_space_list = configuration_space_list # create a experiment configuration objects for each calculated configuration to test for c in configuration_space_list: rc = ExperimentConfiguration(self, c) self.experiment_configurations.append(rc) LOG.info("Populated experiment specification: {} with {} configurations to be executed.".format( self.name, len(self.experiment_configurations)))
def test_cartesian_product(self): """ Test the function which computes the cartesian product of a dictionary of lists. This one is used to explore the complete parameter space specifeid in a PED file. :return: """ def _dict_is_in_list(d, l): for d1 in l: if d1 == d: return True return False INPUT = {"x": [1, 2, 3], "y": ["value1", "value2"]} OUTPUT = [{ "x": 1, "y": "value1" }, { "x": 1, "y": "value2" }, { "x": 2, "y": "value1" }, { "x": 2, "y": "value2" }, { "x": 3, "y": "value1" }, { "x": 3, "y": "value2" }] # calculate Cartesian product result = compute_cartesian_product(INPUT) # check if results are as expected self.assertEqual(len(result), len(OUTPUT)) for d in result: self.assertTrue(_dict_is_in_list(d, OUTPUT))