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

Script annotations output #741

Merged
merged 7 commits into from
Aug 30, 2023

Conversation

dejamiko
Copy link
Contributor

@dejamiko dejamiko commented Aug 8, 2023

Pull Request Checklist

This PR implements the output annotation behaviour described in #740. The case with output params in the function signature as Path is not tested and this can be done with #652.

def func(..., output_param: Annotated[Path, Parameter(output=True, global_name="...", name="")]) -> Annotated[arbitrary_pydantic_type, OutputItem]:
    output_param.write_text("...")
    return output

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #741 (259bc10) into main (6feeec0) will increase coverage by 0.4%.
The diff coverage is 83.3%.

@@           Coverage Diff           @@
##            main    #741     +/-   ##
=======================================
+ Coverage   77.9%   78.4%   +0.4%     
=======================================
  Files         45      45             
  Lines       3475    3622    +147     
  Branches     677     725     +48     
=======================================
+ Hits        2708    2840    +132     
- Misses       580     588      +8     
- Partials     187     194      +7     
Files Changed Coverage Δ
src/hera/workflows/_mixins.py 78.8% <60.0%> (+0.3%) ⬆️
src/hera/workflows/script.py 85.3% <79.2%> (-1.6%) ⬇️
src/hera/workflows/protocol.py 82.1% <80.0%> (-0.5%) ⬇️
src/hera/workflows/runner.py 81.8% <91.4%> (+7.4%) ⬆️
src/hera/workflows/artifact.py 97.9% <96.2%> (+0.1%) ⬆️
src/hera/workflows/parameter.py 90.4% <100.0%> (+2.9%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@flaviuvadan flaviuvadan left a comment

Choose a reason for hiding this comment

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

🎖️ looks fantastic! I left a few questions / small suggestions

@sambhav sambhav added the semver:minor A change requiring a minor version bump label Aug 9, 2023
Comment on lines 142 to 146
output_dir = Path(
str(global_config.experimental_features["hera_output_directory"])
if global_config.experimental_features["hera_output_directory"]
else "hera/outputs"
)
Copy link
Collaborator

@elliotgunton elliotgunton Aug 9, 2023

Choose a reason for hiding this comment

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

Very nice thought to use the experimental features for users to play with the directory explicitly, but I'm thinking if we really need it? 🤔 Also, on the technical side, the type of the dict is:

experimental_features: Dict[str, bool] = field(default_factory=lambda: defaultdict(bool))

So we need to think about how we can specify this directory, or if we can change the types.

Also a very small suggestion if we keep this approach is to add an s on outputs: hera_outputs_directory to match the default

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make another field on the global config vs use the experimental features + use the experimental features to check for allowed usage?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should use

def set_class_defaults(self, cls: Type[TBase], **kwargs: Any) -> None:
+ an attribute in the script runner class.

@sambhav
Copy link
Collaborator

sambhav commented Aug 15, 2023

@dejamiko you don't need to call _get_class_defaults, the hera mixin automatically handles it. See

def _set_defaults(cls, values):

tests/test_runner.py Outdated Show resolved Hide resolved
Mikolaj Deja added 2 commits August 17, 2023 10:52
Add support for output annotations for scripts.
Allow for the users to define them in the function
return type as well as function parameters. Automatically
mount the volumes and save the files for the runner
constructor.

Signed-off-by: Mikolaj Deja <[email protected]>
Add runner and example tests, check that results
are saved in the expected directories and that the
correct yaml is generated.
Restructure test naming and file structure,
add docstrings and fix workflow naming.

Signed-off-by: Mikolaj Deja <[email protected]>
Copy link
Collaborator

@elliotgunton elliotgunton left a comment

Choose a reason for hiding this comment

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

A few nitpicks to tidy up before approving! 🚀

src/hera/workflows/script.py Outdated Show resolved Hide resolved
src/hera/workflows/script.py Outdated Show resolved Hide resolved
src/hera/workflows/runner.py Outdated Show resolved Hide resolved
src/hera/workflows/script.py Outdated Show resolved Hide resolved
src/hera/workflows/script.py Outdated Show resolved Hide resolved
already_set_artifacts = {a.name for a in current_io.artifacts or []}

for param in func_parameters:
if param.name not in already_set_params and param.name not in already_set_artifacts:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why we need to check param.name not in already_set_artifacts (and artifact.name not in already_set_params below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because if you have a function with an artifact

@script(inputs=Artifact(name="i", path="/tmp/i"))
def consume(i):
    import pickle

    with open("/tmp/i", "rb") as f:
        i = pickle.load(f)
    print(i)

i would be interpreted as both an Artifact and a Parameter. The check in the other direction is not necessary.

src/hera/workflows/script.py Outdated Show resolved Hide resolved
src/hera/workflows/script.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@elliotgunton elliotgunton left a comment

Choose a reason for hiding this comment

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

:shipit:

@elliotgunton elliotgunton merged commit 3ffcbab into argoproj-labs:main Aug 30, 2023
13 checks passed
elliotgunton added a commit that referenced this pull request Sep 1, 2023
**Pull Request Checklist**
- [x] Fixes bugs in #741
- [x] Tests added
- [x] Documentation/examples added
- [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR
title

**Description of PR**
Currently, output Artifacts/Parameters contained in function return
annotations or function parameter annotations where marked as output
don't output their paths in the yaml. The runner also does not pre-load
function input parameters marked as outputs as Path objects for the
given kwarg.

This PR fixes output annotations for these use cases and makes the tests
more robust. The "advanced-hera-features" doc was also edited.

I also fixed the codebase for use with VSCode's pytest debugger.

---------

Signed-off-by: Elliot Gunton <[email protected]>
kimjunil pushed a commit to kimjunil/hera that referenced this pull request Sep 3, 2023
**Pull Request Checklist**
- [x] Fixes bugs in argoproj-labs#741
- [x] Tests added
- [x] Documentation/examples added
- [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR
title

**Description of PR**
Currently, output Artifacts/Parameters contained in function return
annotations or function parameter annotations where marked as output
don't output their paths in the yaml. The runner also does not pre-load
function input parameters marked as outputs as Path objects for the
given kwarg.

This PR fixes output annotations for these use cases and makes the tests
more robust. The "advanced-hera-features" doc was also edited.

I also fixed the codebase for use with VSCode's pytest debugger.

---------

Signed-off-by: Elliot Gunton <[email protected]>
Signed-off-by: KimJunil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:minor A change requiring a minor version bump type:enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script outputs annotations
4 participants