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

Redesign Adapter subsystem #876

Merged
merged 82 commits into from
Oct 5, 2022
Merged

Redesign Adapter subsystem #876

merged 82 commits into from
Oct 5, 2022

Conversation

gkirgizov
Copy link
Collaborator

@gkirgizov gkirgizov commented Sep 13, 2022

Adaptation subsystem is refactored -- now it's more high-level and declarative, requiring less attention from developers.

Main changes:

  • It's possible to adapt functions that must work with Opt Graphs instead of adapting their arguments & return values.
    It works like this: adapt_func( f(Pipeline)->Pipeline ) => f'(OptGraph)->OptGraph
    That is, from the function that can work with domain graphs (e.g. Pipeline) we get a function that can work with OptGraphs (it automatically adapts its arguments and return type).
  • Ad-hoc check for whether the function must be adapted (like isinstance(mutation_type, Callable)) is dropped -- it is determined automatically inside BaseAdapter.
  • Additional functions are introduced for adapting/restoring whole populations: adapt_population
  • Functions that shouldn't be adapted can be marked with a special decorator @register_native -- these functions are supposed to work with OptGraph directly.
  • Added separate unit tests for adapters

See doc-comment of the new class AdaptRegistry for more detailed description.

Aimed at #742

@pep8speaks
Copy link

pep8speaks commented Sep 13, 2022

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

Line 10:1: F401 'fedot.core.adapter.AdaptRegistry' imported but unused

Line 1:1: F401 '.adapter.BaseOptimizationAdapter' imported but unused
Line 1:1: F401 '.adapter.DirectAdapter' imported but unused
Line 2:1: F401 '.adapt_registry.AdaptRegistry' imported but unused
Line 2:1: F401 '.adapt_registry.register_native' imported but unused

Line 3:1: F401 'fedot.core.adapter.AdaptRegistry' imported but unused

Line 2:1: F401 'typing.Any' imported but unused

Line 3:1: F401 'typing.Any' imported but unused
Line 3:1: F401 'typing.Generic' imported but unused

Line 2:1: F401 'typing.Callable' imported but unused

Line 206:16: E126 continuation line over-indented for hanging indent

Line 6:1: F401 'fedot.core.optimisers.gp_comp.individual.Individual' imported but unused
Line 8:1: F401 'fedot.core.pipelines.node.Node' imported but unused
Line 10:1: F401 'fedot.core.pipelines.template.PipelineTemplate' imported but unused

Line 2:1: F401 'multiprocessing' imported but unused

Line 8:1: F401 'fedot.core.optimisers.gp_comp.individual.Individual' imported but unused

Line 4:1: F401 'typing.Sequence' imported but unused

Line 1:1: F401 'copy.deepcopy' imported but unused
Line 4:1: F401 'fedot.core.adapter.AdaptRegistry' imported but unused
Line 48:29: W503 line break before binary operator

Line 200:35: F541 f-string is missing placeholders

Line 3:1: F401 'typing.Union' imported but unused

Line 9:1: F401 'fedot.core.optimisers.adapters.PipelineAdapter' imported but unused

Line 4:1: F403 'from fedot.core.pipelines.verification_rules import *' used; unable to detect undefined names
Line 8:5: F405 'has_correct_operation_positions' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 9:5: F405 'has_primary_nodes' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 10:5: F405 'has_final_operation_as_model' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 11:5: F405 'has_final_operation_as_model' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 12:5: F405 'has_no_conflicts_with_data_flow' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 13:5: F405 'has_correct_data_connections' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules

Line 156:9: E126 continuation line over-indented for hanging indent
Line 182:9: E126 continuation line over-indented for hanging indent
Line 196:9: F841 local variable 'mutated_dom_graph' is assigned to but never used
Line 197:38: F841 local variable 'e' is assigned to but never used
Line 198:9: F841 local variable 'mutated_graph' is assigned to but never used

