-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tuning history to OptHistory #228
base: main
Are you sure you want to change the base?
Changes from 6 commits
2656a42
d2eb0f2
7068a0d
be1457e
2b21d96
d9d6c32
03915f1
5beeb22
ae5b242
e98ec48
c19ebbb
56a51f9
1c7ef13
1c42b3f
c286828
ff5b6e6
02e3ecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,16 @@ | |
import os | ||
import shutil | ||
from pathlib import Path | ||
from typing import Any, Dict, List, Optional, Sequence, Union, TYPE_CHECKING | ||
from typing import Any, Dict, List, Optional, Sequence, TYPE_CHECKING, Union | ||
|
||
from golem.core.log import default_log | ||
from golem.core.optimisers.objective.objective import ObjectiveInfo | ||
from golem.core.optimisers.opt_history_objects.generation import Generation | ||
|
||
from golem.core.paths import default_data_dir | ||
from golem.serializers.serializer import default_load, default_save | ||
from golem.visualisation.opt_viz import OptHistoryVisualizer | ||
|
||
if TYPE_CHECKING: | ||
from golem.core.dag.graph import Graph | ||
from golem.core.optimisers.opt_history_objects.individual import Individual | ||
|
||
|
||
|
@@ -36,8 +34,7 @@ def __init__(self, | |
default_save_dir: Optional[os.PathLike] = None): | ||
self._objective = objective or ObjectiveInfo() | ||
self._generations: List[Generation] = [] | ||
self.archive_history: List[List[Individual]] = [] | ||
self._tuning_result: Optional[Graph] = None | ||
self.evolution_best_archive: List[List[Individual]] = [] | ||
|
||
# init default save directory | ||
if default_save_dir: | ||
|
@@ -61,8 +58,8 @@ def add_to_history(self, individuals: Sequence[Individual], generation_label: Op | |
generation = Generation(individuals, self.generations_count, generation_label, generation_metadata) | ||
self.generations.append(generation) | ||
|
||
def add_to_archive_history(self, individuals: Sequence[Individual]): | ||
self.archive_history.append(list(individuals)) | ||
def add_to_evolution_best_archive(self, individuals: Sequence[Individual]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Может сделать единый метод, просто передавать в параметрах нужную метку? |
||
self.evolution_best_archive.append(list(individuals)) | ||
|
||
def to_csv(self, save_dir: Optional[os.PathLike] = None, file: os.PathLike = 'history.csv'): | ||
save_dir = save_dir or self._default_save_dir | ||
|
@@ -219,27 +216,24 @@ def initial_assumptions(self) -> Optional[Generation]: | |
return gen | ||
|
||
@property | ||
def final_choices(self) -> Optional[Generation]: | ||
def generations_count(self) -> int: | ||
return len(self.generations) | ||
|
||
@property | ||
def evolution_results(self) -> Optional[Generation]: | ||
if not self.generations: | ||
return None | ||
for gen in reversed(self.generations): | ||
if gen.label == 'final_choices': | ||
if gen.label == 'evolution_results': | ||
return gen | ||
|
||
@property | ||
def generations_count(self) -> int: | ||
return len(self.generations) | ||
|
||
@property | ||
def tuning_result(self): | ||
if hasattr(self, '_tuning_result'): | ||
return self._tuning_result | ||
else: | ||
def tuning_result(self) -> Optional[Generation]: | ||
if not self.generations: | ||
return None | ||
|
||
@tuning_result.setter | ||
def tuning_result(self, val): | ||
self._tuning_result = val | ||
for gen in reversed(self.generations): | ||
if gen.label == 'tuning_result': | ||
return gen | ||
|
||
@property | ||
def generations(self): | ||
|
@@ -270,8 +264,7 @@ def lighten_history(history: OptHistory) -> OptHistory: | |
without excessive memory usage. """ | ||
light_history = OptHistory() | ||
light_history._generations = \ | ||
[Generation(iterable=gen, generation_num=i) for i, gen in enumerate(history.archive_history)] | ||
light_history.archive_history = history.archive_history | ||
[Generation(iterable=gen, generation_num=i) for i, gen in enumerate(history.evolution_best_archive)] | ||
light_history.evolution_best_archive = history.evolution_best_archive | ||
light_history._objective = history.objective | ||
light_history._tuning_result = history.tuning_result | ||
return light_history |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List, Dict, Generic, Tuple, Any, Optional | ||
from typing import Any, Dict, Generic, List, Optional, Tuple | ||
|
||
import numpy as np | ||
from iOpt.method.listener import ConsoleFullOutputListener | ||
from iOpt.problem import Problem | ||
from iOpt.solver import Solver | ||
from iOpt.solver_parametrs import SolverParameters | ||
from iOpt.trial import Point, FunctionValue | ||
from iOpt.trial import FunctionValue, Point | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Почему в этом тюнере не добавлена возможность сохранить в историю? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Пока что сохраняются изначальный и финальный графы через initial_check и final_check. Но тут можно прокинуть в GolemProblem функцию для сохранения промежуточных результатов. Пожалуй, так и сделаю. |
||
|
||
from golem.core.adapter import BaseOptimizationAdapter | ||
from golem.core.optimisers.graph import OptGraph | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я не совсем понимаю зачем нужно такое переименование?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я пока не реализовал ведение archive_history для тюнинга, потому что для оптимизации его ведёт фронт Парето в составе оптимизатора. Поэтому название поля явно отражает, что оно относится к истории эволюции, но не тюнинга.
Честно, не знаю, как тут лучше поступить.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну точно не нужна отсылка к эволюции, для большей абстрактности.
Мне кажется идея что archive_history это основная история, а для файн-тюнинга - отдельная, будет доступной пользователю.