Skip to content

Commit

Permalink
Fix some argo lint errors in examples folder (#1244)
Browse files Browse the repository at this point in the history
**Pull Request Checklist**
- [ ] ~~Fixes~~ #1163 
- [ ] ~~Tests added~~
- [ ] ~~Documentation/examples added~~
- [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR
title

**Description of PR**

Fixed argo lint errors in following dirs:
- examples/workflows/use-case
- examples/workflows/scripts
- examples/workflows/misc

---------

Signed-off-by: Ukjae Jeong <[email protected]>
  • Loading branch information
jeongukjae authored Oct 21, 2024
1 parent e7ed95b commit 3266a5b
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 76 deletions.
3 changes: 2 additions & 1 deletion docs/examples/workflows/misc/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Workflow,
)

with Workflow(generate_name="data-") as w:
with Workflow(generate_name="data-", entrypoint="list-log-files") as w:
Data(
name="list-log-files",
source=S3Artifact(name="test-bucket", bucket="my-bucket"),
Expand All @@ -33,6 +33,7 @@
metadata:
generateName: data-
spec:
entrypoint: list-log-files
templates:
- data:
source:
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/workflows/misc/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

with Workflow(generate_name="secret-env-from-", entrypoint="whalesay") as w:
whalesay = Container(
name="whalesay",
image="docker/whalesay:latest",
command=["cowsay"],
env_from=[
Expand Down Expand Up @@ -76,5 +77,6 @@
optional: false
prefix: abc
image: docker/whalesay:latest
name: whalesay
```

2 changes: 2 additions & 0 deletions docs/examples/workflows/misc/env_from.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

with Workflow(generate_name="secret-env-from-", entrypoint="whalesay") as w:
whalesay = Container(
name="whalesay",
image="docker/whalesay:latest",
command=["cowsay"],
env_from=[
Expand Down Expand Up @@ -44,5 +45,6 @@
optional: false
prefix: abc
image: docker/whalesay:latest
name: whalesay
```

6 changes: 4 additions & 2 deletions docs/examples/workflows/misc/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from hera.expr import g
from hera.workflows import HTTP, Parameter, Workflow

with Workflow(generate_name="http-") as w:
with Workflow(generate_name="http-", entrypoint="http") as w:
HTTP(
name="http",
inputs=[Parameter(name="url")],
inputs=[Parameter(name="url", value="https://example.com")],
timeout_seconds=20,
url=f"{g.inputs.parameters.url:$}",
method="GET",
Expand All @@ -32,6 +32,7 @@
metadata:
generateName: http-
spec:
entrypoint: http
templates:
- http:
body: test body
Expand All @@ -45,6 +46,7 @@
inputs:
parameters:
- name: url
value: https://example.com
name: http
```

3 changes: 2 additions & 1 deletion docs/examples/workflows/misc/suspend.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```python linenums="1"
from hera.workflows import Parameter, Suspend, Workflow

with Workflow(generate_name="suspend-") as w:
with Workflow(generate_name="suspend-", entrypoint="suspend-without-duration") as w:
Suspend(name="suspend-without-duration")
Suspend(name="suspend-with-duration", duration=30)
Suspend(
Expand All @@ -31,6 +31,7 @@
metadata:
generateName: suspend-
spec:
entrypoint: suspend-without-duration
templates:
- name: suspend-without-duration
suspend: {}
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/workflows/scripts/callable_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
return Output(output=[annotated_input_value])


with Workflow(name="my-workflow") as w:
with Workflow(name="my-workflow", entrypoint="my-steps") as w:
with Steps(name="my-steps") as s:
my_function(arguments={"input": Input(a=2, b="bar", c=42)})
str_function(arguments={"input": serialize(Input(a=2, b="bar", c=42))})
Expand All @@ -109,6 +109,7 @@
metadata:
name: my-workflow
spec:
entrypoint: my-steps
templates:
- name: my-steps
steps:
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/workflows/scripts/callable_script_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
return Output(output=[annotated_input_value])


with Workflow(name="my-workflow") as w:
with Workflow(name="my-workflow", entrypoint="my-steps") as w:
with Steps(name="my-steps") as s:
my_function(arguments={"input": Input(a=2, b="bar", c=42)})
str_function(arguments={"input": serialize(Input(a=2, b="bar", c=42))})
Expand All @@ -112,6 +112,7 @@
metadata:
name: my-workflow
spec:
entrypoint: my-steps
templates:
- name: my-steps
steps:
Expand Down
12 changes: 4 additions & 8 deletions docs/examples/workflows/use-cases/fine_tune_llama.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ There are several implicit dependencies in this script:
NUM_NODES = 4

"""`create_ssd_storage_class` defines the K8s storage class required for an ssd that's created dynamically.

K8s will create the necessary PersistentVolumeClaim and PersistentVolume resources when a pod requests a volume
rather than when the PVC/PV are _defined_. This helps avoid the risk of pod + volume zone mismatches. Note that this
was tested in GCP / GKE specifically. If you have a different cloud provider you have to change the `provisioner`
rather than when the PVC/PV are _defined_. This helps avoid the risk of pod + volume zone mismatches. Note that this
was tested in GCP / GKE specifically. If you have a different cloud provider you have to change the `provisioner`
field.
"""
create_ssd_storage_class = Resource(
Expand Down Expand Up @@ -144,7 +144,7 @@ There are several implicit dependencies in this script:

"""The delete resource removes the etcd client load balancer and the stateful set.

Useful for cases when you want to dynamically spin up an etcd cluster and then delete it after the client application
Useful for cases when you want to dynamically spin up an etcd cluster and then delete it after the client application
is done.
"""
delete_etcd_resources = Resource(
Expand Down Expand Up @@ -244,8 +244,6 @@ There are several implicit dependencies in this script:
mount_path="/kubecon_na_23_llama2_finetune/finetune",
name="{{inputs.parameters.node-vol}}",
),
# in addition, we set a volume mount for the empty dir volume that we use for communication between GPUs
m.VolumeMount(mount_path="/dev/shm", name="gpu-comm"),
],
)

Expand Down Expand Up @@ -540,8 +538,6 @@ There are several implicit dependencies in this script:
name: '{{inputs.parameters.node-vol}}'
- mountPath: /dev/shm
name: gpu-comm
- mountPath: /dev/shm
name: gpu-comm
inputs:
parameters:
- name: rdvz-id
Expand Down
19 changes: 15 additions & 4 deletions docs/examples/workflows/use-cases/map_reduce.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ See the upstream example [here](https://github.com/argoproj/argo-workflows/blob/

@script(
image="python:alpine3.6",
inputs=Artifact(name="part", path="/mnt/in/part.json"),
inputs=[
Parameter(name="part_id"),
Artifact(name="part", path="/mnt/in/part.json"),
],
outputs=S3Artifact(
name="part",
path="/mnt/out/part.json",
Expand Down Expand Up @@ -76,10 +79,13 @@ See the upstream example [here](https://github.com/argoproj/argo-workflows/blob/

with Workflow(generate_name="map-reduce-", entrypoint="main", arguments=Parameter(name="num_parts", value="4")) as w:
with DAG(name="main"):
s = split(arguments=Parameter(name="num_parts", value="{{workflow.parameters.numParts}}"))
s = split(arguments=Parameter(name="num_parts", value="{{workflow.parameters.num_parts}}"))
m = map_(
with_param=s.result,
arguments=S3Artifact(name="part", key="{{workflow.name}}/parts/{{item}}.json"),
arguments=[
Parameter(name="part_id", value="{{item}}"),
S3Artifact(name="part", key="{{workflow.name}}/parts/{{item}}.json"),
],
)
s >> m >> reduce()
```
Expand All @@ -103,14 +109,17 @@ See the upstream example [here](https://github.com/argoproj/argo-workflows/blob/
- arguments:
parameters:
- name: num_parts
value: '{{workflow.parameters.numParts}}'
value: '{{workflow.parameters.num_parts}}'
name: split
template: split
- arguments:
artifacts:
- name: part
s3:
key: '{{workflow.name}}/parts/{{item}}.json'
parameters:
- name: part_id
value: '{{item}}'
depends: split
name: map-
template: map-
Expand Down Expand Up @@ -156,6 +165,8 @@ See the upstream example [here](https://github.com/argoproj/argo-workflows/blob/
artifacts:
- name: part
path: /mnt/in/part.json
parameters:
- name: part_id
name: map-
outputs:
artifacts:
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/workflows/use-cases/spacy_inference_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ Step 2: Performs inference on the dataset in the volume path /mnt/data using Spa


with Workflow(
generate_name="spacy_inference_pipeline-",
entrypoint="spacy_inference_pipeline",
generate_name="spacy-inference-pipeline-",
entrypoint="spacy-inference-pipeline",
volumes=[Volume(name="data-dir", size="1Gi", mount_path="/mnt/data")],
service_account_name="hera",
namespace="argo",
) as w:
with Steps(name="spacy_inference_pipeline") as steps:
with Steps(name="spacy-inference-pipeline") as steps:
data_prep(name="data-prep")
inference_spacy(name="inference-spacy")
```
Expand All @@ -128,13 +128,13 @@ Step 2: Performs inference on the dataset in the volume path /mnt/data using Spa
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: spacy_inference_pipeline-
generateName: spacy-inference-pipeline-
namespace: argo
spec:
entrypoint: spacy_inference_pipeline
entrypoint: spacy-inference-pipeline
serviceAccountName: hera
templates:
- name: spacy_inference_pipeline
- name: spacy-inference-pipeline
steps:
- - name: data-prep
template: data-prep
Expand Down
28 changes: 14 additions & 14 deletions docs/examples/workflows/use-cases/spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/


@script(image="jupyter/pyspark-notebook:latest", resources=Resources(cpu_request=4, memory_request="8Gi"))
def spark(n: int) -> None:
def spark(num_data: int) -> None:
import random
import subprocess
import time
Expand All @@ -33,7 +33,7 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/
spark = SparkSession.builder.master("local[1]").appName("my-spark-example-running-in-hera.com").getOrCreate()

# let's compare a regular dataframe vs a spark dataframe! First, we define the data to use
data, columns = [random.randint(0, n) for _ in range(n)], ["value"]
data, columns = [random.randint(0, num_data) for _ in range(num_data)], ["value"]

# as a very simple and naive comparison, let's print out the average, min, and max of both dataframes
# and now let's create a regular Pandas dataframe
Expand All @@ -58,8 +58,8 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/

with Workflow(generate_name="spark-", entrypoint="d") as w:
with DAG(name="d"):
for i, n in enumerate([1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000]):
spark(name="spark-{i}".format(i=i), arguments={"n": n})
for i, num_data in enumerate([1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000]):
spark(name="spark-{i}".format(i=i), arguments={"num_data": num_data})
```

=== "YAML"
Expand All @@ -76,44 +76,44 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/
tasks:
- arguments:
parameters:
- name: n
- name: num_data
value: '1000'
name: spark-0
template: spark
- arguments:
parameters:
- name: n
- name: num_data
value: '10000'
name: spark-1
template: spark
- arguments:
parameters:
- name: n
- name: num_data
value: '100000'
name: spark-2
template: spark
- arguments:
parameters:
- name: n
- name: num_data
value: '1000000'
name: spark-3
template: spark
- arguments:
parameters:
- name: n
- name: num_data
value: '10000000'
name: spark-4
template: spark
- arguments:
parameters:
- name: n
- name: num_data
value: '100000000'
name: spark-5
template: spark
name: d
- inputs:
parameters:
- name: n
- name: num_data
name: spark
script:
command:
Expand All @@ -128,8 +128,8 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/
import sys
sys.path.append(os.getcwd())
import json
try: n = json.loads(r'''{{inputs.parameters.n}}''')
except: n = r'''{{inputs.parameters.n}}'''
try: num_data = json.loads(r'''{{inputs.parameters.num_data}}''')
except: num_data = r'''{{inputs.parameters.num_data}}'''

import random
import subprocess
Expand All @@ -138,7 +138,7 @@ compares a regular Pandas dataframe with a Spark dataframe. Inspired by: https:/
import pandas as pd
from pyspark.sql import SparkSession
spark = SparkSession.builder.master('local[1]').appName('my-spark-example-running-in-hera.com').getOrCreate()
(data, columns) = ([random.randint(0, n) for _ in range(n)], ['value'])
(data, columns) = ([random.randint(0, num_data) for _ in range(num_data)], ['value'])
pandas_df = pd.DataFrame(data=data, columns=columns)
start = time.time()
pandas_result = pandas_df.describe()
Expand Down
2 changes: 1 addition & 1 deletion examples/workflows/misc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Workflow,
)

with Workflow(generate_name="data-") as w:
with Workflow(generate_name="data-", entrypoint="list-log-files") as w:
Data(
name="list-log-files",
source=S3Artifact(name="test-bucket", bucket="my-bucket"),
Expand Down
1 change: 1 addition & 0 deletions examples/workflows/misc/data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: Workflow
metadata:
generateName: data-
spec:
entrypoint: list-log-files
templates:
- data:
source:
Expand Down
1 change: 1 addition & 0 deletions examples/workflows/misc/env-from.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ spec:
optional: false
prefix: abc
image: docker/whalesay:latest
name: whalesay
1 change: 1 addition & 0 deletions examples/workflows/misc/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

with Workflow(generate_name="secret-env-from-", entrypoint="whalesay") as w:
whalesay = Container(
name="whalesay",
image="docker/whalesay:latest",
command=["cowsay"],
env_from=[
Expand Down
1 change: 1 addition & 0 deletions examples/workflows/misc/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ spec:
optional: false
prefix: abc
image: docker/whalesay:latest
name: whalesay
Loading

0 comments on commit 3266a5b

Please sign in to comment.