-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94cc8e7
commit 16a7a3e
Showing
5 changed files
with
132 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
golem/core/optimisers/common_optimizer/common_optimizer_params.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from abc import abstractmethod | ||
from collections import deque | ||
from dataclasses import dataclass | ||
from typing import Optional, Sequence, Union, Any, Dict, List, Callable | ||
|
||
from golem.core.dag.graph import Graph | ||
from golem.core.optimisers.common_optimizer.node import Node | ||
from golem.core.optimisers.common_optimizer.old_config import default_stages | ||
from golem.core.optimisers.common_optimizer.scheme import Scheme | ||
from golem.core.optimisers.common_optimizer.stage import Stage | ||
from golem.core.optimisers.common_optimizer.task import Task, TaskStatusEnum | ||
from golem.core.optimisers.genetic.operators.operator import PopulationT, EvaluationOperator | ||
from golem.core.optimisers.graph import OptGraph | ||
from golem.core.optimisers.objective import Objective, ObjectiveFunction | ||
from golem.core.optimisers.opt_history_objects.individual import Individual | ||
from golem.core.optimisers.opt_history_objects.opt_history import OptHistory | ||
from golem.core.optimisers.optimization_parameters import OptimizationParameters | ||
from golem.core.optimisers.optimizer import GraphOptimizer, GraphGenerationParams, AlgorithmParameters | ||
from golem.core.optimisers.populational_optimizer import PopulationalOptimizer | ||
from golem.core.optimisers.timer import OptimisationTimer | ||
|
||
|
||
@dataclass | ||
class CommonOptimizerParameters(AlgorithmParameters): | ||
""" This class is for storing a state of all CommonOptimizer parameters """ | ||
generations: Optional[List[PopulationT]] = None | ||
population: Optional[PopulationT] = None | ||
|
||
objective: Optional[Objective] = None | ||
initial_graphs: Optional[Sequence[Union[Graph, Any]]] = None | ||
requirements: Optional[OptimizationParameters] = None | ||
graph_generation_params: Optional[GraphGenerationParams] = None | ||
graph_optimizer_params: Optional[AlgorithmParameters] = None | ||
history: Optional[OptHistory] = None | ||
|
||
repo: Optional[Dict[str, bool]] = None | ||
new_population: Optional[PopulationT] = None | ||
evaluator: Optional[Any] = None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
golem/core/optimisers/common_optimizer/nodes/uniqueness_check.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from copy import deepcopy | ||
from random import choice | ||
|
||
from typing import Optional, Dict, Callable | ||
|
||
from golem.core.optimisers.common_optimizer.node import Node | ||
from golem.core.optimisers.common_optimizer.task import Task, TaskStatusEnum, TaskMixin | ||
from golem.core.optimisers.genetic.operators.base_mutations import base_mutations_repo, MutationTypesEnum | ||
from golem.core.optimisers.graph import OptGraph | ||
from golem.core.optimisers.opt_history_objects.individual import Individual | ||
from golem.core.optimisers.opt_history_objects.parent_operator import ParentOperator | ||
|
||
|
||
class UniquenessCheckTask(TaskMixin): | ||
def __init__(self, parameters: 'CommonOptimizerParameters'): | ||
super().__init__(parameters) | ||
self.generation = parameters.population | ||
self.repo = parameters.graph_optimizer_params.repo | ||
|
||
def update_parameters(self, parameters: 'CommonOptimizerParameters'): | ||
return super().update_parameters(parameters) | ||
|
||
|
||
class UniquenessCheck(Node): | ||
def __init__(self, name: str = 'uniqueness_check'): | ||
self.name = name | ||
|
||
def __call__(self, task: UniquenessCheckTask): | ||
to_add = dict() | ||
new_inds = [] | ||
for ind in task.generation: | ||
descriptive_id = ind.graph.descriptive_id | ||
if descriptive_id not in task.repo and descriptive_id not in to_add: | ||
to_add[descriptive_id] = True | ||
new_inds.append(ind) | ||
|
||
if to_add: | ||
task.repo.update(to_add) | ||
|
||
if new_inds: | ||
task.generation = new_inds | ||
task.status = TaskStatusEnum.SUCCESS | ||
return [task] | ||
|
||
task.status = TaskStatusEnum.FAIL | ||
return [task] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters