penguin.genetic module¶
- class penguin.genetic.ConfigChromosome(parent=None, new_gene=None)[source]¶
Bases:
object- Parameters:
parent (ConfigChromosome)
- genes: frozenset[MitigationPatch]¶
- hash: int¶
- class penguin.genetic.ConfigPopulation(proj_dir, base_config, run_base, logger, pop_size, timeout, max_runs, nelites=1, verbose=False)[source]¶
Bases:
ConfigSearch- config_in_pop(config)[source]¶
- Parameters:
config (ConfigChromosome)
- create_work_queue(nworkers, chromosomes)[source]¶
- Parameters:
nworkers (int)
chromosomes (Set[ConfigChromosome])
- crossover(p1_prob=0.5)[source]¶
Perform crossover on the parents to create new children, choose from p1 with probability p1_prob
- extend_genome(parent, new_gene)[source]¶
- Parameters:
parent (ConfigChromosome)
new_gene (MitigationAlleleSet)
- get_fitness(config)[source]¶
- Parameters:
config (ConfigChromosome)
- get_full_config(config)[source]¶
Given a configuration, return the full configuration (base_config+config)
- Parameters:
config (ConfigChromosome)
- get_patched_config(config)[source]¶
- Parameters:
config (ConfigChromosome)
- mutation(nmuts=1)[source]¶
Perform mutation on the population, we are going to be a bit more aggressive with mutation than traditional GAs
Our mutation here is essentially “try a different mitigation”. Elites will get modified here
- record_fitness(config, fitness)[source]¶
- Parameters:
config (ConfigChromosome)
- run_config(config, run_index)[source]¶
Careful! This function is run in parallel and should not modify any shared state.
This is very dirty - we return the failure type from graph.py, not our own Failure class
We also tack on the base config, so watch out for that.
- Parameters:
config (ConfigChromosome)
run_index (int)
- Return type:
Tuple[List[Failure], float]
- run_configs(nthreads, chromosomes)[source]¶
- Parameters:
nthreads (int)
chromosomes (Set[ConfigChromosome])
- class penguin.genetic.GenePool[source]¶
Bases:
objectThe gene pool tracks the set of possible mitigations for a given failure
- class penguin.genetic.MitigationAlleleSet(failure_name, mitigations)[source]¶
Bases:
objectThis class contains a set of mitigations we know about for a given failure In the biology analogy, each mitigation would be an allele
- Parameters:
failure_name (str)
mitigations (frozenset)
- failure_name: str¶
- mitigations: frozenset¶
- class penguin.genetic.MitigationPatch(failure_name, patch)[source]¶
Bases:
objectThis class represents a single mitigation and the patch to apply
- Parameters:
failure_name (str)
patch (frozenset)
- failure_name: str¶
- patch: frozenset¶
- penguin.genetic.create_init_gene(base_config, proj_dir, patch_dir)[source]¶
Based on add_init_options_to_graph in manager.py
A config needs to have an [‘env’][‘igloo_init’] in order to do anything useful. We might have a single option already set or we might have multiple options stored proj_dir/static/InitFinder.yaml (based on static analysis).
If we have no value set and no potential values, we raise an error.
Otherwise we’ll create a fake failure for “init” and a mitigation node to add each of the init options. Then we’ll create configs with each init. This means we’ll start our search with multiple configuration options to explore.
If an igloo_init is set in the initial config, we’ll assume that’s right and leave it alone.