-
Notifications
You must be signed in to change notification settings - Fork 313
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
Support bound inputs for array node tasks #3185
Merged
+162
−1
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3220eae
support bound inputs in array node map tasks
pvditt d22ad13
clean up
pvditt dc595a1
clean up
pvditt 89c5895
temp set error until changes are upstreamed
pvditt 7af739a
Revert "temp set error until changes are upstreamed"
pvditt 9252ce8
test
pvditt 31a7ee2
test
pvditt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ def __init__( | |
min_successes: Optional[int] = None, | ||
min_success_ratio: Optional[float] = None, | ||
bound_inputs: Optional[Set[str]] = None, | ||
bound_inputs_values: Optional[Dict[str, Any]] = None, | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -49,6 +50,7 @@ def __init__( | |
:param min_successes: The minimum number of successful executions | ||
:param min_success_ratio: The minimum ratio of successful executions | ||
:param bound_inputs: The set of inputs that should be bound to the map task | ||
:param bound_inputs_values: Inputs that are bound to the array node and will not be mapped over | ||
:param kwargs: Additional keyword arguments to pass to the base class | ||
""" | ||
self._partial = None | ||
|
@@ -78,10 +80,21 @@ def __init__( | |
if n_outputs > 1: | ||
raise ValueError("Only tasks with a single output are supported in map tasks.") | ||
|
||
# Note, bound_inputs are passed in during run time when executing the task | ||
# so both values shouldn't be set at the same time | ||
if bound_inputs and bound_inputs_values: | ||
if bound_inputs != set(bound_inputs_values): | ||
raise ValueError("bound_inputs and bound_inputs_values should have the same keys if both set") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we include a test that triggers this error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
self._bound_inputs: Set[str] = bound_inputs or set(bound_inputs) if bound_inputs else set() | ||
if self._partial: | ||
self._bound_inputs.update(self._partial.keywords.keys()) | ||
|
||
self._bound_inputs_values: Dict[str, Any] = bound_inputs_values or {} | ||
if self._bound_inputs_values: | ||
# bounded input values override any collisions w/ partials | ||
self._bound_inputs.update(set(self._bound_inputs_values)) | ||
|
||
# Transform the interface to List[Optional[T]] in case `min_success_ratio` is set | ||
output_as_list_of_optionals = min_success_ratio is not None and min_success_ratio != 1 and n_outputs == 1 | ||
collection_interface = transform_interface_to_list_interface( | ||
|
@@ -247,6 +260,8 @@ def __call__(self, *args, **kwargs): | |
if self._partial: | ||
"""If partial exists, then mix-in all partial values""" | ||
kwargs = {**self._partial.keywords, **kwargs} | ||
# bounded input values override any collisions w/ partials | ||
kwargs.update(self._bound_inputs_values) | ||
return super().__call__(*args, **kwargs) | ||
|
||
def _literal_map_to_python_input( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
bound_inputs != set(bound_inputs_values)
might not work as expected when comparing a set with dictionary keys. Consider usingbound_inputs != set(bound_inputs_values.keys())
to ensure proper comparison between the set and dictionary keys.Code suggestion
Code Review Run #f8b189
Should Bito avoid suggestions like this for future reviews? (Manage Rules)