Skip to content

Bug when encountering multiple overloaded power lines #60

@Mleyliabadi

Description

@Mleyliabadi

Problem
Two problems:

  1. When more than one lines are impacted, there is a bug in alphadeesp and when running compute_new_network_changes
  2. After the resolution of the problem (see the suggested solution below), all the suggested remedial action obtain a score of 0

Script to reproduce the results:

import configparser
import numpy as np

from alphaDeesp.core.grid2op.Grid2opObservationLoader import Grid2opObservationLoader
from alphaDeesp.core.grid2op.Grid2opSimulation import Grid2opSimulation
from alphaDeesp.core.graphsAndPaths import OverFlowGraph
from alphaDeesp.core.alphadeesp import AlphaDeesp
        
def main(config, env_folder):
    chronic_scenario = 4
    time_step = 992
    loader = Grid2opObservationLoader(env_folder)
    env, obs, action_space = loader.get_observation(chronic_scenario= chronic_scenario, 
                                                    timestep=time_step)
    observation_space = env.observation_space
    ltc=list(np.where(obs.rho>1)[0])#overloaded line to solve
    sim = Grid2opSimulation(obs, action_space, observation_space, param_options=config["DEFAULT"], debug=False,
                                    ltc=ltc,plot=False)
    g_over =  OverFlowGraph(sim.topo, ltc, sim.get_dataframe())#sim.build_graph_from_data_frame(ltc)
    simulator_data = {"substations_elements": sim.get_substation_elements(),
        "substation_to_node_mapping": sim.get_substation_to_node_mapping(),
        "internal_to_external_mapping": sim.get_internal_to_external_mapping()}

    alphadeesp = AlphaDeesp(g_over.get_graph(), sim.get_dataframe(), simulator_data,sim.substation_in_cooldown)
    alphadeesp.identify_routing_buses()
    ranked_combinations = alphadeesp.get_ranked_combinations()
    expert_system_results, actions = sim.compute_new_network_changes(ranked_combinations)
    print(expert_system_results)

if __name__ == "__main__":

    config = configparser.ConfigParser()
    config.read("../ressources/config.ini")
    env_folder = "../ai4realnet_small"

    main(config, env_folder)

expertop4grid config file

[DEFAULT]
# Simulator choice, either: "Pypownet" or "RTE"
simulatorType = Grid2OP

# Path to grid representation files
gridPath = ../ai4realnet_small

# Grid2op difficulty level for manual mode
grid2opDifficulty = 0

# 2 percent of the max overload flow
ThresholdReportOfLine = 0.2

# 10 percent de la surcharge max
ThersholdMinPowerOfLoop = 0.1

# If at least a loop is detected, only keep the ones with a flow  of at least 25 percent the biggest one
ratioToKeepLoop = 0.25

# Ratio percentage for reconsidering the flow direction
ratioToReconsiderFlowDirection = 0.75

# max unused lines
maxUnusedLines = 3

# number of simulated topologies node at the final simulation step
totalNumberOfSimulatedTopos = 30

# number of simulated topologies per node at the final simulation step
numberOfSimulatedToposPerNode = 10

Data

Clone the data from ai4realnet github repository: https://github.com/AI4REALNET/grid2op-scenario/tree/main/ai4realnet_small

output (Error)

##############################################################################
##########...........COMPUTE NEW NETWORK CHANGES..........####################
##############################################################################
########### Compute new network changes on node [22] with new topo [[1 2 1 2 2]] ###########
Traceback (most recent call last):
  File "bug_report.py", line 36, in <module>
    main(config, env_folder)
  File "bug_report.py", line 27, in main
    expert_system_results, actions = sim.compute_new_network_changes(ranked_combinations)
  File "/home/milad/miniconda3/envs/expertop4grid/lib/python3.7/site-packages/alphaDeesp/core/grid2op/Grid2opSimulation.py", line 229, in compute_new_network_changes
    score_data=self.compute_one_network_change_score_data(obs,virtual_obs,done,info,new_conf,internal_target_node,alphaDeesp_Internal_topo,new_conf_grid2op,score_topo)
  File "/home/milad/miniconda3/envs/expertop4grid/lib/python3.7/site-packages/alphaDeesp/core/grid2op/Grid2opSimulation.py", line 273, in compute_one_network_change_score_data
    if (bool(info['disc_lines'][self.ltc]>=0)):#other line disconnections are already accounted in worsened lines
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Expected output

