Skip to content

Commit

Permalink
Update unit test workflow to include Python 3.11 and refactor ApiMana…
Browse files Browse the repository at this point in the history
…ger initialization
  • Loading branch information
technocreep committed Nov 8, 2024
1 parent 1175397 commit 3583b92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/poetry_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: [3.9, '3.10']
python-version: [3.9, '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
65 changes: 30 additions & 35 deletions fedot_ind/api/utils/api_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,31 @@

class ApiManager:
def __init__(self, **kwargs):
self.null_state_object()
self.user_config_object(kwargs)
self.path_object(kwargs)
self.industrial_config_object(kwargs)
self.industrial_api_object()
self.industrial_strategy_params = kwargs.get('industrial_strategy_params', {})
self.logger = logging.getLogger('FedotIndustrialAPI')
self.backend_method = kwargs.get('backend', 'cpu')
self.task_params = kwargs.get('task_params', {})

self.industrial_strategy = kwargs.get('industrial_strategy', None)
self.path_to_composition_results = kwargs.get('history_dir', None)
self.output_folder = kwargs.get('output_folder', None)

def null_state_object(self):
self.solver = None
self.is_default_fedot_context = None
self.predicted_labels = None
self.predicted_probs = None
self.predict_data = None
self.target_encoder = None
self.is_finetuned = False
self.predict_data = None
self.solver = None

def user_config_object(self, kwargs):
self.output_folder = kwargs.get('output_folder', None)
self.industrial_strategy_params = kwargs.get(
'industrial_strategy_params', {})
self.industrial_strategy = kwargs.get('industrial_strategy', None)
self.path_to_composition_results = kwargs.get('history_dir', None)
self.backend_method = kwargs.get('backend', 'cpu')
self.task_params = kwargs.get('task_params', {})
self.create_path(kwargs)
self.industrial_config_object(kwargs)
self.industrial_api_object()

def get(self, key):
return self.config_dict(key)

def path_object(self, kwargs):
def create_path(self, kwargs):
# create dirs with results
if self.path_to_composition_results is None:
prefix = './composition_results'
Expand All @@ -51,30 +52,27 @@ def path_object(self, kwargs):
# create dirs with results
if self.output_folder is None:
self.output_folder = default_path_to_save_results
Path(self.output_folder).mkdir(parents=True, exist_ok=True)
else:
Path(self.output_folder).mkdir(parents=True, exist_ok=True)
del kwargs['output_folder']
Path(self.output_folder).mkdir(parents=True, exist_ok=True)

# init logger
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s: %(name)s - %(message)s',
handlers=[
logging.FileHandler(
Path(
self.output_folder) /
'log.log'),
logging.StreamHandler()])
self.logger = logging.getLogger('FedotIndustrialAPI')
logging.FileHandler(Path(self.output_folder) / 'log.log'),
logging.StreamHandler()
]
)

def industrial_config_object(self, kwargs):
# map Fedot params to Industrial params
self.config_dict = kwargs
# self.config_dict['history_dir'] = prefix
self.preset = kwargs.get('preset', self.config_dict['problem'])
self.config_dict['available_operations'] = kwargs.get('available_operations',
default_industrial_availiable_operation(self.preset))
self.config_dict['available_operations'] = kwargs.get(
'available_operations',
default_industrial_availiable_operation(self.preset)
)
self.is_default_fedot_context = self.preset.__contains__('tabular')
self.is_regression_task_context = self.config_dict['problem'] in ['ts_forecasting', 'regression']
self.config_dict['cv_folds'] = kwargs.get('cv_folds', 3)
Expand All @@ -87,12 +85,10 @@ def industrial_config_object(self, kwargs):
either(left_function=fedot_init_assumptions,
right_function=fedot_init_assumptions)

self.config_dict['use_input_preprocessing'] = kwargs.get(
'use_input_preprocessing', False)
self.config_dict['use_input_preprocessing'] = kwargs.get('use_input_preprocessing', False)

if self.task_params is not None and self.config_dict['problem'] == 'ts_forecasting':
self.config_dict['task_params'] = TsForecastingParams(
forecast_length=self.task_params['forecast_length'])
self.config_dict['task_params'] = TsForecastingParams(forecast_length=self.task_params['forecast_length'])
self.__init_experiment_setup()

def industrial_api_object(self):
Expand All @@ -115,8 +111,7 @@ def industrial_api_object(self):
def __init_experiment_setup(self):
self.logger.info('Initialising experiment setup')

industrial_params = set(self.config_dict.keys()) - \
set(FEDOT_API_PARAMS.keys())
industrial_params = set(self.config_dict.keys()) - set(FEDOT_API_PARAMS.keys())
for param in industrial_params:
self.config_dict.pop(param, None)

Expand Down

0 comments on commit 3583b92

Please sign in to comment.