Skip to content

Commit

Permalink
Debugging genetic search
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Apr 15, 2024
1 parent d8c73d2 commit 4e18bef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/apex/apex_kokkos_tuning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class KokkosSession {
} else if (strncmp(apex::apex_options::kokkos_tuning_policy(),
"simulated_annealing", strlen("simulated_annealing")) == 0) {
strategy = apex_ah_tuning_strategy::SIMULATED_ANNEALING;
} else if (strncmp(apex::apex_options::kokkos_tuning_policy(),
"genetic_search", strlen("genetic_search")) == 0) {
strategy = apex_ah_tuning_strategy::GENETIC_SEARCH;
} else {
strategy = apex_ah_tuning_strategy::NELDER_MEAD;
}
Expand Down
2 changes: 1 addition & 1 deletion src/apex/apex_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ inline int __common_setup_custom_tuning(shared_ptr<apex_tuning_session>
}
);
}
} else if (request.strategy == apex_ah_tuning_strategy::APEX_GENETIC) {
} else if (request.strategy == apex_ah_tuning_strategy::GENETIC_SEARCH) {
status = __genetic_setup(tuning_session, request);
if(status == APEX_NOERROR) {
apex::register_policy(
Expand Down
2 changes: 1 addition & 1 deletion src/apex/apex_policies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class apex_ah_tuning_strategy : int {
EXHAUSTIVE, RANDOM, NELDER_MEAD,
PARALLEL_RANK_ORDER, SIMULATED_ANNEALING,
APEX_EXHAUSTIVE, APEX_RANDOM,
APEX_GENETIC};
GENETIC_SEARCH};

struct apex_tuning_session;
class apex_tuning_request;
Expand Down
16 changes: 10 additions & 6 deletions src/apex/genetic_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ auto get_random_number(const std::size_t min, const std::size_t max)
void GeneticSearch::getNewSettings() {
static bool bootstrapping{true};
if (bootstrapping) {
// we are still bootstrapping, so just get a random selection.
for (auto& v : vars) { v.second.get_next_neighbor(); }
return;
if (population.size() >= population_size) {
bootstrapping = false;
} else {
// we are still bootstrapping, so just get a random selection.
for (auto& v : vars) { v.second.get_next_neighbor(); }
return;
}
}
std::cout << "Have population of " << population.size() << " to evaluate!" << std::endl;
// time to cull the herd?
if (population.size() >= population_size) {
std::cout << "Have population of " << population.size() << " to evaluate!" << std::endl;
Expand All @@ -102,13 +107,12 @@ void GeneticSearch::getNewSettings() {
// ...then drop half of them - the "weakest" ones.
population.erase(population.cbegin() + crossover, population.cend());
std::cout << "Now have population of " << population.size() << std::endl;
bootstrapping = false;
}
// We want to generate a new individual using two "high quality" parents.
// choose parent A
individual& A = population[get_random_number(0,crossover)];
individual& A = population[get_random_number(0,crossover-1)];
// choose parent B
individual& B = population[get_random_number(0,crossover)];
individual& B = population[get_random_number(0,crossover-1)];
// blend their variables into a new individual and maybe mutate?
size_t i = 0;
for (auto& v : vars) {
Expand Down

0 comments on commit 4e18bef

Please sign in to comment.