def test_mapping_and_ordering(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager(ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) config_2 = deepcopy(config) config_2["interact_individuals_count"] = 4 solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def test_mapping_and_ordering(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager( ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) config_2 = deepcopy(config) config_2["interact_individuals_count"] = 4 solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def do_experiment(saver, config, _wf, rm, estimator): solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(_wf, estimator, rm, solution) m = Utility.makespan(schedule) data = { "metainfo": { "interact_individuals_count": config["interact_individuals_count"], "generations": config["generations"], "species": [s.name for s in config["species"]], "pop_sizes": [s.pop_size for s in config["species"]], "nodes": {n.name: n.flops for n in config["env"].rm.get_nodes()}, "ideal_inds": { MAPPING_SPECIE: ms_str_repr, ORDERING_SPECIE: os_ideal_ind }, "wf_name": _wf.name }, "initial_pops": initial_pops, "final_solution": solution, "final_makespan": m, "iterations": logbook } saver(data) return m
def test_hall_of_fame(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager(ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) config["hall_of_fame_size"] = 3 solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def test_hall_of_fame(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager( ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) config["hall_of_fame_size"] = 3 solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def test_predefined_init_pop(self): ## TODO: make loading from save file too wf_name = "Montage_25" _wf = WF(wf_name) manager = ExperimentResourceManager( ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(_wf, manager, estimator) ## TODO: need to hide low level details import os path = os.path.join( TEMP_PATH, "cga_exp_for_example/5760f488-932e-4224-942f-1f5ac68709bf.json") with open(path, "r") as f: data = json.load(f) initial_pops = data["initial_pops"] mps = [ ListBasedIndividual([tuple(g) for g in ind]) for ind in initial_pops[MAPPING_SPECIE] ] os = [ ListBasedIndividual(ind) for ind in initial_pops[ORDERING_SPECIE] ] for s in config["species"]: if s.name == MAPPING_SPECIE: s.initialize = lambda ctx, size: mps elif s.name == ORDERING_SPECIE: s.initialize = lambda ctx, size: os else: raise Exception("Unexpected specie: " + s.name) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(_wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, _wf) pass
def do_exp(): config = { "interact_individuals_count": 500, "generations": 1000, "env": Env(_wf, rm, estimator), "species": [Specie(name=MAPPING_SPECIE, pop_size=500, cxb=0.9, mb=0.9, mate=lambda env, child1, child2: tools.cxOnePoint(child1, child2), # mutate=mapping_default_mutate, # mutate=lambda ctx, mutant: mapping_k_mutate(ctx, 3, mutant) mutate=mapping_all_mutate, # mutate=mapping_improving_mutation, select=selector, initialize=mapping_default_initialize, # initialize=lambda ctx, pop: mapping_heft_based_initialize(ctx, pop, heft_mapping, 3), stat=lambda pop: {"hamming_distances": hamming_distances([to_seq(p) for p in pop], to_seq(ms_ideal_ind)), "unique_inds_count": unique_individuals(pop), "pcm": pcm(pop), "gdm": gdm(pop)} ), Specie(name=ORDERING_SPECIE, fixed=True, representative_individual=ListBasedIndividual(os_representative)) ], "solstat": lambda sols: {"best_components": hamming_for_best_components(sols, ms_ideal_ind, os_ideal_ind), "best_components_itself": best_components_itself(sols), "best": -1*Utility.makespan(build_schedule(_wf, estimator, rm, max(sols, key=lambda x: x.fitness))) }, "operators": { # "choose": default_choose, "build_solutions": default_build_solutions, # "fitness": fitness_mapping_and_ordering, "fitness": overhead_fitness_mapping_and_ordering, # "assign_credits": default_assign_credits # "assign_credits": max_assign_credits "assign_credits": assign_from_transfer_overhead } } return do_experiment(saver, config, _wf, rm, estimator)
def test_fixed_specie(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager(ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) ms_ideal_ind = build_ms_ideal_ind(wf, manager) config["species"][0] = Specie(name=MAPPING_SPECIE, fixed=True, representative_individual=ListBasedIndividual(ms_ideal_ind)) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def test_predefined_init_pop(self): ## TODO: make loading from save file too wf_name = "Montage_25" _wf = WF(wf_name) manager = ExperimentResourceManager(ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(_wf, manager, estimator) ## TODO: need to hide low level details import os path = os.path.join(TEMP_PATH, "cga_exp_for_example/5760f488-932e-4224-942f-1f5ac68709bf.json") with open(path, "r") as f: data = json.load(f) initial_pops = data["initial_pops"] mps = [ListBasedIndividual([tuple(g) for g in ind]) for ind in initial_pops[MAPPING_SPECIE]] os = [ListBasedIndividual(ind) for ind in initial_pops[ORDERING_SPECIE]] for s in config["species"]: if s.name == MAPPING_SPECIE: s.initialize = lambda ctx, size: mps elif s.name == ORDERING_SPECIE: s.initialize = lambda ctx, size: os else: raise Exception("Unexpected specie: " + s.name) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(_wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, _wf) pass
def test_fixed_specie(self): wf_name = "Montage_25" wf = WF(wf_name) manager = ExperimentResourceManager( ResourceGenerator.r([10, 15, 15, 25])) estimator = ExperimentEstimator(None, 20, 1.0, transfer_time=100) config = default_config(wf, manager, estimator) ms_ideal_ind = build_ms_ideal_ind(wf, manager) config["species"][0] = Specie( name=MAPPING_SPECIE, fixed=True, representative_individual=ListBasedIndividual(ms_ideal_ind)) solution, pops, logbook, initial_pops = run_cooperative_ga(**config) schedule = build_schedule(wf, estimator, manager, solution) for k, items in schedule.mapping.items(): for item in items: item.state = ScheduleItem.FINISHED ## TODO: refactor this ExecutorRunner.extract_result(schedule, True, wf) pass
def cost_mapping_and_ordering(ctx, solution): env = ctx['env'] schedule = build_schedule(env.wf, env.estimator, env.rm, solution) all_cost = cost(schedule, env.estimator) return -all_cost
stat=lambda pop: { "hamming_distances": hamming_distances(pop, os_ideal_ind), "unique_inds_count": unique_individuals(pop), "pcm": pcm(pop), "gdm": gdm(pop) }) ], "solstat": lambda sols: { "best_components": hamming_for_best_components(sols, ms_ideal_ind, os_ideal_ind), "best_components_itself": best_components_itself(sols), "best": -1 * Utility.makespan( build_schedule(_wf, estimator, rm, max(sols, key=lambda x: x.fitness))) }, "analyzers": [mapping_mut_reg.analyze], "operators": { # "choose": default_choose, # "build_solutions": default_build_solutions, "build_solutions": one_to_one_build_solutions, "fitness": fitness_mapping_and_ordering, # "fitness": overhead_fitness_mapping_and_ordering, # "assign_credits": default_assign_credits # "assign_credits": bonus2_assign_credits "assign_credits": max_assign_credits } }
), Specie(name=ORDERING_SPECIE, pop_size=50, cxb=0.8, mb=0.5, mate=ordering_default_crossover, mutate=ordering_default_mutate, select=ordering_selector, initialize=ordering_default_initialize, stat=lambda pop: {"hamming_distances": hamming_distances(pop, os_ideal_ind), "unique_inds_count": unique_individuals(pop), "pcm": pcm(pop), "gdm": gdm(pop)} ) ], "solstat": lambda sols: {"best_components": hamming_for_best_components(sols, ms_ideal_ind, os_ideal_ind), "best_components_itself": best_components_itself(sols), "best": -1* Utility.makespan(build_schedule(_wf, estimator, rm, max(sols, key=lambda x: x.fitness))) }, "operators": { # "choose": default_choose, "build_solutions": default_build_solutions, # "fitness": fitness_mapping_and_ordering, "fitness": overhead_fitness_mapping_and_ordering, # "assign_credits": default_assign_credits # "assign_credits": max_assign_credits "assign_credits": assign_from_transfer_overhead } } saver = UniqueNameSaver("../../temp/cga_heft_mixin") def do_exp():
Specie(name=ORDERING_SPECIE, pop_size=50, cxb=0.9, mb=0.9, mate=ordering_default_crossover, mutate=ordering_default_mutate, select=ordering_selector, # initialize=ordering_default_initialize, initialize=lambda ctx, pop: ordering_heft_based_initialize(ctx, pop, heft_ordering, 3), stat=lambda pop: {"hamming_distances": hamming_distances(pop, os_ideal_ind), "unique_inds_count": unique_individuals(pop), "pcm": pcm(pop), "gdm": gdm(pop)} ) ], "solstat": lambda sols: {"best_components": hamming_for_best_components(sols, ms_ideal_ind, os_ideal_ind), "best_components_itself": best_components_itself(sols), "best": -1*Utility.makespan(build_schedule(_wf, estimator, rm, max(sols, key=lambda x: x.fitness)))}, "analyzers": [mapping_mut_reg.analyze], "use_credit_inheritance": True, "operators": { # "choose": default_choose, # "build_solutions": default_build_solutions, "build_solutions": one_to_one_build_solutions, "fitness": fitness_mapping_and_ordering, # "fitness": overhead_fitness_mapping_and_ordering, # "assign_credits": default_assign_credits # "assign_credits": bonus2_assign_credits "assign_credits": max_assign_credits }
def do_exp(): config = { "interact_individuals_count": 100, "generations": 300, "env": Env(_wf, rm, estimator), "species": [ Specie( name=MAPPING_SPECIE, pop_size=50, cxb=0.9, mb=0.9, mate=lambda env, child1, child2: tools.cxOnePoint( child1, child2), # mutate=mapping_default_mutate, # mutate=lambda ctx, mutant: mapping_k_mutate(ctx, 3, mutant) mutate=mapping_all_mutate, # mutate=OnlyUniqueMutant()(mapping_all_mutate), select=selector, # initialize=mapping_default_initialize, initialize=lambda ctx, pop: mapping_heft_based_initialize( ctx, pop, heft_mapping, 3), stat=lambda pop: { "hamming_distances": hamming_distances([to_seq(p) for p in pop], to_seq(ms_ideal_ind)), "unique_inds_count": unique_individuals(pop), "pcm": pcm(pop), "gdm": gdm(pop) }), Specie(name=ORDERING_SPECIE, fixed=True, representative_individual=ListBasedIndividual( os_representative)) ], "solstat": lambda sols: { "best_components": hamming_for_best_components(sols, ms_ideal_ind, os_ideal_ind), "best_components_itself": best_components_itself(sols), "best": -1 * Utility.makespan( build_schedule(_wf, estimator, rm, max(sols, key=lambda x: x.fitness))) }, "operators": { # "choose": default_choose, "build_solutions": default_build_solutions, "fitness": fitness_mapping_and_ordering, # "fitness": overhead_fitness_mapping_and_ordering, # "assign_credits": default_assign_credits # "assign_credits": max_assign_credits "assign_credits": assign_from_transfer_overhead } } return do_experiment(saver, config, _wf, rm, estimator)