Closed marota closed 4 years ago
I could reproduce the graph you get at timestep 797
Yet, I could not reproduce the same expert_result dataframe. I don't have substation 12 in it, so it seems alphadeesp doesn't return the best actions
So I set the parameter "totalnumberofsimulatedtopos" in Expert Agent to 25 instead of 10 to see more actions
self.config = { "totalnumberofsimulatedtopos": 25, "numberofsimulatedtopospernode": 5, "maxUnusedLines": 3, "ratioToReconsiderFlowDirection": 0.75, "ratioToKeepLoop": 0.25, "ThersholdMinPowerOfLoop": 0.1, "ThresholdReportOfLine": 0.2 }
You may want to check:
grid2op version = 1.1.0
On my side, self.config = { "totalnumberofsimulatedtopos": 30, "numberofsimulatedtopospernode": 10, "maxUnusedLines": 3, "ratioToReconsiderFlowDirection": 0.75, "ratioToKeepLoop": 0.25, "ThersholdMinPowerOfLoop": 0.1, "ThresholdReportOfLine": 0.2 }
I will look into it. By the way, I had to make this slight improvement in l2rpn-baseline/ExpertAgent (but I am not allowed to commit): ++ best_action=self.action_space({})#do nothing action ++ if not np.isnan(index_best_action): ++ best_action = actions[index_best_action]
Is this what you want to commit ?
Yes
OK it's done in commit 5a38e54ce143e51907592257e6fad547d4890339
When debugging we noticed 2 important things:
The numerous game over are justified by the following parameters:
Topology names returned in the dataframe are alphadeesp topologies (e.g. substation 4, [1,1,2,2,2]) and this is not in the same order as grid2op topologies The mapping between both of these topology representations is made by method: alphadeesp.core.Grid2OpSimulation.get_action_from_topo
Expert4Grid is not working properly when the topology is different from the meshed topology. Launching the expert system at this timestep (for which substation 1 is split into 2 nodes) we obtain the following overflow graph substation 1 should be split into 2 nodes
the corresponding Graph DataFrame confirms it:
from alphaDeesp.core.grid2op.Grid2opSimulation import Grid2opSimulation
config= {
"totalnumberofsimulatedtopos": 30,
"numberofsimulatedtopospernode": 10,
"maxUnusedLines": 3,
"ratioToReconsiderFlowDirection": 0.75,
"ratioToKeepLoop": 0.25,
"ThersholdMinPowerOfLoop": 0.1,
"ThresholdReportOfLine": 0.2
}
id_lines=[17]
plot_graphs=True
plot_folder='Test_Expert_Baseline'
sim = Grid2opSimulation(obs, env.action_space, env.observation_space, param_options=config, debug=False,
ltc=id_lines, plot=plot_graphs, plot_folder = plot_folder)
import os
if plot_graphs:
#plot_folder = "alphaDeesp/ressources/output"
os.makedirs(plot_folder, exist_ok=True)
gridName = dataset#config['DEFAULT']['gridPath'].split('/')[-1]
plot_folder = os.path.join(plot_folder, gridName)
os.makedirs(plot_folder, exist_ok=True)
lineName = 'linetocut_'+str(id_lines)
plot_folder = os.path.join(plot_folder, lineName)
os.makedirs(plot_folder, exist_ok=True)
#scenarioName = 'Scenario_'+str(args.chronicscenario)
plot_folder = os.path.join(plot_folder, scenarioName)
os.makedirs(plot_folder, exist_ok=True)
timestepName = 'Timestep_' + str(timestep_of_interest)
plot_folder = os.path.join(plot_folder, timestepName)
os.makedirs(plot_folder, exist_ok=True)
from alphaDeesp.expert_operator import expert_operator
ranked_combinations, expert_system_results, action = expert_operator(sim, plot=plot_graphs)
This function needs to be changed: we expect node ids and not substations ids, especially when a substation has 2 nodes. In AlphaDeesp represenation, the second node id is 666+sub_id
Because of that, the graph of alphadeesp is not the graph of the current topology is nodes splitting has already been performed
This test should be rewritten: the node splitting action should be done using grid2op, before creating sim = Grid2opSimulation() https://github.com/marota/ExpertOp4Grid/blob/2830ceb5737dbde37ac3c449961da9201bf738f8/alphaDeesp/tests/grid2op/grid2op_grid_test.py#L20
def test_detailed_graph_with_node_0_split_in_two():
"""
From an observation, avec using load2()
basic graph with zero nodes split in two, has 14 nodes
with node 0 split in two, we should have 15 nodes
:return:
"""
config = configparser.ConfigParser()
config.read("./alphaDeesp/tests/resources_for_tests_grid2op/config_for_tests.ini")
param_folder = "./alphaDeesp/tests/resources_for_tests_grid2op/l2rpn_2019_ltc_9"
loader = Grid2opObservationLoader(param_folder)
env, obs, action_space = loader.get_observation()
new_configuration = [2, 2, 2, 1, 1]
sub_id = 4
action_def = {"set_bus": {"substations_id": [(sub_id, new_configuration)]}}
action = env.action_space(action_def)
osb, _reward, _done, _info = env.step(action)
observation_space = env.observation_space
sim = Grid2opSimulation(obs, action_space, observation_space, param_options=config["DEFAULT"], debug=False,
ltc=[9])
network = Network(sim.substations_elements)
print("There are {} graphical nodes ".format(network.get_graphical_number_of_nodes()))
assert (network.get_graphical_number_of_nodes() == 15)
Something like that. This one fails currently as it returns 14 nodes
@NMegel @mjothy
It is not useful that g_over displays 2 node at a given substation (if this substation was initially at 2 nodes) because it does not change the process of the expert system then (given that the backend simulation to compute the graph edges is indeed computed with the current topology with 2 nodes at the relevant substation)
A use case displays the "end result dataframe" with only Nans for action efficacy. It should not be.
However:
the first action (sub_id=4, topo=[2, 2, 1, 1, 1]) can be simulated, and we see some values and should have an efficacy.
Second action [1, 1, 2, 2, 2] can also be simulated (and is equivalent to the first one) but no Flows after seems to be displayed
The third action [2, 2, 2, 1, 1] leads to a diverging load flow, so result should be nan indeed
Action sub_id=12, target_topology=[2, 1, 1, 2] is a solution and should have Topology Simulated Score=4
To reproduce:
The problem arrises ar timestep 798
To investigate more deeply: