-
Notifications
You must be signed in to change notification settings - Fork 229
Adds support for selectors in Union[List[...], Selector(...)] patterns #1764
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
Open
joaomarcoscrs
wants to merge
3
commits into
main
Choose a base branch
from
joao/fix-array-input-references
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+348
−5
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
134fb43
Enhance schema and selectors parsing to support Union[List[...], Sele…
joaomarcoscrs ea53e4b
Merge branch 'main' into joao/fix-array-input-references
joaomarcoscrs 9aea492
Merge remote-tracking branch 'origin/main' into joao/fix-array-input-…
joaomarcoscrs 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 hidden or 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 hidden or 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
167 changes: 167 additions & 0 deletions
167
tests/workflows/integration_tests/execution/test_workflow_with_union_list_selector.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| """Integration tests for Union[List[...], Selector(...)] patterns in workflow blocks. | ||
|
|
||
| This test verifies that blocks can properly handle properties defined as | ||
| Union[List[T], Selector(...)] where the value can be either: | ||
| - A literal list: ["tag1", "tag2"] | ||
| - A selector to a list: $inputs.tags | ||
| - A mixed list with literals and selectors: ["literal", "$inputs.tag"] | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from inference.core.env import WORKFLOWS_MAX_CONCURRENT_STEPS | ||
| from inference.core.managers.base import ModelManager | ||
| from inference.core.workflows.core_steps.common.entities import StepExecutionMode | ||
| from inference.core.workflows.execution_engine.core import ExecutionEngine | ||
|
|
||
|
|
||
| WORKFLOW_WITH_SELECTOR_TO_LIST = { | ||
| "version": "1.0", | ||
| "inputs": [ | ||
| {"type": "WorkflowImage", "name": "image"}, | ||
| { | ||
| "type": "WorkflowParameter", | ||
| "name": "classes_to_consider", | ||
| }, | ||
| ], | ||
| "steps": [ | ||
| { | ||
| "type": "RoboflowObjectDetectionModel", | ||
| "name": "detection", | ||
| "image": "$inputs.image", | ||
| "model_id": "yolov8n-640", | ||
| }, | ||
| { | ||
| "type": "DetectionsConsensus", | ||
| "name": "consensus", | ||
| "predictions_batches": ["$steps.detection.predictions"], | ||
| "required_votes": 1, | ||
| "classes_to_consider": "$inputs.classes_to_consider", | ||
| }, | ||
| ], | ||
| "outputs": [ | ||
| { | ||
| "type": "JsonField", | ||
| "name": "predictions", | ||
| "selector": "$steps.consensus.predictions", | ||
| } | ||
| ], | ||
| } | ||
|
|
||
|
|
||
| WORKFLOW_WITH_LITERAL_LIST = { | ||
| "version": "1.0", | ||
| "inputs": [ | ||
| {"type": "WorkflowImage", "name": "image"}, | ||
| ], | ||
| "steps": [ | ||
| { | ||
| "type": "RoboflowObjectDetectionModel", | ||
| "name": "detection", | ||
| "image": "$inputs.image", | ||
| "model_id": "yolov8n-640", | ||
| }, | ||
| { | ||
| "type": "DetectionsConsensus", | ||
| "name": "consensus", | ||
| "predictions_batches": ["$steps.detection.predictions"], | ||
| "required_votes": 1, | ||
| "classes_to_consider": ["person"], | ||
| }, | ||
| ], | ||
| "outputs": [ | ||
| { | ||
| "type": "JsonField", | ||
| "name": "predictions", | ||
| "selector": "$steps.consensus.predictions", | ||
| } | ||
| ], | ||
| } | ||
|
|
||
|
|
||
| def test_union_list_selector_with_selector_to_list( | ||
| model_manager: ModelManager, | ||
| crowd_image: np.ndarray, | ||
| ) -> None: | ||
| """Test Union[List[str], Selector(...)] when using a selector to a list.""" | ||
| # given | ||
| workflow_init_parameters = { | ||
| "workflows_core.model_manager": model_manager, | ||
| "workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
| } | ||
| execution_engine = ExecutionEngine.init( | ||
| workflow_definition=WORKFLOW_WITH_SELECTOR_TO_LIST, | ||
| init_parameters=workflow_init_parameters, | ||
| max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
| ) | ||
|
|
||
| # when | ||
| result = execution_engine.run( | ||
| runtime_parameters={ | ||
| "image": crowd_image, | ||
| "classes_to_consider": ["person"], | ||
| } | ||
| ) | ||
|
|
||
| # then | ||
| assert isinstance(result, list), "Expected list of results" | ||
| assert len(result) == 1, "Expected single result" | ||
| assert "predictions" in result[0], "Expected predictions in output" | ||
| # Verify that the selector was properly resolved and the workflow executed | ||
|
|
||
|
|
||
| def test_union_list_selector_with_literal_list( | ||
| model_manager: ModelManager, | ||
| crowd_image: np.ndarray, | ||
| ) -> None: | ||
| """Test Union[List[str], Selector(...)] when using a literal list.""" | ||
| # given | ||
| workflow_init_parameters = { | ||
| "workflows_core.model_manager": model_manager, | ||
| "workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
| } | ||
| execution_engine = ExecutionEngine.init( | ||
| workflow_definition=WORKFLOW_WITH_LITERAL_LIST, | ||
| init_parameters=workflow_init_parameters, | ||
| max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
| ) | ||
|
|
||
| # when | ||
| result = execution_engine.run( | ||
| runtime_parameters={ | ||
| "image": crowd_image, | ||
| } | ||
| ) | ||
|
|
||
| # then | ||
| assert isinstance(result, list), "Expected list of results" | ||
| assert len(result) == 1, "Expected single result" | ||
| assert "predictions" in result[0], "Expected predictions in output" | ||
| # Verify that the literal list was properly handled | ||
|
|
||
|
|
||
| def test_union_list_selector_validates_type_mismatch( | ||
| model_manager: ModelManager, | ||
| crowd_image: np.ndarray, | ||
| ) -> None: | ||
| """Test that type validation catches invalid selector resolution.""" | ||
| # given | ||
| workflow_init_parameters = { | ||
| "workflows_core.model_manager": model_manager, | ||
| "workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
| } | ||
| execution_engine = ExecutionEngine.init( | ||
| workflow_definition=WORKFLOW_WITH_SELECTOR_TO_LIST, | ||
| init_parameters=workflow_init_parameters, | ||
| max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
| ) | ||
|
|
||
| # when/then - passing a string instead of a list should fail validation | ||
| with pytest.raises(Exception): # Should raise validation error | ||
| execution_engine.run( | ||
| runtime_parameters={ | ||
| "image": crowd_image, | ||
| "classes_to_consider": "person", # String instead of list | ||
| } | ||
| ) |
This file contains hidden or 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.
please use constants for key names
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.
and also values