Skip to content

Commit

Permalink
Add an example for echo task (#1724)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Co-authored-by: Nikki Everett <[email protected]>
  • Loading branch information
pingsutw and neverett authored Aug 29, 2024
1 parent 5289896 commit 89bf7bc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/advanced_composition/advanced_composition/conditional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random

from flytekit import conditional, task, workflow
from flytekit.core.task import Echo


# Simple branch
Expand Down Expand Up @@ -177,6 +178,37 @@ def consume_task_output(radius: float, seed: int = 5) -> float:
)


# Running a noop task in a conditional
#
# In some cases, you may want to skip the execution of a conditional workflow
# if a certain condition is not met.
# You can achieve this by using the `echo` task, which simply returns the input value.

# :::{note}
# To enable the echo plugin in the backend, add the plugin to Flyte's configuration file.
# ```yaml
# task-plugins:
# enabled-plugins:
# - echo
# ```
# :::


echo = Echo(name="echo", inputs={"radius": float})


@workflow
def noop_in_conditional(radius: float, seed: int = 5) -> float:
is_heads = coin_toss(seed=seed)
return (
conditional("noop_in_conditional")
.if_(is_heads.is_true())
.then(calculate_circle_circumference(radius=radius))
.else_()
.then(echo(radius=radius))
)


# Run the workflow locally
if __name__ == "__main__":
default_seed_output = consume_task_output(radius=0.4)
Expand Down

0 comments on commit 89bf7bc

Please sign in to comment.