Skip to content
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

Refactor pipeline generation as builder #509 #597

Merged
merged 17 commits into from
Mar 22, 2022
Merged

Conversation

gkirgizov
Copy link
Collaborator

Refactor Assumptions Pipeline building process

Primary changes:

  • Extract TaskAssumptions as a kind of data-class containing actual readable assumptions.
  • Extract PreprocessingBuilder which is almost independent of the task. Handles gaps and categorical data.
  • PrimaryAssumptionsBuilder handles case of InputData, logger and available operations.
  • MultiModalData assumptions case is reduced to InputData case. Can now be easily customized if needed. Handled by MultiModalAssumptionsBuilder. In principle, can be also extended to handle available operations mechanics.
  • Actual pipeline building is handled by PipelineBuilder underneath. It's independent, all other logic is built on top. So it can be used elsewhere for somewhat shorter construction of pipelines.

@gkirgizov gkirgizov requested a review from Dreamlone March 15, 2022 16:01
@gkirgizov gkirgizov self-assigned this Mar 15, 2022
@pep8speaks
Copy link

pep8speaks commented Mar 15, 2022

Hello @gkirgizov! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-03-22 11:03:46 UTC

Copy link
Collaborator

@Dreamlone Dreamlone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы предложил все .py файлы отвечающие за построение начальных приближений вынести в отдельный модуль в api, - что-то вроде такого
image

Comment on lines 28 to 29
def pipeline_contains_one(pipeline: Pipeline, op: OpT) -> bool:
def is_the_op(node: Node):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше в нотации писать, что op operation_name: str

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это же относится и к другим сокращениям) Расширь их тоже плиз

Comment on lines 44 to 45
def get_suitable_operations_for_task(task_type: TaskTypesEnum, data_type: DataTypesEnum, repo='model'):
return OperationTypesRepository(repo).suitable_operation(task_type=task_type, data_type=data_type)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мб тут можно переиспользовать operations_for_task из fedot/api/help.py, или get_operations_for_task из fedot/core/repository/operation_types_repository.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этих методах не указывается data_type параметр, что, вероятно, повлияет на результат. Да и все-таки это прямое использование публичного api репозитория, не вижу чего-то криминального в этом. Но, конечно, могу чего-то не знать.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ок, убедил
Ещё тут опишусь: пожалуйста, не помечай треды как решенные, мне так тяжело сообразить что в итоге было изменено и когда (могу запутаться) - я сам их помечу как resolved, когда буду просматривать код второй раз или когда буду лазить по коммитам, оставленным в комментариях
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, ок, без проблем. Отмечал, чтобы самому не запутаться, что поправил, а что нет.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, ок, без проблем. Отмечал, чтобы самому не запутаться, что поправил, а что нет.

Ты простой оставляй коммент по каждому, тогда будет легко понять что done а что нет.

@gkirgizov
Copy link
Collaborator Author

gkirgizov commented Mar 16, 2022

Я бы предложил все .py файлы отвечающие за построение начальных приближений вынести в отдельный модуль в api, - что-то вроде такого image

Насчет этого -- сейчас остался только assumptions_builder.py & pipeline_builder.py. (Я дропнул легаси и initial_assumptions.) Второй по логике не относится к assumptions, а как раз скорее api_utils. Выносить же один файл, наверное, нет смысла. Согласны?

@nicl-nno
Copy link
Collaborator

Второй по логике не относится к assumptions, а как раз скорее api_utils

Может PIpelineBuilder его отправить вообще в Pipelines? Он же не только в API может быть применен

@gkirgizov
Copy link
Collaborator Author

Второй по логике не относится к assumptions, а как раз скорее api_utils

Может PIpelineBuilder его отправить вообще в Pipelines? Он же не только в API может быть применен

Вот да, мне тоже кажется, что ему где-то еще место. Перенесу в Pipelines.

@codecov
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #597 (95a8175) into master (30945d6) will increase coverage by 0.41%.
The diff coverage is 93.75%.

❗ Current head 95a8175 differs from pull request most recent head b97359a. Consider uploading reports for the commit b97359a to get more accurate results

@@            Coverage Diff             @@
##           master     #597      +/-   ##
==========================================
+ Coverage   86.23%   86.65%   +0.41%     
==========================================
  Files         145      149       +4     
  Lines       10959    11080     +121     