##############################################################################
##########...........COMPUTE NEW NETWORK CHANGES..........####################
##############################################################################
########### Compute new network changes on node [22] with new topo [[1 2 1 2 2]] ###########
########### Compute new network changes on node [22] with new topo [[1 1 2 2 1]] ###########
########### Compute new network changes on node [22] with new topo [[1 2 1 1 2]] ###########
########### Compute new network changes on node [22] with new topo [[1 1 2 1 2]] ###########
########### Compute new network changes on node [22] with new topo [[1 2 1 2 1]] ###########
########### Compute new network changes on node [22] with new topo [[1 1 1 2 2]] ###########
########### Compute new network changes on node [22] with new topo [[1 2 2 1 1]] ###########
########### Compute new network changes on node [22] with new topo [[1 2 2 2 1]] ###########
########### Compute new network changes on node [22] with new topo [[1 2 2 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 1 1 1 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 1 1 2 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 2 1 1 1 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 2 1 1 2 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 2 1 1 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 2 1 2 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 2 2 1 2 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 2 2 1 1 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 1 2 1 1 2]] ###########
########### Compute new network changes on node [23] with new topo [[1 1 1 2 1 1 2 2 1 2]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 2 2 2 1]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 2 2 2]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 1 1 1]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 1 1 2]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 1 2 1]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 1 2 2]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 2 1 2]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 2 2 1]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 1 2 1 1]] ###########
########### Compute new network changes on node [21] with new topo [[1 2 2 2 2 1 1 1]] ###########

Solution
The problem comes from this line

if (bool(info['disc_lines'][self.ltc]>=0)):#other line disconnections are already accounted in worsened lines

This would solve the problem:

if (info['disc_lines'][self.ltc].any()):
                simulated_score = 0

However, all the suggested remedial actions obtain a score of 0 which is related to my second problem as described in the beginning of this issue.

    overflow ID  Flows before  Flows after  Delta flows     Worsened line  \
0        20.000       -30.429      -30.495        0.066              [29]   
1        20.000       -30.429      -30.385       -0.044              [29]   
2        20.000       -30.429      -30.381       -0.048              [29]   
3        20.000       -30.429      -30.838        0.409              [39]   
4        20.000       -30.429      -30.829        0.400              [39]   
5        20.000       -30.429      -30.417       -0.012              [31]   
6        20.000       -30.429      -30.416       -0.013              [31]   
7        20.000       -30.429      -30.431        0.002              [31]   
8        20.000       -30.429      -30.424       -0.004              [31]   
9        20.000       -30.429      -30.573        0.144  [29, 30, 31, 39]   
10       20.000       -30.429      -30.771        0.343      [29, 30, 31]   
11       20.000       -30.429      -30.351       -0.077      [29, 30, 31]   
12       20.000       -30.429      -30.548        0.119      [29, 30, 31]   
13       20.000       -30.429      -30.380       -0.048      [29, 30, 31]   
14       20.000       -30.429      -30.586        0.157      [29, 30, 31]   
15       20.000       -30.429      -30.390       -0.039      [29, 30, 31]   
16       20.000       -30.429      -30.189       -0.240      [29, 30, 31]   
17       20.000       -30.429      -30.763        0.334      [29, 30, 31]   
18       20.000       -30.429      -30.980        0.551      [29, 30, 31]   
19       20.000       -30.429      -31.019        0.590                []   
20       20.000       -30.429      -29.893       -0.536              [36]   
21       20.000       -30.429      -30.711        0.282                []   
22       20.000       -30.429      -30.466        0.038                []   
23       20.000       -30.429      -30.462        0.033                []   
24       20.000       -30.429      -30.260       -0.169                []   
25       20.000       -30.429      -30.352       -0.077              [36]   
26       20.000       -30.429      -30.343       -0.086              [36]   
27       20.000       -30.429      -30.685        0.256                []   
28       20.000       -30.429      -31.197        0.768                []   

    Prod redispatched  Load redispatched      Internal Topology applied   \
0               0.342              0.000                 [0, 1, 0, 1, 1]   
1               0.365              0.000                 [0, 0, 1, 1, 0]   
2               0.519              0.000                 [0, 1, 0, 0, 1]   
3               1.176              0.000                 [0, 0, 1, 0, 1]   
4               1.743              0.000                 [0, 1, 0, 1, 0]   
5               0.020              0.000                 [0, 0, 0, 1, 1]   
6               0.055              0.000                 [0, 1, 1, 0, 0]   
7               0.037              0.000                 [0, 1, 1, 1, 0]   
8               0.028              0.000                 [0, 1, 1, 0, 1]   
9               1.941              0.000  [0, 0, 0, 1, 0, 0, 0, 0, 0, 1]   
10              1.740              0.000  [0, 0, 0, 1, 0, 0, 0, 1, 0, 1]   
11              1.887              0.000  [0, 0, 0, 1, 1, 0, 0, 0, 0, 1]   
12              1.744              0.000  [0, 0, 0, 1, 1, 0, 0, 1, 0, 1]   
13              2.138              0.000  [0, 0, 0, 1, 0, 1, 0, 0, 0, 1]   
14              1.972              0.000  [0, 0, 0, 1, 0, 1, 0, 1, 0, 1]   
15              1.992              0.000  [0, 0, 0, 1, 1, 1, 0, 1, 0, 1]   
16              2.102              0.000  [0, 0, 0, 1, 1, 1, 0, 0, 0, 1]   
17              1.745              0.000  [0, 0, 0, 1, 0, 0, 1, 0, 0, 1]   
18              1.633              0.000  [0, 0, 0, 1, 0, 0, 1, 1, 0, 1]   
19              4.068              0.000        [0, 1, 1, 1, 1, 1, 1, 0]   
20              1.912              0.000        [0, 1, 1, 1, 0, 1, 1, 1]   
21              1.281              0.000        [0, 1, 1, 1, 0, 0, 0, 0]   
22              0.895              0.000        [0, 1, 1, 1, 0, 0, 0, 1]   
23              0.838              0.000        [0, 1, 1, 1, 0, 0, 1, 0]   
24              0.627              0.000        [0, 1, 1, 1, 0, 0, 1, 1]   
25              1.972              0.000        [0, 1, 1, 1, 0, 1, 0, 1]   
26              1.934              0.000        [0, 1, 1, 1, 0, 1, 1, 0]   
27              2.420              0.000        [0, 1, 1, 1, 0, 1, 0, 0]   
28              1.623              0.000        [0, 1, 1, 1, 1, 0, 0, 0]   

                  Topology applied  Substation ID  Rank Substation ID  \
0                  [2, 1, 2, 1, 2]         22.000               1.000   
1                  [1, 2, 2, 1, 1]         22.000               1.000   
2                  [2, 1, 1, 1, 2]         22.000               1.000   
3                  [2, 2, 1, 1, 1]         22.000               1.000   
4                  [1, 1, 2, 1, 2]         22.000               1.000   
5                  [2, 1, 2, 1, 1]         22.000               1.000   
6                  [1, 2, 1, 1, 2]         22.000               1.000   
7                  [1, 2, 2, 1, 2]         22.000               1.000   
8                  [2, 2, 1, 1, 2]         22.000               1.000   
9   [1, 2, 1, 1, 1, 1, 1, 1, 1, 2]         23.000               1.000   
10  [1, 2, 1, 1, 1, 2, 1, 1, 1, 2]         23.000               1.000   
11  [1, 2, 2, 1, 1, 1, 1, 1, 1, 2]         23.000               1.000   
12  [1, 2, 2, 1, 1, 2, 1, 1, 1, 2]         23.000               1.000   
13  [1, 2, 1, 2, 1, 1, 1, 1, 1, 2]         23.000               1.000   
14  [1, 2, 1, 2, 1, 2, 1, 1, 1, 2]         23.000               1.000   
15  [1, 2, 2, 2, 1, 2, 1, 1, 1, 2]         23.000               1.000   
16  [1, 2, 2, 2, 1, 1, 1, 1, 1, 2]         23.000               1.000   
17  [1, 2, 1, 1, 2, 1, 1, 1, 1, 2]         23.000               1.000   
18  [1, 2, 1, 1, 2, 2, 1, 1, 1, 2]         23.000               1.000   
19        [2, 2, 1, 2, 2, 2, 1, 2]         21.000               1.000   
20        [2, 2, 2, 2, 2, 1, 1, 2]         21.000               1.000   
21        [1, 1, 1, 2, 2, 1, 1, 2]         21.000               1.000   
22        [1, 1, 2, 2, 2, 1, 1, 2]         21.000               1.000   
23        [1, 2, 1, 2, 2, 1, 1, 2]         21.000               1.000   
24        [1, 2, 2, 2, 2, 1, 1, 2]         21.000               1.000   
25        [2, 1, 2, 2, 2, 1, 1, 2]         21.000               1.000   
26        [2, 2, 1, 2, 2, 1, 1, 2]         21.000               1.000   
27        [2, 1, 1, 2, 2, 1, 1, 2]         21.000               1.000   
28        [1, 1, 1, 2, 2, 2, 1, 2]         21.000               1.000   

    Topology score  Topology simulated score  Efficacity  
0           86.900                     0.000      -0.065  
1           78.350                     0.000      -0.044  
2           78.350                     0.000      -0.047  
3           55.050                     0.000      -0.402  
4           55.050                     0.000      -0.393  
5           40.400                     0.000      -0.012  
6           40.400                     0.000      -0.013  
7           31.850                     0.000      -0.002  
8            8.550                     0.000      -0.004  
9          175.180                     0.000      -0.142  
10         175.180                     0.000      -0.337  
11         174.420                     0.000      -0.077  
12         174.420                     0.000      -0.118  
13         174.240                     0.000      -0.048  
14         174.240                     0.000      -0.155  
15         173.480                     0.000      -0.039  
16         173.480                     0.000      -0.240  
17         169.470                     0.000      -0.329  
18         169.470                     0.000      -0.539  
19         108.950                     0.000      -0.577  
20         108.950                     0.000      -0.541  
21         108.950                     0.000      -0.278  
22         108.950                     0.000      -0.037  
23         108.950                     0.000      -0.033  
24         108.950                     0.000      -0.168  
25         108.950                     0.000      -0.077  
26         108.950                     0.000      -0.085  
27         108.950                     0.000      -0.253  
28         108.950                     0.000      -0.747 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions