-
-
Notifications
You must be signed in to change notification settings - Fork 21
Resource requirement min max validation #384
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
Stellatsuu
wants to merge
4
commits into
common-workflow-language:main
Choose a base branch
from
Stellatsuu:ResourceRequirement-MinMax
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
addfebb
dev: added minmax check in ResourceRequirement
Stellatsuu 83ea39c
Merge branch 'common-workflow-language:main' into ResourceRequirement…
Stellatsuu 7963a71
fix: lint and mypy
Stellatsuu 18635e6
Merge remote-tracking branch 'origin/ResourceRequirement-MinMax' into…
Stellatsuu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| from typing import Optional, List, Any | ||
|
|
||
| from cwl_utils.parser.cwl_v1_2 import ( | ||
| ResourceRequirement, | ||
| WorkflowStep, | ||
| Workflow, | ||
| CommandLineTool, | ||
| save, | ||
| ) | ||
| import pytest | ||
| from schema_salad.exceptions import ValidationException | ||
|
|
||
|
|
||
| # Helper functions | ||
| def create_commandlinetool( | ||
| requirements: Optional[List[Any]] = None, | ||
| inputs: Optional[List[Any]] = None, | ||
| outputs: Optional[List[Any]] = None, | ||
| ) -> CommandLineTool: | ||
| return CommandLineTool( | ||
| requirements=requirements or [], | ||
| inputs=inputs or [], | ||
| outputs=outputs or [], | ||
| ) | ||
|
|
||
|
|
||
| def create_workflow( | ||
| requirements: Optional[List[Any]] = None, | ||
| steps: Optional[List[Any]] = None, | ||
| inputs: Optional[List[Any]] = None, | ||
| outputs: Optional[List[Any]] = None, | ||
| ) -> Workflow: | ||
| return Workflow( | ||
| requirements=requirements or [], | ||
| steps=steps or [], | ||
| inputs=inputs or [], | ||
| outputs=outputs or [], | ||
| ) | ||
|
|
||
|
|
||
| def create_step( | ||
| requirements: Optional[List[Any]] = None, | ||
| run: Any = None, | ||
| in_: Optional[List[Any]] = None, | ||
| out: Optional[List[Any]] = None, | ||
| ) -> WorkflowStep: | ||
| return WorkflowStep( | ||
| requirements=requirements or [], | ||
| run=run, | ||
| in_=in_ or [], | ||
| out=out or [], | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "bad_min_max_reqs", | ||
| [ | ||
| # cores | ||
| ResourceRequirement(coresMin=4, coresMax=2), | ||
| # ram | ||
| ResourceRequirement(ramMin=2048, ramMax=1024), | ||
| # tmpdir | ||
| ResourceRequirement(tmpdirMin=1024, tmpdirMax=512), | ||
| # outdir | ||
| ResourceRequirement(outdirMin=512, outdirMax=256), | ||
| ], | ||
| ) | ||
| def test_bad_min_max_resource_reqs(bad_min_max_reqs: ResourceRequirement) -> None: | ||
| # Test invalid min/max resource requirements in CWL objects. | ||
|
|
||
| # CommandlineTool with bad minmax reqs | ||
| clt = create_commandlinetool(requirements=[bad_min_max_reqs]) | ||
| with pytest.raises(ValidationException): | ||
| save(clt) | ||
|
|
||
| # WorkflowStep.run with bad minmax reqs | ||
| step_bad_run = create_step(run=clt) | ||
| workflow = create_workflow(steps=[step_bad_run]) | ||
| with pytest.raises(ValidationException): | ||
| save(workflow) | ||
|
|
||
| # WorkflowStep with bad minmax reqs | ||
| clt = create_commandlinetool() | ||
| step = create_step(run=clt, requirements=[bad_min_max_reqs]) | ||
| workflow = create_workflow(steps=[step]) | ||
| with pytest.raises(ValidationException): | ||
| save(workflow) | ||
|
|
||
| # Workflow with bad minmax reqs | ||
| workflow = create_workflow(requirements=[bad_min_max_reqs]) | ||
| with pytest.raises(ValidationException): | ||
| save(workflow) | ||
|
|
||
| # NestedWorkflow with bad minmax reqs | ||
| nest_workflow = create_workflow(requirements=[bad_min_max_reqs]) | ||
| step = create_step(run=nest_workflow) | ||
| workflow = create_workflow(steps=[step]) | ||
| with pytest.raises(ValidationException): | ||
| save(workflow) | ||
|
|
||
| # DeepNestedWorkflow with bad minmax reqs | ||
| deep_workflow = create_workflow(requirements=[bad_min_max_reqs]) | ||
| deep_step = create_step(run=deep_workflow) | ||
| nest_workflow = create_workflow(steps=[deep_step]) | ||
| step = create_step(run=nest_workflow) | ||
| workflow = create_workflow(steps=[step]) | ||
| with pytest.raises(ValidationException): | ||
| save(workflow) |
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.
Thank you for prototyping the validation. This file is autogenerated, so any changes here would get overwritten.
https://github.com/common-workflow-language/cwl-utils/blob/4a8390d897913c3776a0d2b2a01e1e6134b968bc/cwl_utils/parser/cwl_v1_2.py#L2
cwl-utils/Makefile
Lines 191 to 209 in 4a8390d
Additional validation logic should be added elsewhere, perhaps cwl_utils/parser/utils.py
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.
Oh, my bad on that! I didn't see it was autogenerated, those comments were hidden on my IDE.
I will look to add this validation in
cwltoolonly then, since you mentioned that there isn't much validation code to add incwl-utils🙂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.
Is there any documentation to onboard developers?
I am also trying to understand the workflow to see where we should add that piece of logic. From what I understand:
IIUC, checks should generally be included in the CWL specifications in JSON/YAML; But the structure would not enable the comparison of 2 attributes like
minCoresandmaxCoresfor instance.So this would need to be added in the
cwl_utils/parser/utils.pymodule.From here - and if my understanding has been correct so far - I am a bit confused. I don't see where these functions are used. They don't seem to appear in the generated parser files, and in
cwltoolI see functions with the same names but they are redefined. Example:cwl-utils/cwl_utils/parser/utils.py
Line 35 in 4a8390d
cwl-utils/cwl_utils/parser/cwl_v1_2_utils.py
Line 358 in 4a8390d
Ideally I think we would love to have this min-max validation when we call
load_document.Thank you very much for you guidance