From 6ae6c98d65c7eea141e834312c5722cdee0f398f Mon Sep 17 00:00:00 2001 From: Sergey Kasyanov Date: Fri, 28 Jul 2023 16:33:33 +0300 Subject: [PATCH] Fix random list elements order in case of set -> list transform Model become less random but it is not full solution --- fedot/api/api_utils/presets.py | 2 +- fedot/core/data/multi_modal.py | 2 +- .../data_operations/categorical_encoders.py | 2 +- fedot/core/operations/operation.py | 2 +- fedot/core/pipelines/pipeline_node_factory.py | 4 ++-- fedot/core/pipelines/verification_rules.py | 2 +- fedot/core/repository/pipeline_operation_repository.py | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fedot/api/api_utils/presets.py b/fedot/api/api_utils/presets.py index 72454a9ba0..f905b63087 100644 --- a/fedot/api/api_utils/presets.py +++ b/fedot/api/api_utils/presets.py @@ -82,7 +82,7 @@ def filter_operations_by_preset(self, data_type: Optional[DataTypesEnum] = None) filtered_operations = set(available_operations).difference(set(excluded_tree)) available_operations = list(filtered_operations) - return available_operations + return sorted(available_operations) @staticmethod def new_operations_without_heavy(excluded_operations, available_operations) -> list: diff --git a/fedot/core/data/multi_modal.py b/fedot/core/data/multi_modal.py index 6d7f617035..7e5301d234 100644 --- a/fedot/core/data/multi_modal.py +++ b/fedot/core/data/multi_modal.py @@ -198,7 +198,7 @@ def from_csv_time_series(cls, df = get_df_from_csv(file_path, delimiter, index_col, possible_idx_keywords, columns_to_use=columns_to_use) idx = df.index.to_numpy() if not columns_to_use: - columns_to_use = list(set(df.columns) - {index_col}) + columns_to_use = sorted(list(set(df.columns) - {index_col})) if is_predict: raise NotImplementedError( diff --git a/fedot/core/operations/evaluation/operation_implementations/data_operations/categorical_encoders.py b/fedot/core/operations/evaluation/operation_implementations/data_operations/categorical_encoders.py index 8d34a3b3c3..454ec49b22 100644 --- a/fedot/core/operations/evaluation/operation_implementations/data_operations/categorical_encoders.py +++ b/fedot/core/operations/evaluation/operation_implementations/data_operations/categorical_encoders.py @@ -180,7 +180,7 @@ def _apply_label_encoder(self, categorical_column: np.array, categorical_id: int encoder_classes = list(column_encoder.classes_) # If the column contains categories not previously encountered - for label in list(set(categorical_column)): + for label in sorted(list(set(categorical_column))): if label not in encoder_classes: encoder_classes.append(label) diff --git a/fedot/core/operations/operation.py b/fedot/core/operations/operation.py index 23314407e1..00ff6ca45f 100644 --- a/fedot/core/operations/operation.py +++ b/fedot/core/operations/operation.py @@ -194,7 +194,7 @@ def _eval_strategy_for_task(operation_type: str, current_task_type: TaskTypesEnu globally_compatible_task_types = compatible_task_types(current_task_type) globally_set = set(globally_compatible_task_types) - comp_types_acceptable_for_operation = list(set_acceptable_types.intersection(globally_set)) + comp_types_acceptable_for_operation = sorted(list(set_acceptable_types.intersection(globally_set))) if len(comp_types_acceptable_for_operation) == 0: raise ValueError(f'Operation {operation_type} can not be used as a part of {current_task_type}.') current_task_type = comp_types_acceptable_for_operation[0] diff --git a/fedot/core/pipelines/pipeline_node_factory.py b/fedot/core/pipelines/pipeline_node_factory.py index c422dafc5f..7ca26ad23c 100644 --- a/fedot/core/pipelines/pipeline_node_factory.py +++ b/fedot/core/pipelines/pipeline_node_factory.py @@ -54,8 +54,8 @@ def get_node(self, def _return_node(candidates) -> Optional[OptNode]: if not candidates: return None - return OptNode(content={'name': choice(candidates)}) + return OptNode(content={'name': choice(sorted(candidates))}) @staticmethod def filter_specific_candidates(candidates: list): - return list(filter(lambda x: not check_for_specific_operations(x), candidates)) + return sorted(list(filter(lambda x: not check_for_specific_operations(x), candidates))) diff --git a/fedot/core/pipelines/verification_rules.py b/fedot/core/pipelines/verification_rules.py index cfb02f480f..3e20cb0886 100644 --- a/fedot/core/pipelines/verification_rules.py +++ b/fedot/core/pipelines/verification_rules.py @@ -107,7 +107,7 @@ def has_no_data_flow_conflicts_in_ts_pipeline(pipeline: Pipeline): """ Function checks the correctness of connection between nodes """ task = Task(TaskTypesEnum.ts_forecasting) ts_models = get_operations_for_task(task=task, mode='model', tags=["non_lagged"]) - non_ts_models = list(set(get_operations_for_task(task=task, mode='model')).difference(set(ts_models))) + non_ts_models = sorted(list(set(get_operations_for_task(task=task, mode='model')).difference(set(ts_models)))) # Preprocessing not only for time series non_ts_data_operations = get_operations_for_task(task=task, diff --git a/fedot/core/repository/pipeline_operation_repository.py b/fedot/core/repository/pipeline_operation_repository.py index bc6780119e..2a9c1ef0b9 100644 --- a/fedot/core/repository/pipeline_operation_repository.py +++ b/fedot/core/repository/pipeline_operation_repository.py @@ -27,7 +27,7 @@ def from_available_operations(self, task: Task, preset: str, available_operations: List[str]): """ Initialize repository from available operations, task and preset """ operations_by_task_preset = OperationsPreset(task, preset).filter_operations_by_preset() - all_operations = list(set.intersection(set(operations_by_task_preset), set(available_operations))) + all_operations = sorted(list(set.intersection(set(operations_by_task_preset), set(available_operations)))) primary_operations, secondary_operations = \ self.divide_operations(all_operations, task) self.operations_by_keys = {'primary': primary_operations, 'secondary': secondary_operations} @@ -40,7 +40,7 @@ def get_operations(self, is_primary: bool) -> List[str]: def get_all_operations(self) -> List[str]: """ Get all pipeline operations with all keys """ - return list(itertools.chain(*self.operations_by_keys.values())) + return sorted(list(itertools.chain(*self.operations_by_keys.values()))) @staticmethod def divide_operations(available_operations, task): @@ -61,7 +61,7 @@ def divide_operations(available_operations, task): ts_primary_operations = ts_data_operations + ts_primary_models # Filter - remain only operations, which were in available ones - primary_operations = list(set(ts_primary_operations).intersection(available_operations)) + primary_operations = sorted(list(set(ts_primary_operations).intersection(available_operations))) secondary_operations = available_operations else: primary_operations = available_operations