Skip to content

Commit

Permalink
feat(optimizer): add argument --evolutionary
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Jan 8, 2024
1 parent 0da4463 commit 4d37b78
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions discopop_library/discopop_optimizer/OptimizerArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# directory for details.
import os.path
from dataclasses import dataclass
from typing import List, Optional


@dataclass
Expand All @@ -16,6 +17,7 @@ class OptimizerArguments(object):
verbose: bool
interactive: bool
exhaustive: bool
evolutionary: Optional[List[str]]
doall_microbench_file: str
reduction_microbench_file: str
allow_nested_parallelism: bool
Expand All @@ -24,6 +26,13 @@ class OptimizerArguments(object):
check_called_function_for_nested_parallelism: bool

def __post_init__(self):
# fix correct optimization method
if not self.exhaustive:
if self.evolutionary == None:
self.evolutionary = [str(50), str(5)]
elif self.evolutionary != None:
self.evolutionary = None

self.__validate()

def __validate(self):
Expand Down
5 changes: 4 additions & 1 deletion discopop_library/discopop_optimizer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def parse_args() -> OptimizerArguments:
parser.add_argument("-v", "--verbose", action="store_true",
help="Enable verbose output.")
parser.add_argument("-x", "--exhaustive", action="store_true",
help="Enable exhaustive search. By default, an evolutionary search is performed.")
help="Enable exhaustive search. By default, an evolutionary search with a population size of 50 and 5 generations is performed.")
parser.add_argument("-e", "--evolutionary", type=str, default=None, nargs=2, metavar=("population_size", "generations"),
help="Enable evolutionary search. By default, an evolutionary search with a population size of 50 and 5 generations is performed.")
parser.add_argument(
"--doall-microbench-file", type=str, default="None",
help="Do-All microbenchmark results"
Expand Down Expand Up @@ -56,6 +58,7 @@ def parse_args() -> OptimizerArguments:
verbose=arguments.verbose,
interactive=arguments.interactive,
exhaustive=arguments.exhaustive,
evolutionary=arguments.evolutionary,
doall_microbench_file=arguments.doall_microbench_file,
reduction_microbench_file=arguments.reduction_microbench_file,
allow_nested_parallelism=arguments.allow_nested_parallelism,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def perform_evolutionary_search(
optimizer_dir: str,
) -> Optional[OptimizerOutputPattern]:
### SETTINGS
population_size = 50
generations = 5
population_size = int(arguments.evolutionary[0])
generations = int(arguments.evolutionary[1])
selection_strength = 0.85 # 0.8 --> 80% of the population will be selected for the next generation
crossovers = int(population_size / 10)
mutations = int(population_size / 10)
Expand Down
4 changes: 3 additions & 1 deletion discopop_library/discopop_optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ def run(arguments: OptimizerArguments):
best_configuration = evaluate_all_decision_combinations(
experiment, available_decisions, arguments, optimizer_dir
)
else:
elif arguments.evolutionary != None:
# perform evolutionary search
best_configuration = perform_evolutionary_search(
experiment,
available_decisions,
arguments,
optimizer_dir,
)
else:
raise ValueError("No optimization method specified!")

if best_configuration is not None:
best_configuration = optimize_updates(experiment, best_configuration, arguments)
Expand Down

0 comments on commit 4d37b78

Please sign in to comment.