This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_experiment.py
67 lines (51 loc) · 1.65 KB
/
run_experiment.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
import argparse
import json
import os
from datetime import datetime
import calendar
from simulations.experiment import Experiment
from simulations.utils import (
select_network,
select_protocol,
validator_generator
)
def timestamp():
d = datetime.utcnow()
return str(calendar.timegm(d.utctimetuple()))
def main():
parser = argparse.ArgumentParser(description='Run CasperCBC standard simulations.')
parser.add_argument(
'json_file', metavar='J', type=str,
help='specifies the json file with the experiment params'
)
args = parser.parse_args()
with open(args.json_file) as f:
config = json.load(f)
base_name = os.path.basename(args.json_file)
file_name = os.path.splitext(base_name)[0]
experiment_name = "{}-{}".format(file_name, timestamp())
protocol = select_protocol(config['protocol'])
network_class = select_network(config['network'])
experiment = Experiment(
experiment_name,
config['data'],
config['num_simulations'],
validator_generator(config['validator_info'], protocol),
config['msg_mode'],
protocol,
network_class,
config['rounds_per_sim'],
config['report_interval']
)
experiment.run()
experiment.output_results()
experiment.store_copy_config(config)
final_data = experiment.analyzer_data["aggregated"][experiment.intervals - 1]
for data in final_data:
if "interval" in data:
continue
print("{}:\t{}".format(data, final_data[data]))
print()
print("Output written to: {}/".format(experiment.output_dir))
if __name__ == '__main__':
main()