Skip to content

Commit 5a8f2ef

Browse files
committed
1 parent 0bc7c59 commit 5a8f2ef

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

fedot/api/api_utils/api_composer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from golem.core.log import default_log
66
from golem.core.optimisers.opt_history_objects.opt_history import OptHistory
77
from golem.core.tuning.simultaneous import SimultaneousTuner
8+
from golem.core.tuning.tuner_interface import BaseTuner
89

910
from fedot.api.api_utils.assumptions.assumptions_handler import AssumptionsHandler
1011
from fedot.api.api_utils.params import ApiParams
@@ -72,11 +73,8 @@ def obtain_model(self, train_data: InputData) -> Tuple[Pipeline, Sequence[Pipeli
7273
fitted_assumption
7374
)
7475
if with_tuning:
75-
best_pipeline = self.tune_final_pipeline(train_data, best_pipeline)
76-
if gp_composer.history:
77-
adapter = self.params.graph_generation_params.adapter
78-
gp_composer.history.tuning_result = adapter.adapt(best_pipeline)
79-
# enforce memory cleaning
76+
best_pipeline = self.tune_final_pipeline(train_data, best_pipeline, gp_composer.history)
77+
8078
gc.collect()
8179

8280
self.log.message('Model generation finished')
@@ -142,7 +140,8 @@ def compose_pipeline(self, train_data: InputData, initial_assumption: Sequence[P
142140
best_pipeline = best_pipelines[0] if isinstance(best_pipelines, Sequence) else best_pipelines
143141
return best_pipeline, best_pipeline_candidates, gp_composer
144142

145-
def tune_final_pipeline(self, train_data: InputData, pipeline_gp_composed: Pipeline) -> Pipeline:
143+
def tune_final_pipeline(self, train_data: InputData, pipeline_gp_composed: Pipeline,
144+
history: Optional[OptHistory]) -> Tuple[BaseTuner, Pipeline]:
146145
""" Launch tuning procedure for obtained pipeline by composer """
147146
timeout_for_tuning = abs(self.timer.determine_resources_for_tuning()) / 60
148147
tuner = (TunerBuilder(self.params.task)
@@ -152,6 +151,7 @@ def tune_final_pipeline(self, train_data: InputData, pipeline_gp_composed: Pipel
152151
.with_timeout(datetime.timedelta(minutes=timeout_for_tuning))
153152
.with_eval_time_constraint(self.params.composer_requirements.max_graph_fit_time)
154153
.with_requirements(self.params.composer_requirements)
154+
.with_history(history)
155155
.build(train_data))
156156

157157
if self.timer.have_time_for_tuning():

fedot/core/pipelines/tuning/tuner_builder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import timedelta
2-
from typing import Type, Union, Iterable, Sequence
2+
from typing import Iterable, Sequence, Type, Union
33

44
from golem.core.tuning.optuna_tuner import OptunaTuner
55
from golem.core.tuning.simultaneous import SimultaneousTuner
@@ -33,6 +33,7 @@ def __init__(self, task: Task):
3333
self.eval_time_constraint = None
3434
self.additional_params = {}
3535
self.adapter = PipelineAdapter()
36+
self.history = None
3637

3738
def with_tuner(self, tuner: Type[BaseTuner]):
3839
self.tuner_class = tuner
@@ -89,6 +90,10 @@ def with_adapter(self, adapter):
8990
self.adapter = adapter
9091
return self
9192

93+
def with_history(self, history):
94+
self.history = history
95+
return self
96+
9297
def with_additional_params(self, **parameters):
9398
self.additional_params.update(parameters)
9499
return self

0 commit comments

Comments
 (0)