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

[Feature] Support positional arguments #2522

Merged

Conversation

MortalHappiness
Copy link
Contributor

@MortalHappiness MortalHappiness commented Jun 20, 2024

Tracking issue

Resolves: flyteorg/flyte#5320

Why are the changes needed?

The the issue description for details.

What changes were proposed in this pull request?

  • Change the inputs and outputs attributes in the Interface class to OrderedDict to preserve the order.
  • Write values in positional arguments to kwargs.

How was this patch tested?

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.19%. Comparing base (29662e7) to head (3fd412a).
Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2522       +/-   ##
===========================================
+ Coverage   71.79%   91.19%   +19.39%     
===========================================
  Files         182       75      -107     
  Lines       18561     3849    -14712     
  Branches     3654        0     -3654     
===========================================
- Hits        13326     3510     -9816     
+ Misses       4592      339     -4253     
+ Partials      643        0      -643     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MortalHappiness MortalHappiness force-pushed the feature/#5320-positional-args branch 2 times, most recently from be4c921 to 0e46066 Compare June 20, 2024 09:07
@@ -24,9 +25,9 @@ def __init__(
query_template: str,
task_config: Optional[T] = None,
task_type="sql_task",
inputs: Optional[Dict[str, Tuple[Type, Any]]] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.

https://docs.python.org/3.7/library/stdtypes.html#dict

flytekit only supports 3.8+, do we still need to use OrderedDict here?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know that the dictionary after Python 3.7 is ordered. I use OrderedDict because I found somewhere in the codebase still uses OrderedDict. After some discussions in meetings, it seems that those are legacy codes. Therefore, I've rolled back the changes of OrderedDict.

@pingsutw
Copy link
Member

Could you also test it on serverless? Thanks!

@wild-endeavor
Copy link
Contributor

@MortalHappiness for changes that only touch flytekit, and to give all reviewers peace of mind, could you please sign up for serverless, use this commit to build the image, and run some tests? (incidentally, this also helps us test serverless 😄). Could you link it in the pr description as well please?

Copy link
Contributor

@wild-endeavor wild-endeavor left a comment

Choose a reason for hiding this comment

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

as always, thanks! this has been bugging us for a while.


@workflow
def wf_pure_positional_args() -> int:
return t1(arg1, arg2)
Copy link
Contributor

Choose a reason for hiding this comment

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

could you also write a test (and run on serverless) where a downstream task takes both positional and named arguments from both 1) workflow inputs and 2) outputs of upstream tasks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please see if these tests are what you want. Thanks. Also, I'll run them on the serverless later.

https://github.com/flyteorg/flytekit/pull/2522/files#diff-fa72fab667c8393cca8d5afd3943db0edc55794423b7cfc3ab33d0f8c3146650R1022-R1044

Resolves: flyteorg/flyte#5320
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
Resolves: flyteorg/flyte#5320
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@MortalHappiness
Copy link
Contributor Author

MortalHappiness commented Jun 28, 2024

image

from flytekit import task, workflow

@task
def t1(x: int, y: int) -> int:
    return x + y * 2

@workflow
def wf() -> int:
    return t1(5, y=6)

@wild-endeavor wild-endeavor merged commit 2719b34 into flyteorg:master Jun 28, 2024
46 of 48 checks passed
bgedik pushed a commit to bgedik/flytekit that referenced this pull request Jul 3, 2024
- Change the `inputs` and `outputs` attributes in the `Interface` class to `OrderedDict` to preserve the order.
- Write values in positional arguments to `kwargs`.
Resolves: flyteorg/flyte#5320
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
Signed-off-by: bugra.gedik <bugra.gedik@predera.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants