Skip to content

Instantly share code, notes, and snippets.

@perrygeo
Last active October 9, 2024 23:30
Show Gist options
  • Save perrygeo/05b438430ab776786bdc85185360c327 to your computer and use it in GitHub Desktop.
Save perrygeo/05b438430ab776786bdc85185360c327 to your computer and use it in GitHub Desktop.
Flyte example
from flytekit import ContainerTask, kwtypes, task, workflow
@task
def say_hello(name: str, area: float) -> str:
return f"Hey {name}! You have an ellipse of area {area}"
calculate_ellipse_area_python = ContainerTask(
command=[
"python",
"calculate-ellipse-area.py",
"{{.inputs.a}}",
"{{.inputs.b}}",
"/var/outputs",
],
image="ghcr.io/flyteorg/rawcontainers-python:v2",
input_data_dir="/var/inputs",
inputs=kwtypes(a=float, b=float),
name="ellipse-area-metadata-python",
output_data_dir="/var/outputs",
outputs=kwtypes(area=float, metadata=str),
)
@workflow
def wf(name: str = "world", a: float = 1.0, b: float = 1.0) -> str:
"""
A test Flyte workflow demonstrating passing data between nodes.
"""
area, metadata = calculate_ellipse_area_python(a, b)
return say_hello(name, area)
@perrygeo
Copy link
Author

perrygeo commented Oct 9, 2024

<1 second locally, 2 minutes in the sandbox.

$ time pyflyte run workflows/try.py wf --name Joe --a 1 --b 2
Running Execution on local.
Hey Joe! You have an ellipse of area 6.283185307179586
pyflyte run workflows/try.py wf --name Joe --a 1 --b 2  0.38s user 0.04s system 50% cpu 0.846 total

vs.

$ time pyflyte run --remote workflows/try.py wf --name Joe --a 1 --b 2
Running Execution on Remote.

[✔] Go to http://localhost:30080/console/projects/flytesnacks/domains/development/executions/astbr2jprtpmsqhl4fd7 

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment