forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_reuse.py
63 lines (50 loc) · 1.72 KB
/
test_reuse.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
import time
from dflow import InputParameter, Inputs, Step, Steps, Workflow
from dflow.python import OP, OPIO, OPIOSign, PythonOPTemplate
class Plus1(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'iter': int
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'iter': int
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
return OPIO({
'iter': op_in['iter'] + 1
})
if __name__ == "__main__":
steps = Steps(name="iter", inputs=Inputs(
parameters={"iter": InputParameter(value=0),
"limit": InputParameter(value=5)}))
plus1 = Step(name="plus1",
template=PythonOPTemplate(Plus1,
image="python:3.8"),
parameters={"iter": steps.inputs.parameters["iter"]},
key="iter-%s" % steps.inputs.parameters["iter"])
steps.add(plus1)
next = Step(name="next", template=steps,
parameters={"iter": plus1.outputs.parameters["iter"]},
when="%s < %s" % (
plus1.outputs.parameters["iter"],
steps.inputs.parameters["limit"]))
steps.add(next)
wf = Workflow("recurse", steps=steps)
wf.submit()
while wf.query_status() in ["Pending", "Running"]:
time.sleep(1)
assert(wf.query_status() == "Succeeded")
step0 = wf.query_step(key="iter-0")[0]
step1 = wf.query_step(key="iter-1")[0]
step1.modify_output_parameter("iter", 3)
wf = Workflow("recurse-resubmit", steps=steps)
wf.submit(reuse_step=[step0, step1])