Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (51 loc) · 2.46 KB
/
Copy pathmain.py
File metadata and controls
69 lines (51 loc) · 2.46 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
66
67
68
69
import json
import pathlib
from lips.benchmark.powergridBenchmark import PowerGridBenchmark
from gnn_powergrid.gnn.gnn_simulator import GnnSimulator
from gnn_powergrid.gnn.models.gnn import GPGmodel
from gnn_powergrid.utils import NpEncoder
env_name = "l2rpn_case14_sandbox"
path = pathlib.Path().resolve()
BENCH_CONFIG_PATH = path / "configs" / (env_name + ".ini")
DATA_PATH = path / "Datasets" / env_name / "DC"
LOG_PATH = path / "logs.log"
if not DATA_PATH.exists():
DATA_PATH.mkdir(parents=True)
NB_SAMPLE_TRAIN = 1e2
NB_SAMPLE_VAL = 1e2
NB_SAMPLE_TEST = 1e2
NB_SAMPLE_OOD = 1e2
EPOCHS = 500
if __name__ == "__main__":
benchmark = PowerGridBenchmark(benchmark_path=DATA_PATH,
benchmark_name="Benchmark4",
load_data_set=False,
config_path=BENCH_CONFIG_PATH,
log_path=LOG_PATH)
benchmark.generate(nb_sample_train=int(NB_SAMPLE_TRAIN),
nb_sample_val=int(NB_SAMPLE_VAL),
nb_sample_test=int(NB_SAMPLE_TEST),
nb_sample_test_ood_topo=int(NB_SAMPLE_OOD),
do_store_physics=True,
is_dc=True
)
# use this if you have already generated some data to import them and comment two previous statements
# benchmark = PowerGridBenchmark(benchmark_path=DATA_PATH,
# benchmark_name="Benchmark4",#"DoNothing",
# load_data_set=True,
# config_path=BENCH_CONFIG_PATH,
# log_path=LOG_PATH)
# read the hyperparameters from the configuration file
SIM_CONFIG_PATH = path / "configs" / "gnn.ini"
gnn_simulator = GnnSimulator(model=GPGmodel,
name="gnn_torch",
sim_config_path=SIM_CONFIG_PATH,
input_size=2,
output_size=1,
epochs=EPOCHS)
gnn_simulator.train(benchmark.train_dataset, benchmark.val_dataset)
predictions = gnn_simulator.predict(dataset=benchmark._test_dataset)
metrics_test = benchmark.evaluate_simulator(dataset="all", augmented_simulator=gnn_simulator)
print(metrics_test)
with open("results.json", "w", encoding="utf-8") as f:
json.dump(obj=metrics_test, fp=f, indent=4, sort_keys=True, cls=NpEncoder)