Line 5:1: F403 'from fedot.core.pipelines.verification_rules import *' used; unable to detect undefined names
Line 9:5: F405 'has_correct_operation_positions' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 10:5: F405 'has_primary_nodes' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 11:5: F405 'has_no_conflicts_with_data_flow' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules
Line 12:5: F405 'has_correct_data_connections' may be undefined, or defined from star imports: fedot.core.pipelines.verification_rules

Line 2:1: F401 'pathlib' imported but unused
Line 6:1: F401 'pytest' imported but unused
Line 13:1: F401 'fedot.core.log.Log' imported but unused
Line 18:1: F401 'fedot.core.utils.default_fedot_data_dir' imported but unused

Line 1:1: F401 'typing.Tuple' imported but unused
Line 1:1: F401 'typing.Iterable' imported but unused

Comment last updated at 2022-09-13 14:29:43 UTC

@gkirgizov gkirgizov added composer Related to GP-composition algorithm architecture (re)design of existing or new framework subsystem refactoring labels Sep 13, 2022
@gkirgizov gkirgizov changed the title 608 adapters Redesign Adapter subsystem Sep 13, 2022
@gkirgizov gkirgizov force-pushed the 608-adapters branch 3 times, most recently from 21a0c8c to 32d95ee Compare September 14, 2022 13:54
@gkirgizov
Copy link
Collaborator Author

@pep8speaks pls update youself

@gkirgizov gkirgizov marked this pull request as ready for review September 19, 2022 09:52
@codecov
Copy link

codecov bot commented Sep 19, 2022

Codecov Report

Merging #876 (66d1232) into master (55e6528) will decrease coverage by 0.02%.
The diff coverage is 96.05%.

@@            Coverage Diff             @@
##           master     #876      +/-   ##
==========================================
- Coverage   88.01%   87.98%   -0.03%     
==========================================
  Files         198      201       +3     
  Lines       13479    13528      +49     
==========================================
+ Hits        11863    11903      +40     
- Misses       1616     1625       +9     
Impacted Files Coverage Δ
...ore/optimisers/gp_comp/operators/regularization.py 54.76% <0.00%> (-1.06%) ⬇️
...timisers/gp_comp/pipeline_composer_requirements.py 95.23% <ø> (ø)
fedot/core/pipelines/pipeline.py 96.20% <ø> (-0.05%) ⬇️
fedot/core/optimisers/opt_history.py 78.72% <80.00%> (+1.58%) ⬆️
fedot/core/dag/graph.py 78.31% <87.50%> (+1.09%) ⬆️
...dot/core/optimisers/gp_comp/operators/crossover.py 95.00% <92.30%> (+4.41%) ⬆️
fedot/core/adapter/adapter.py 94.28% <94.28%> (ø)
fedot/core/adapter/adapt_registry.py 94.59% <94.59%> (ø)
fedot/api/api_utils/api_composer.py 98.83% <100.00%> (+0.04%) ⬆️
fedot/core/adapter/__init__.py 100.00% <100.00%> (ø)
... and 22 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@gkirgizov gkirgizov force-pushed the 608-adapters branch 3 times, most recently from 9f5f286 to 25a1ad7 Compare September 20, 2022 15:06
Copy link
Collaborator

@nicl-nno nicl-nno left a comment

Choose a reason for hiding this comment

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

Предлагаю сразу на основе описания PR-а сделать заметку в документации, посвященную именно адаптерам. Можно со ссылками на докстринги (т.к. они довольно подробные), которые нужно почитать.

fedot/core/adapter/adapter.py Outdated Show resolved Hide resolved
fedot/core/adapter/adapter.py Outdated Show resolved Hide resolved
fedot/api/api_utils/api_composer.py Show resolved Hide resolved
raise NotImplementedError()

@abstractmethod
def _restore(self, opt_graph: OptGraph, metadata: Optional[Dict[str, Any]] = None) -> DomainStructureType:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Может тогда этот метод назвать restore_graph или restore_single?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Аналогично с _adapt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops, не заметил твой коммент перед мерджем.
вообще, это непубличный метод, и его не предполагается вызывать извне. это скорее ядро реализации метода, для определения в потомках.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture (re)design of existing or new framework subsystem composer Related to GP-composition algorithm refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants