-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtlode.py
76 lines (59 loc) · 2.7 KB
/
rtlode.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
#!/usr/bin/env python3
import argparse
import sys
import json
class RtlOde(object):
def __init__(self):
parser = argparse.ArgumentParser(
description='Used to generate and run ode solver logic on FPGAs.',
usage='''rtlode <command> [<args>]
The most commonly used commands are:
build Generate a solver for a given configuration
run Solve a single initial value problem in a given solver
benchmark Bechmark a given solver
''')
parser.add_argument('command', help='Subcommand to run')
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
print('Unrecognized command')
parser.print_help()
exit(1)
getattr(self, args.command)()
def build(self):
parser = argparse.ArgumentParser(description='Generate a solver for a given configuration')
parser.add_argument('configuration', nargs='+',
help='configuration files for the solver')
args = parser.parse_args(sys.argv[2:])
from generator import generator
generator.build(*args.configuration)
def run(self):
parser = argparse.ArgumentParser(
description='Solve a the given number (default: 0) of initial value problems in a given solver'
)
parser.add_argument('solver', help='solver file to execute')
parser.add_argument('--runtime_config', help='overwrites the default config, must be an json string')
parser.add_argument('--amount', type=int, help='number of initial value problems to solve', default=1)
args = parser.parse_args(sys.argv[2:])
assert args.amount > 0
from runtime import runtime
res = runtime.run(
args.solver,
json.loads(args.runtime_config) if args.runtime_config is not None else None,
amount_data=args.amount
)
print('Result:\n%s' % json.dumps(res, sort_keys=True, indent=4))
def benchmark(self):
parser = argparse.ArgumentParser(description='Benchmark a given solver')
parser.add_argument('solver', help='solver file to execute')
parser.add_argument('--runtime_config', help='overwrites the default config, must be an json string')
args = parser.parse_args(sys.argv[2:])
from runtime import runtime
for adata in [1, 10, 100, 1000, 10000]:
timing = runtime.benchmark(
args.solver,
json.loads(args.runtime_config) if args.runtime_config is not None else None,
amount_data=adata
)
print('For %s ivp the solver finished in: %s' % (adata, timing))
if __name__ == '__main__':
RtlOde()