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: Isolate logic that finds next runnable component waiting for input #7880

Merged
merged 6 commits into from
Jun 18, 2024

Conversation

silvanocerza
Copy link
Contributor

@silvanocerza silvanocerza commented Jun 17, 2024

Related Issues

Part of #7614.

Proposed Changes:

This PR isolates the logic that moves Components from waiting_for_input to to_run queue when to_run is empty and waiting_for_input is not.

How did you test it?

I added unit tests and ran tests locally.

Notes for the reviewer

There's some formatting changes too as we changed the default formatted from black to ruff.

Checklist

@silvanocerza silvanocerza added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Jun 17, 2024
@silvanocerza silvanocerza self-assigned this Jun 17, 2024
@silvanocerza silvanocerza requested a review from a team as a code owner June 17, 2024 14:11
@silvanocerza silvanocerza requested review from masci and removed request for a team June 17, 2024 14:11
@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9549247852

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 51 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.09%) to 89.837%

Files with Coverage Reduction New Missed Lines %
core/pipeline/base.py 25 93.16%
core/pipeline/pipeline.py 26 65.14%
Totals Coverage Status
Change from base Build 9544797751: 0.09%
Covered Lines: 6930
Relevant Lines: 7714

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9549480203

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 51 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.09%) to 89.837%

Files with Coverage Reduction New Missed Lines %
core/pipeline/base.py 25 93.16%
core/pipeline/pipeline.py 26 65.14%
Totals Coverage Status
Change from base Build 9544797751: 0.09%
Covered Lines: 6930
Relevant Lines: 7714

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9549815154

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 51 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.09%) to 89.837%

Files with Coverage Reduction New Missed Lines %
core/pipeline/base.py 25 93.16%
core/pipeline/pipeline.py 26 65.14%
Totals Coverage Status
Change from base Build 9544797751: 0.09%
Covered Lines: 6930
Relevant Lines: 7714

💛 - Coveralls

haystack/core/pipeline/base.py Outdated Show resolved Hide resolved
for other_name, other_comp in waiting_for_input:
if name == other_name:
continue
there_are_only_lazy_variadics &= (
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can rewrite this check to break early if a non(-lazy)-variadic component is encountered.

Comment on lines 910 to 911
is_variadic = any(socket.is_variadic for socket in comp.__haystack_input__._sockets_dict.values()) # type: ignore
if is_variadic and not comp.__haystack_is_greedy__: # type: ignore[attr-defined]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's extract this into a nested helper function.

is_variadic = any(socket.is_variadic for socket in comp.__haystack_input__._sockets_dict.values()) # type: ignore
if is_variadic and not comp.__haystack_is_greedy__: # type: ignore[attr-defined]
there_are_only_lazy_variadics = True
for other_name, other_comp in waiting_for_input:
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the looks of this, we only need to perform this check once. Let's move it outside of the outer loop.

)
if has_only_defaults:
there_are_only_components_with_defaults = True
for other_name, other_comp in waiting_for_input:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above - Doesn't look like it needs to be recalculated for every component.

Comment on lines 942 to 945
there_are_only_components_with_defaults &= all(
not s.is_mandatory
for s in other_comp.__haystack_input__._sockets_dict.values() # type: ignore
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above - We can break early.

Comment on lines 952 to 959
if input_socket.is_mandatory and input_socket.name not in inputs_by_component[name]:
has_enough_inputs = False
break
if input_socket.is_mandatory:
continue

if input_socket.name not in inputs_by_component[name]:
inputs_by_component[name][input_socket.name] = input_socket.default_value
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rewrite this to just use a single if input_socket.name not in inputs_by_component[name]: - break if it's mandatory, copy default value otherwise.

@silvanocerza
Copy link
Contributor Author

I updated the comment.
Though I won't change the logic as is outside the scope of the PR and further refactoring will be made in following PRs.

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9562857219

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 55 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.839%

Files with Coverage Reduction New Missed Lines %
evaluation/eval_run_result.py 4 92.42%
core/pipeline/base.py 25 93.16%
core/pipeline/pipeline.py 26 65.14%
Totals Coverage Status
Change from base Build 9544797751: 0.1%
Covered Lines: 6932
Relevant Lines: 7716

💛 - Coveralls

@silvanocerza
Copy link
Contributor Author

After some discussion with @shadeMe we decided to change the refactoring approach a bit.
I'll make the changes suggested above and go from there.

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9565856215

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 55 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.868%

Files with Coverage Reduction New Missed Lines %
evaluation/eval_run_result.py 4 92.42%
core/pipeline/base.py 25 93.33%
core/pipeline/pipeline.py 26 65.14%
Totals Coverage Status
Change from base Build 9544797751: 0.1%
Covered Lines: 6945
Relevant Lines: 7728

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566408308

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 48 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.3%) to 89.995%

Files with Coverage Reduction New Missed Lines %
evaluation/eval_run_result.py 4 92.42%
core/pipeline/pipeline.py 19 74.31%
core/pipeline/base.py 25 93.3%
Totals Coverage Status
Change from base Build 9544797751: 0.3%
Covered Lines: 6953
Relevant Lines: 7726

💛 - Coveralls

@silvanocerza silvanocerza merged commit 15ee622 into main Jun 18, 2024
14 checks passed
@silvanocerza silvanocerza deleted the refactor-pipeline-run branch June 18, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-for-release-notes PRs with this flag won't be included in the release notes. topic:core topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants