55from golem .core .log import default_log
66from golem .core .optimisers .opt_history_objects .opt_history import OptHistory
77from golem .core .tuning .simultaneous import SimultaneousTuner
8+ from golem .core .tuning .tuner_interface import BaseTuner
89
910from fedot .api .api_utils .assumptions .assumptions_handler import AssumptionsHandler
1011from 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 ():
0 commit comments