acoustic-carpenter-78188
11/01/2023, 1:12 AMbasic_workflow contains trivial examples to access output attributes
• failed_workflow contains examples that causes exception (e.g. out of range)
• advanced_workflow contains examples with more complex attribute access
from dataclasses import dataclass
from typing import Dict, List, NamedTuple
from dataclasses_json import dataclass_json
from flytekit import WorkflowFailurePolicy, task, workflow
@dataclass_json
@dataclass
class foo:
a: str
@task
def t1() -> (List[str], Dict[str, str], foo):
return ["a", "b"], {"a": "b"}, foo(a="b")
@task
def t2(a: str) -> str:
print("a", a)
return a
@task
def t3() -> (Dict[str, List[str]], List[Dict[str, str]], Dict[str, foo]):
return {"a": ["b"]}, [{"a": "b"}], {"a": foo(a="b")}
@task
def t4(a: List[str]):
print("a", a)
@task
def t5(a: Dict[str, str]):
print("a", a)
@workflow
def basic_workflow():
l, d, f = t1()
t2(a=l[0])
t2(a=d["a"])
t2(a=f.a)
@workflow(
# The workflow doesn't fail when one of the nodes fails but other nodes are still executable
failure_policy=WorkflowFailurePolicy.FAIL_AFTER_EXECUTABLE_NODES_COMPLETE
)
def failed_workflow():
# This workflow is supposed to fail due to exceptions
l, d, f = t1()
t2(a=l[100])
t2(a=d["b"])
t2(a=f.b)
@workflow
def advanced_workflow():
dl, ld, dd = t3()
t2(a=dl["a"][0])
t2(a=ld[0]["a"])
t2(a=dd["a"].a)
t4(a=dl["a"])
t5(a=ld[0])
Local execution
$ pyflyte run test_workflow.py basic_workflow
a a
a b
a b
$ pyflyte run test_workflow.py failed_workflow
Failed with Exception Code: USER:PromiseAttributeResolveError
Underlying Exception: Failed to resolve attribute path [100] in promise Resolved(o0=<FlyteLiteral collection { literals { scalar { primitive { string_value: "a" } } } literals { scalar { primitive { string_value: "b" } } } }>), index 100 out of range 2
Encountered error while executing workflow 'test_workflow.failed_workflow':
Error encountered while executing 'failed_workflow':
Failed to resolve attribute path [100] in promise Resolved(o0=<FlyteLiteral collection { literals { scalar { primitive { string_value: "a" } } } literals { scalar { primitive { string_value: "b" } } } }>), index 100 out of range 2
$ pyflyte run test_workflow.py advanced_workflow
a b
a b
a b
a ['b']
a {'a': 'b'}
Remote Execution
basic
https://user-images.githubusercontent.com/24364830/267101816-fd1b65cb-eb2e-49ef-b773-d2d621aff5b7.png▾
https://user-images.githubusercontent.com/24364830/267101784-e686d575-a97e-494a-acb7-1fdb7e9b328d.png▾
https://user-images.githubusercontent.com/24364830/267101581-b6100bbd-2025-4813-b661-5f7f6c0e5649.png▾
acoustic-carpenter-78188
11/01/2023, 1:12 AM