-
Notifications
You must be signed in to change notification settings - Fork 42
/
test_wlm.py
83 lines (69 loc) · 2.18 KB
/
test_wlm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from typing import List
from dflow import SlurmJobTemplate, Step, Workflow, argo_range
from dflow.python import OP, OPIO, Artifact, OPIOSign, PythonOPTemplate, Slices
class Hello(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'filename': str
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'foo': Artifact(str)
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
open(op_in["filename"], "w").write("foo")
op_out = OPIO({
'foo': op_in["filename"]
})
return op_out
class Check(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'foo': Artifact(List[str])
})
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
print(op_in["foo"])
for filename in op_in["foo"]:
with open(filename, "r") as f:
print(f.read())
return OPIO()
if __name__ == "__main__":
wf = Workflow(name="wlm")
hello = Step("hello",
PythonOPTemplate(Hello, image="python:3.8",
slices=Slices("{{item}}",
input_parameter=["filename"],
output_artifact=["foo"]
)
),
parameters={"filename": ["f1.txt", "f2.txt"]},
with_param=argo_range(2),
key="hello-{{item}}",
executor=SlurmJobTemplate(
header="#!/bin/sh\n#SBATCH --nodes=1",
node_selector={
"kubernetes.io/hostname": "slurm-minikube-v100"}))
wf.add(hello)
check = Step("check",
PythonOPTemplate(Check, image="python:3.8"),
artifacts={"foo": hello.outputs.artifacts["foo"]})
wf.add(check)
wf.submit()