Skip to content

Commit

Permalink
add lots of test for detailed topo description
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Oct 9, 2024
1 parent 15b524c commit 8f55b82
Show file tree
Hide file tree
Showing 665 changed files with 24,988 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ grid2op/tests/venv_test_autoclass/
test_eduardo.py
grid2op/tests/failed_test*
grid2op/tests/ampl_from_iidm.py
grid2op/tests/do_I_repeat.txt
grid2op/tests/parse_res35_working.txt
grid2op/tests/parse_res_35 (copie).txt
grid2op/tests/parse_res_35.txt
grid2op/tests/res_algo_topo_35.txt
grid2op/tests/test_topo_ampl/
grid2op/tests/test_topo_ampl2/

# profiling files
**.prof
37 changes: 29 additions & 8 deletions grid2op/Space/detailed_topo_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import numpy as np
import networkx as nx
import copy
from functools import lru_cache

import grid2op
from grid2op.dtypes import dt_int, dt_bool
Expand Down Expand Up @@ -710,6 +709,7 @@ def _aux_compute_switches_position_one_sub(self,

# new_order = np.arange(len(li_bbs)) # debug
# end perf optim
# TODO another speed optim: put together the objects that can be connected to the same busbars

# cn_can_be_connected = np.ones((nb_conn_node, self.busbar_section_to_subid.shape[0]))
try:
Expand Down Expand Up @@ -1033,8 +1033,8 @@ def _dfs_compute_switches_position(self,

for cn_bbs in better_order: # chose a busbar section
# TODO detailed topo: speed optim: this is probably copied too many times
# if main_obj_id <= 4:
# print(f"{str_debug}obj {main_obj_id}, bbs {cn_bbs}, bus : {my_bus}, {conn_node_to_bus_id}")
# if main_obj_id <= 200:
# print(f"{str_debug} obj {main_obj_id}, order {order_pos[main_obj_id]}, bbs {cn_bbs}, bus : {my_bus}, {conn_node_to_bus_id}")
n_switch_visited = copy.deepcopy(switch_visited)
n_switches_state = copy.deepcopy(switches_state)
n_conn_node_to_bus_id = copy.deepcopy(conn_node_to_bus_id)
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def _dfs_compute_switches_position(self,
try:
debug_id2, (path, cn_path) = next(generator_path)
except StopIteration:
# cannot conenct cn_bbs to other_bbs_cn
# cannot connect cn_bbs to other_bbs_cn
# move to another
break

Expand Down Expand Up @@ -1163,7 +1163,19 @@ def _dfs_compute_switches_position(self,
# nothing to do if the object is not on the same bus
# TODO detailed topo: actually we can do something if an element
# in this case is forced to be connected on my_bus it is not possible
continue
if bus_other == -1:
continue
# continue
possible_bbs_other = list(self._conn_node_to_bbs_conn_node_id[other_cn_id])
possible_bbs_other_is = self._cn_pos_in_sub[possible_bbs_other]
possible_bus_this = nn_conn_node_to_bus_id[possible_bbs_other_is]
if (possible_bus_this != 0).all() and (possible_bus_this != bus_other).all():
# this element cannot be connected to the right bus
is_working = False
break
# feasibility checks are done, do not study this bus
continue

ps_tmp, cns_tmp = self._aux_connect_el_to_switch(conn_graph_this_sub,
other_cn_id,
cn_bbs,
Expand All @@ -1179,14 +1191,23 @@ def _dfs_compute_switches_position(self,
# both objects are on the same bus and there is only one path
# to connect this object to the main object, so I necessarily
# toggle all switches on this path and continue
# print(f"adding conn nodes {cns_tmp[0]} to bus {my_bus} when studying cn {other_cn_id}")
solve_constraints = True
tmp_path = ps_tmp[0]
nn_switch_visited[tmp_path] = True
nn_switches_state[tmp_path] = True
nn_conn_node_visited[cns_tmp[0]] = True
nn_conn_node_to_bus_id[cns_tmp[0]] = my_bus
if solve_constraints:
print("One constraint solved")

this_topo_vect = nn_conn_node_to_bus_id[all_pos]
assigned_this = this_topo_vect != 0
if (this_topo_vect[assigned_this] != topo_vect[assigned_this]).any():
# solving the constraints would for sure create a problem
# as one element would not be assigned to the right bus
is_working = False
break
# if solve_constraints:
# print("One constraint solved")
# else:
# print("stop trying to add constraints")

Expand All @@ -1197,7 +1218,7 @@ def _dfs_compute_switches_position(self,
# this seems to work, I try to see if I can
# handle all the remaining elements
main_obj_id_new = self._aux_find_next_el_id(main_obj_id, all_pos, nn_conn_node_visited, order_pos)
assert main_obj_id_new != main_obj_id # TODO detailed topo debug
# assert main_obj_id_new != main_obj_id # TODO detailed topo debug
if main_obj_id_new is not None:
# I still need to visit some other elements
this_res = self._dfs_compute_switches_position(topo_vect,
Expand Down
51 changes: 51 additions & 0 deletions grid2op/data_test/test_detailed_topo/test_topo_connections10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
switch_id node1 node2 open
0 2 18 0
1 0 19 1
2 0 20 0
3 1 21 1
4 0 1 0
5 2 3 1
6 2 22 1
7 0 23 1
8 0 24 1
9 3 25 1
10 1 26 1
11 2 27 1
12 3 21 0
13 2 20 1
14 3 28 0
15 3 26 0
16 29 0 0
17 2 30 0
18 2 31 0
19 0 30 1
20 0 27 1
21 1 28 1
22 1 32 0
23 3 33 0
24 0 31 1
25 34 1 0
26 3 32 1
27 3 35 0
28 2 24 0
29 0 22 0
30 1 35 1
31 2 19 0
32 1 25 0
33 2 23 0
34 23 12 0
35 30 16 0
36 26 14 0
37 20 13 0
38 24 17 0
39 31 6 0
40 35 15 0
41 28 5 0
42 21 4 1
43 19 8 0
44 18 29 0
45 25 10 1
46 22 7 0
47 27 9 1
48 33 34 0
49 32 11 0
36 changes: 36 additions & 0 deletions grid2op/data_test/test_detailed_topo/test_topo_connections100.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
switch_id node1 node2 open
0 0 6 1
1 0 8 1
2 0 10 0
3 0 16 1
4 0 20 1
5 0 22 0
6 0 12 0
7 0 14 1
8 0 4 0
9 3 0 0
10 1 2 0
11 1 6 0
12 1 8 0
13 1 10 1
14 1 16 0
15 1 20 0
16 1 22 1
17 1 12 1
18 1 14 0
19 1 4 1
20 2 3 1
21 4 5 0
22 6 7 0
23 8 9 0
24 10 11 0
25 12 13 0
26 14 15 0
27 16 17 0
28 18 17 0
29 19 17 0
30 20 26 0
31 22 23 0
32 24 17 1
33 21 26 0
34 25 26 1
102 changes: 102 additions & 0 deletions grid2op/data_test/test_detailed_topo/test_topo_connections101.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
switch_id node1 node2 open
0 0 61 0
1 79 0 0
2 1 2 0
3 60 1 0
4 2 63 0
5 3 4 0
6 3 76 0
7 62 3 0
8 81 3 0
9 4 65 0
10 83 4 0
11 5 6 0
12 64 5 0
13 6 67 0
14 66 7 0
15 85 7 0
16 8 28 0
17 8 53 0
18 8 78 0
19 9 30 0
20 9 10 1
21 9 36 0
22 52 9 0
23 93 9 0
24 10 32 0
25 10 57 0
26 10 38 0
27 95 10 0
28 11 34 0
29 11 12 1
30 11 80 0
31 56 11 0
32 12 46 0
33 12 82 0
34 12 55 0
35 13 44 0
36 13 48 0
37 13 14 1
38 54 13 0
39 89 13 0
40 14 59 0
41 14 26 0
42 14 40 0
43 91 14 0
44 15 50 0
45 15 84 0
46 15 24 0
47 15 42 0
48 58 15 0
49 16 69 0
50 17 18 0
51 17 92 0
52 68 17 0
53 18 71 0
54 18 94 0
55 19 20 0
56 19 86 0
57 70 19 0
58 20 73 0
59 21 22 0
60 21 88 0
61 72 21 0
62 22 75 0
63 22 90 0
64 74 23 0
65 24 25 1
66 26 27 1
67 28 29 0
68 30 31 0
69 32 33 0
70 34 35 0
71 36 37 0
72 38 39 0
73 40 41 0
74 42 43 0
75 44 45 0
76 46 47 0
77 48 49 0
78 50 51 1
79 53 52 0
80 55 54 0
81 57 56 0
82 59 58 0
83 61 60 0
84 63 62 0
85 65 64 0
86 67 66 0
87 69 68 0
88 71 70 0
89 73 72 0
90 75 74 0
91 76 77 0
92 78 79 0
93 80 81 0
94 82 83 1
95 84 85 1
96 86 87 0
97 88 89 0
98 90 91 0
99 92 93 1
100 94 95 1
Loading

0 comments on commit 8f55b82

Please sign in to comment.