-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpsim.py
More file actions
executable file
·65 lines (47 loc) · 1.55 KB
/
psim.py
File metadata and controls
executable file
·65 lines (47 loc) · 1.55 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
#!/usr/bin/env python
from __future__ import print_function
import json
import docopt
from files import is_file
from files import read_file
from files import read_json
from schema import Schema
from simulator import simulate
usage="""POETS Simulator (PSIM) v0.1
Usage:
psim.py [options] <app.xml>
Options:
-l --level=<n> Specify log messages verbosity [default: 1].
-q --quiet Suppress in-simulation outputs.
-r --result Print simulation result as JSON object.
-t --temp=<dir> Specify simulation file directory [default: /tmp].
-d --debug Print debug information.
"""
def psim(xml_input, rmap={}, options={}):
"""Simulate POETS XML.
Arguments:
- xml_input (str) : an XML file or string.
- rmap (dict) : device region map [optional].
- options (dict) : simulation options [optional].
See docstring of simulator.simulate for simulation options documentation.
Return:
- result (dict) : simulation result.
"""
xml = read_file(xml_input) if is_file(xml_input) else xml_input
schema = Schema(xml, rmap)
result = simulate(schema, options)
return result
def main():
args = docopt.docopt(usage, version="v0.1")
options = {
"debug": args["--debug"],
"quiet": args["--quiet"],
"level": int(args["--level"]),
"temp_dir": args["--temp"],
"printer": print
}
result = psim(args["<app.xml>"], {}, options)
if args["--result"]:
print(json.dumps(result))
if __name__ == '__main__':
main()