|
| 1 | +import argparse |
| 2 | +import os |
| 3 | +from itertools import chain |
| 4 | + |
1 | 5 | from swmmio.run_models.run import run_simple, run_hot_start_sequence
|
2 | 6 | from swmmio.run_models import start_pool
|
3 | 7 |
|
4 |
| -from swmmio import Model |
5 |
| -from itertools import chain |
6 |
| -import os |
7 |
| -import argparse |
8 |
| -from multiprocessing import Pool, cpu_count |
9 |
| -from datetime import datetime |
10 | 8 |
|
11 |
| -#parse the arguments |
12 |
| -parser = argparse.ArgumentParser(description='Process some stuff') |
13 |
| -parser.add_argument('-r', '--run', dest='model_to_run', nargs="+") |
14 |
| -parser.add_argument('-rhs', '--run_hotstart', dest='hotstart_model_to_run', nargs="+") |
15 |
| -parser.add_argument('-sp', '--start_pool', dest='start_pool', nargs="+") |
16 |
| -parser.add_argument('-cores_left', '--cores_left', dest='cores_left', default=4, type=int) |
17 |
| -parser.add_argument('-pp', '--post_process', dest='post_process', nargs="+") |
| 9 | +def main(): |
| 10 | + # parse the arguments |
| 11 | + parser = argparse.ArgumentParser(description='Process some stuff') |
| 12 | + parser.add_argument('-r', '--run', dest='model_to_run', nargs="+") |
| 13 | + parser.add_argument('-rhs', '--run_hotstart', dest='hotstart_model_to_run', nargs="+") |
| 14 | + parser.add_argument('-sp', '--start_pool', dest='start_pool', nargs="+") |
| 15 | + parser.add_argument('-cores_left', '--cores_left', dest='cores_left', default=4, type=int) |
| 16 | + parser.add_argument('-pp', '--post_process', dest='post_process', nargs="+") |
| 17 | + |
| 18 | + args = parser.parse_args() |
| 19 | + wd = os.getcwd() # current directory script is being called from |
18 | 20 |
|
19 |
| -args = parser.parse_args() |
20 |
| -wd = os.getcwd() #current directory script is being called from |
| 21 | + if args.model_to_run is not None: |
21 | 22 |
|
22 |
| -if args.model_to_run is not None: |
| 23 | + models_paths = [os.path.join(wd, f) for f in args.model_to_run] |
| 24 | + print('Adding models to queue:\n\t{}'.format('\n\t'.join(models_paths))) |
23 | 25 |
|
24 |
| - models_paths = [os.path.join(wd, f) for f in args.model_to_run] |
25 |
| - print('Adding models to queue:\n\t{}'.format('\n\t'.join(models_paths))) |
| 26 | + # run the models in series (one after the other) |
| 27 | + list(map(run_simple, models_paths)) |
| 28 | + # run_simple(args.model_to_run) |
26 | 29 |
|
27 |
| - #run the models in series (one after the other) |
28 |
| - list(map(run_simple, models_paths)) |
29 |
| - # run_simple(args.model_to_run) |
| 30 | + elif args.hotstart_model_to_run is not None: |
| 31 | + models_paths = [os.path.join(wd, f) for f in args.hotstart_model_to_run] |
| 32 | + print('hotstart_model_to_run the model: {}'.format(args.hotstart_model_to_run)) |
| 33 | + # m = Model(args.hotstart_model_to_run) |
| 34 | + # run_hot_start_sequence(m)#args.hotstart_model_to_run) |
| 35 | + list(map(run_hot_start_sequence, models_paths)) |
30 | 36 |
|
31 |
| -elif args.hotstart_model_to_run is not None: |
32 |
| - models_paths = [os.path.join(wd, f) for f in args.hotstart_model_to_run] |
33 |
| - print('hotstart_model_to_run the model: {}'.format(args.hotstart_model_to_run)) |
34 |
| - # m = Model(args.hotstart_model_to_run) |
35 |
| - # run_hot_start_sequence(m)#args.hotstart_model_to_run) |
36 |
| - list(map(run_hot_start_sequence, models_paths)) |
| 37 | + elif args.start_pool is not None: |
37 | 38 |
|
38 |
| -elif args.start_pool is not None: |
| 39 | + models_dirs = [os.path.join(wd, f) for f in args.start_pool] |
| 40 | + print('Searching for models in:\n\t{}'.format('\n\t'.join(models_dirs))) |
| 41 | + # combine the segments and options (combinations) into one iterable |
| 42 | + inp_paths = [] |
| 43 | + for root, dirs, files in chain.from_iterable(os.walk(path) for path in models_dirs): |
| 44 | + for f in files: |
| 45 | + if f.endswith('.inp') and 'bk' not in root: |
| 46 | + # we've found a directory containing an inp |
| 47 | + inp_paths.append(os.path.join(root, f)) |
39 | 48 |
|
40 |
| - models_dirs = [os.path.join(wd, f) for f in args.start_pool] |
41 |
| - print('Searching for models in:\n\t{}'.format('\n\t'.join(models_dirs))) |
42 |
| - #combine the segments and options (combinations) into one iterable |
43 |
| - inp_paths = [] |
44 |
| - for root, dirs, files in chain.from_iterable(os.walk(path) for path in models_dirs): |
45 |
| - for f in files: |
46 |
| - if f.endswith('.inp') and 'bk' not in root: |
47 |
| - #we've found a directory containing an inp |
48 |
| - inp_paths.append(os.path.join(root, f)) |
| 49 | + # call the main() function in start_pool.py |
| 50 | + start_pool.main(inp_paths, args.cores_left) |
49 | 51 |
|
| 52 | + print("swmmio has completed running {} models".format(len(inp_paths))) |
50 | 53 |
|
51 |
| - #call the main() function in start_pool.py |
52 |
| - start_pool.main(inp_paths, args.cores_left) |
| 54 | + else: |
| 55 | + print('you need to pass in some args') |
53 | 56 |
|
54 |
| - print("swmmio has completed running {} models".format(len(inp_paths))) |
| 57 | + return 0 |
55 | 58 |
|
56 | 59 |
|
57 |
| -else: |
58 |
| - print('you need to pass in some args') |
| 60 | +if __name__ == '__main__': |
| 61 | + main() |
0 commit comments