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

Adopt flyteidl's ordered variable map change #608

Merged
merged 23 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions flytekit/models/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
from collections import OrderedDict

import six as _six
from flyteidl.core import interface_pb2 as _interface_pb2
Expand Down Expand Up @@ -73,15 +74,19 @@ def to_flyte_idl(self):
"""
:rtype: dict[Text, Variable]
"""
return _interface_pb2.VariableMap(variables={k: v.to_flyte_idl() for k, v in _six.iteritems(self.variables)})
return _interface_pb2.VariableMap(
variables=[
_interface_pb2.VariableMapEntry(name=k, var=v.to_flyte_idl()) for k, v in _six.iteritems(self.variables)
Copy link
Contributor

Choose a reason for hiding this comment

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

while we're at it, let's delete six from this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's a couple failed tests too i think... and by a couple i mean 18,238 :)

It worked on my machine...
I did pip install -e for the flyteidl dependency. I'll update the version once the flyteidl change is released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

while we're at it, let's delete six from this file.

And drop Python 2 compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

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

we haven't had python 2 compatibility in forever... it's just too much work to delete six all at once so i generally just do it when i'm working in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

]
)

@classmethod
def from_flyte_idl(cls, pb2_object):
"""
:param dict[Text, Variable] pb2_object:
:rtype: VariableMap
"""
return cls({k: Variable.from_flyte_idl(v) for k, v in _six.iteritems(pb2_object.variables)})
return cls(OrderedDict((v.name, Variable.from_flyte_idl(v.var)) for v in pb2_object.variables))


class TypedInterface(_common.FlyteIdlEntity):
Expand All @@ -106,9 +111,17 @@ def outputs(self) -> typing.Dict[str, Variable]:

def to_flyte_idl(self) -> _interface_pb2.TypedInterface:
return _interface_pb2.TypedInterface(
inputs=_interface_pb2.VariableMap(variables={k: v.to_flyte_idl() for k, v in _six.iteritems(self.inputs)}),
inputs=_interface_pb2.VariableMap(
variables=[
_interface_pb2.VariableMapEntry(name=k, var=v.to_flyte_idl())
for k, v in _six.iteritems(self.inputs)
]
),
outputs=_interface_pb2.VariableMap(
variables={k: v.to_flyte_idl() for k, v in _six.iteritems(self.outputs)}
variables=[
_interface_pb2.VariableMapEntry(name=k, var=v.to_flyte_idl())
for k, v in _six.iteritems(self.outputs)
]
),
)

Expand All @@ -118,8 +131,8 @@ def from_flyte_idl(cls, proto: _interface_pb2.TypedInterface) -> "TypedInterface
:param proto:
"""
return cls(
inputs={k: Variable.from_flyte_idl(v) for k, v in _six.iteritems(proto.inputs.variables)},
outputs={k: Variable.from_flyte_idl(v) for k, v in _six.iteritems(proto.outputs.variables)},
inputs=OrderedDict((v.name, Variable.from_flyte_idl(v.var)) for v in proto.inputs.variables),
outputs=OrderedDict((v.name, Variable.from_flyte_idl(v.var)) for v in proto.outputs.variables),
)


Expand Down Expand Up @@ -211,7 +224,10 @@ def to_flyte_idl(self):
:rtype: flyteidl.core.interface_pb2.ParameterMap
"""
return _interface_pb2.ParameterMap(
parameters={k: v.to_flyte_idl() for k, v in _six.iteritems(self.parameters)},
parameters=[
_interface_pb2.ParameterMapEntry(name=k, var=v.to_flyte_idl())
for k, v in _six.iteritems(self.parameters)
]
)

@classmethod
Expand All @@ -220,4 +236,4 @@ def from_flyte_idl(cls, pb2_object):
:param flyteidl.core.interface_pb2.ParameterMap pb2_object:
:rtype: ParameterMap
"""
return cls(parameters={k: Parameter.from_flyte_idl(v) for k, v in _six.iteritems(pb2_object.parameters)})
return cls(parameters=OrderedDict((v.name, Parameter.from_flyte_idl(v.var)) for v in pb2_object.parameters))
4 changes: 3 additions & 1 deletion tests/flytekit/unit/common_tests/test_launch_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ def test_serialize():
== _identifier.Identifier(_identifier.ResourceType.WORKFLOW, "p", "d", "n", "v").to_flyte_idl()
)
assert s.spec.auth_role.assumable_iam_role == "iam_role"
assert s.spec.default_inputs.parameters["default_input"].default.scalar.primitive.integer == 5
assert len(s.spec.default_inputs.parameters) == 1
assert s.spec.default_inputs.parameters[0].name == "default_input"
assert s.spec.default_inputs.parameters[0].var.default.scalar.primitive.integer == 5


def test_promote_from_model():
Expand Down
8 changes: 6 additions & 2 deletions tests/flytekit/unit/common_tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,12 @@ def my_list_task(wf_params, a, b):
serialized = w.serialize()
assert isinstance(serialized, _workflow_pb2.WorkflowSpec)
assert len(serialized.template.nodes) == 6
assert len(serialized.template.interface.inputs.variables.keys()) == 2
assert len(serialized.template.interface.outputs.variables.keys()) == 2
assert len(serialized.template.interface.inputs.variables) == 2
assert len(serialized.template.interface.outputs.variables) == 2
assert serialized.template.interface.inputs.variables[0].name == "required"
assert serialized.template.interface.inputs.variables[1].name == "not_required"
assert serialized.template.interface.outputs.variables[0].name == "nested_out"
assert serialized.template.interface.outputs.variables[1].name == "scalar_out"


def test_workflow_disable_default_launch_plan():
Expand Down