forked from ZLI-afk/autotest2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eos_run.py
184 lines (162 loc) · 5.29 KB
/
eos_run.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import time
from pathlib import Path
import glob
import os
import shutil
from dflow import Step, Workflow, download_artifact, upload_artifact
from dflow.python import (OP, OPIO, Artifact, OPIOSign, PythonOPTemplate,
upload_packages)
from dflow.plugins.dispatcher import DispatcherExecutor
lbg_resource_dict = {
"number_node": 1,
"cpu_per_node": 8,
"gpu_per_node": 1,
"queue_name": "eosflow_run",
"group_size": 1,
"source_list": ["/opt/deepmd-kit-2.0.1"]
#"source_list": ["/opt/intel/oneapi/setvars.sh"]
}
lbg_machine_dict = {
"batch_type": "Lebesgue",
"context_type": "LebesgueContext",
"local_root" : "./",
"remote_profile":{
"email": "[email protected]",
"password": "enoughBor715!",
"program_id": 2315,
"input_data":{
"api_version":2,
"job_type": "indicate",
"log_file": "log",
"grouped":True,
"job_name": "eosflow_run",
"disk_size": 100,
"scass_type":"c12_m92_1 * NVIDIA V100",
"platform": "ali",
#"image_name":"zhuoyli/dflow_test:eos",
"image_name":"LBG_DeePMD-kit_2.0.1_v1.1",
"on_demand":0
}
}
}
if "__file__" in locals():
upload_packages.append(__file__)
class RunProperty(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'target_tasks': Artifact(Path)
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'out_tasks': Artifact(Path)
})
def run(self, path_to_work):
tmp_task_list = glob.glob(os.path.join(path_to_work, 'task.[0-9]*[0-9]'))
tmp_task_list.sort()
all_task = tmp_task_list
#run_tasks = util.collect_task(all_task, inter_type)
if len(all_task) == 0:
return
else:
for task in all_task:
os.chdir(task)
os.system("lmp -i in.lammps -v restart 0")
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
op_out = OPIO({
"out_tasks": Path('eos_calc_out')
})
path_to_work = op_in['target_tasks']
cwd = os.getcwd()
self.run(path_to_work)
os.chdir(cwd)
shutil.copytree(path_to_work, op_out["out_tasks"])
return op_out
# def test_python():
# wf = Workflow(name="run")
#
# artifact0 = upload_artifact("eos_calc")
# print(artifact0)
# # print(artifact3)
# dispatcher_executor = DispatcherExecutor(
# host="127.0.0.1", port="2746",
# machine_dict=lbg_machine_dict,
# resources_dict=lbg_resource_dict)
# step = Step(
# name="step",
# template=PythonOPTemplate(RunProperty,
# image="zhuoyli/dflow_test:eos",
# command=['python3']),
# artifacts={"workfile": artifact0}, executor=dispatcher_executor,
# util_command=['python3']
# )
# wf.add(step)
# wf.submit()
#
# while wf.query_status() in ["Pending", "Running"]:
# time.sleep(1)
#
# assert (wf.query_status() == "Succeeded")
# step = wf.query_step(name="step")[0]
# assert (step.phase == "Succeeded")
#
# print(download_artifact(step.outputs.artifacts["eos_calc_out"]))
def main():
from eos_make_post import (EosMake, EosPost)
# define input artifacts
artifact0 = upload_artifact("param.json")
artifact1 = upload_artifact("POSCAR")
artifact2 = upload_artifact("frozen_model.pb")
print(artifact0)
print(artifact1)
print(artifact2)
#define dispatcher
dispatcher_executor = DispatcherExecutor(
host="127.0.0.1", port="2746",
machine_dict=lbg_machine_dict,
resources_dict=lbg_resource_dict)
# define Steps for make, run and post
step_make = Step(
name="make-eos",
template=PythonOPTemplate(EosMake, image="zhuoyli/dflow_test:eos"),
artifacts={"parameters": artifact0,
"structure": artifact1,
"potential": artifact2},
)
artifact_target_tasks = step_make.outputs.artifacts["tasks"]
step_run = Step(
name="run-eos",
template=PythonOPTemplate(RunProperty,
image="zhuoyli/dflow_test:eos",
command=['python3']),
artifacts={"target_tasks": artifact_target_tasks}, executor=dispatcher_executor,
util_command=['python3']
)
artifact_out_tasks = step_run.outputs.artifacts["out_tasks"]
step_post = Step(
name="post-eos",
template=PythonOPTemplate(EosPost, image="zhuoyli/dflow_test:eos"),
artifacts={"result_tasks": artifact_out_tasks}
)
# define Workflow for eos
wf = Workflow(name="eos")
wf.add(step_make)
wf.add(step_run)
wf.add(step_post)
wf.submit()
while wf.query_status() in ["Pending", "Running"]:
time.sleep(1)
assert (wf.query_status() == "Succeeded")
step_post = wf.query_step(name="step_post")[0]
assert (step_post.phase == "Succeeded")
print(download_artifact(step_post.outputs.artifacts["result_json"]))
print(download_artifact(step_post.outputs.artifacts["result_out"]))
if __name__ == "__main__":
main()