|
12 | 12 | from datetime import datetime |
13 | 13 |
|
14 | 14 | import docker |
| 15 | +import tensorboard_reducer as tbr |
15 | 16 |
|
16 | 17 | from nebula.addons.blockchain.blockchain_deployer import BlockchainDeployer |
17 | 18 | from nebula.addons.topologymanager import TopologyManager |
@@ -1034,3 +1035,51 @@ def scenario_finished(self, timeout_seconds): |
1034 | 1035 | return False |
1035 | 1036 |
|
1036 | 1037 | time.sleep(5) |
| 1038 | + |
| 1039 | + @classmethod |
| 1040 | + def generate_statistics(cls, path): |
| 1041 | + try: |
| 1042 | + # Generate statistics |
| 1043 | + logging.info(f"Generating statistics for scenario {path}") |
| 1044 | + |
| 1045 | + # Define input directories |
| 1046 | + input_event_dirs = sorted(glob.glob(os.path.join(path, "metrics/*"))) |
| 1047 | + # Where to write reduced TB events |
| 1048 | + tb_events_output_dir = os.path.join(path, "metrics", "reduced-data") |
| 1049 | + csv_out_path = os.path.join(path, "metrics", "reduced-data-as.csv") |
| 1050 | + # Whether to abort or overwrite when csv_out_path already exists |
| 1051 | + overwrite = False |
| 1052 | + reduce_ops = ("mean", "min", "max", "median", "std", "var") |
| 1053 | + |
| 1054 | + # Handle duplicate steps |
| 1055 | + handle_dup_steps = "keep-first" |
| 1056 | + # Strict steps |
| 1057 | + strict_steps = False |
| 1058 | + |
| 1059 | + events_dict = tbr.load_tb_events( |
| 1060 | + input_event_dirs, handle_dup_steps=handle_dup_steps, strict_steps=strict_steps |
| 1061 | + ) |
| 1062 | + |
| 1063 | + # Number of recorded tags. e.g. would be 3 if you recorded loss, MAE and R^2 |
| 1064 | + n_scalars = len(events_dict) |
| 1065 | + n_steps, n_events = list(events_dict.values())[0].shape |
| 1066 | + |
| 1067 | + logging.info(f"Loaded {n_events} TensorBoard runs with {n_scalars} scalars and {n_steps} steps each") |
| 1068 | + logging.info(f"Events dict keys: {events_dict.keys()}") |
| 1069 | + |
| 1070 | + reduced_events = tbr.reduce_events(events_dict, reduce_ops) |
| 1071 | + |
| 1072 | + for op in reduce_ops: |
| 1073 | + logging.info(f"Writing '{op}' reduction to '{tb_events_output_dir}-{op}'") |
| 1074 | + |
| 1075 | + tbr.write_tb_events(reduced_events, tb_events_output_dir, overwrite) |
| 1076 | + |
| 1077 | + logging.info(f"Writing results to '{csv_out_path}'") |
| 1078 | + |
| 1079 | + tbr.write_data_file(reduced_events, csv_out_path, overwrite) |
| 1080 | + |
| 1081 | + logging.info("Reduction complete") |
| 1082 | + |
| 1083 | + except Exception as e: |
| 1084 | + logging.exception(f"Error generating statistics: {e}") |
| 1085 | + return False |
0 commit comments