==========================================
+ Hits         9451     9601     +150     
+ Misses       1508     1479      -29     
Impacted Files Coverage Δ
...edot/api/api_utils/assumptions/task_assumptions.py 80.76% <80.76%> (ø)
...dot/api/api_utils/assumptions/operations_filter.py 94.73% <94.73%> (ø)
...t/api/api_utils/assumptions/assumptions_builder.py 95.40% <95.40%> (ø)
fedot/core/pipelines/pipeline_builder.py 97.26% <97.26%> (ø)
fedot/api/api_utils/api_composer.py 78.28% <100.00%> (ø)
...api/api_utils/assumptions/preprocessing_builder.py 100.00% <100.00%> (ø)
fedot/api/main.py 78.73% <100.00%> (+0.12%) ⬆️
...re/serializers/coders/opt_history_serialization.py 36.36% <0.00%> (-3.64%) ⬇️
fedot/core/optimisers/graph.py 90.98% <0.00%> (-0.62%) ⬇️
fedot/core/pipelines/template.py 85.95% <0.00%> (-0.42%) ⬇️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30945d6...b97359a. Read the comment docs.

@Dreamlone
Copy link
Collaborator

Насчет этого -- сейчас остался только assumptions_builder.py & pipeline_builder.py. (Я дропнул легаси и initial_assumptions.) Второй по логике не относится к assumptions, а как раз скорее api_utils. Выносить же один файл, наверное, нет смысла. Согласны?

В данном случае с вашими с Колей комментариями согласен. Просто на будущее - я бы хотел взять курс на растаскивание api_utils на отдельные субмодули в рамках большого и структурированного API в ближайшее время (понятно, что не к этому PR). Потому что API заметно усложнился с того момента, как появился "api_utils". Можно будет его потом как-то более прозрачно структурировать, чем надежный подход "всё в кучу"


@staticmethod
def for_task(task: Task):
task2assumptions = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай без цифр лучше обойдемся без необходимости)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это ж сокращение в смысле task_to_assumptions
но ок, переименую

Copy link
Collaborator

@Dreamlone Dreamlone Mar 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай я ещё поиграю в душного деда - вместо task_to_assumptions лучше подошло бы assumption_by_task, потому что ниже ты получаешь подходящего строителя именно по имеющейся задаче

@gkirgizov gkirgizov requested review from Dreamlone and nicl-nno March 17, 2022 13:32
@gkirgizov gkirgizov requested a review from Dreamlone March 18, 2022 07:53
@gkirgizov gkirgizov force-pushed the 509-pipeline-builder branch from aa9f3a5 to ebe1c26 Compare March 18, 2022 14:39
@gkirgizov gkirgizov force-pushed the 509-pipeline-builder branch from ebe1c26 to 95a8175 Compare March 21, 2022 14:13
@gkirgizov gkirgizov requested a review from Dreamlone March 21, 2022 15:05
Copy link
Collaborator

@Dreamlone Dreamlone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Всё кул, осталось сделать rebase на мастер ветку и можно мержить

@gkirgizov gkirgizov force-pushed the 509-pipeline-builder branch from 95a8175 to 17b529b Compare March 21, 2022 17:04
@Dreamlone
Copy link
Collaborator

А претензии PEP8 можешь поправить ещё плиз?

Extract TaskAssumptions as a kind of data-class containing actual readable assumptions.
Extract PreprocessingBuilder which is almost independent of the task. Handles gaps and categorical data.
PrimaryAssumptionsBuilder handles case of InputData, logger and available operations.
MultiModalData assumptions case is reduced to InputData case. Can now be easily customized if needed. Also now handles available operations.
Actual Pipeline building is handled by PipelineBuilder underneath.
For case when SupplementaryData has no computed column_types
Also fix review comments in builders, rename interfaces
Also fix tests according to review comments. Restructure them a bit.
This also changes semantics of PipelineBuilder
from 'one-shot' to reusable, as they now return copies.

This change is required for simplifying TaskAssumptions.
- In case when no PipelineBuilder satisfies
OperationsFilter -- return only a single fallback
alternative instead of many.
- Add dependency on OperationTypesRepository to
TaskAssumptions to build valid fallback pipeline
in TSForecastingAssumptions.
@gkirgizov gkirgizov force-pushed the 509-pipeline-builder branch from 17b529b to b97359a Compare March 22, 2022 11:03
@gkirgizov gkirgizov merged commit e0ba2f0 into master Mar 22, 2022
@nicl-nno nicl-nno deleted the 509-pipeline-builder branch November 23, 2022 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants