-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalgo.py
More file actions
68 lines (53 loc) · 2.15 KB
/
algo.py
File metadata and controls
68 lines (53 loc) · 2.15 KB
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
import argparse
import yaml
from typing import Dict
from eqsql import eq, worker_pool, db_tools
def run(exp_id: str, params: Dict):
db_started = False
pool = None
task_queue = None
try:
# start database
db_tools.start_db(params['db_path'])
db_started = True
# start task queue
task_queue = eq.init_task_queue(params['db_host'], params['db_user'],
port=None, db_name=params['db_name'])
# check if the input and output queues are empty,
# if not, then exit with a warning.
if not task_queue.are_queues_empty():
print("WARNING: db input / output queues are not empty. Aborting run", flush=True)
return
# start worker pool
pool_params = worker_pool.cfg_file_to_dict(params['pool_cfg_file'])
pool = worker_pool.start_local_pool(params['worker_pool_id'], params['pool_launch_script'],
exp_id, pool_params)
task_type = params['task_type']
fts = []
# TODO: submit some tasks to DB, and append the returned eqsql.eq.futures to
# the list of futures. For example:
# payload = {'x': random.uniform(0, 10), 'y': random.uniform(0, 10)}
# _ , ft = task_queue.submit_task(exp_id, task_type, json.dumps(payload))
# fts.append(ft)
# TODO: do something with the completed futures. See esql.eq documentation
# for more options. For example:
# for ft in eq.as_completed(fts):
# print(ft.result())
finally:
if task_queue is not None:
task_queue.close()
if pool is not None:
pool.cancel()
if db_started:
db_tools.stop_db(params['db_path'])
def create_parser():
parser = argparse.ArgumentParser()
parser.add_argument('exp_id', help='experiment id')
parser.add_argument('config_file', help="yaml format configuration file")
return parser
if __name__ == '__main__':
parser = create_parser()
args = parser.parse_args()
with open(args.config_file) as fin:
params = yaml.safe_load(fin)
run(args.exp_id, params)