rte-france / Grid2Op

Grid2Op a testbed platform to model sequential decision making in power systems.
https://grid2op.readthedocs.io/
Mozilla Public License 2.0
282 stars 116 forks source link

5 bus example showing unusual behaviour #26

Closed medhasubramanian closed 4 years ago

medhasubramanian commented 4 years ago

The 5 bus example shows unusual behaviour while deploying the do-nothing-agent. Load 3's voltage, after some amount of time, does not have a value, and becomes 'NaN'. This occurs in the main episode as well as most of the provided scenarios. In all these scenarios however, the do-nothing-agent does not fail. Attached is a code snippet to reproduce this issue. The code shows 3 plots: Load 3's voltage, Line 4 extremity's voltage, Line 8 extremity's voltage. The plot produced by the code shows that even though the scenario is longer (the length is 2016) the load 3's voltage does not have a curve after index 100 (approximately). With each of the scenarios, this occurs, though this "failure" occurs at different timesteps. Other information: Pandapower version: 2.2.0 Grid2op version: 0.5.2

Scenario numbers that have a similar output: 00, 01, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 14, 15, 16, 17, 18, 19

Scenarios that had normal behaviour: 13

Scenarios where the agent failed: 02 code_snippet_5bus_network.txt

BDonnot commented 4 years ago

Hello @Medha710 i am not witnessing any unusual behaviour in the grid2op 0.5.2 version on my machine. The outcome of your script, for the load_v part look like this to me: load_voltage_scneario2

We notice everything is fine, until there is a game over (at time step around 90-100). This change of behaviour (sending a game over when a load is disconnected) has been added in version 0.5.0 I believe. Can you confirm you get the same results as me on this exact script please (this is a copy paste of your program that sets the scenario tested to the bugy scenario) ?

import numpy as np
import pandas as pd
import grid2op
import matplotlib.pyplot as plt

def obs_to_df(obs, reward):
    """ Extract relevant information from observation and put it into dataframe. """
    # create dataframe from observations
    num_load=obs.n_load
    num_line=obs.n_line
    data = [[pd.Timestamp(obs.year, obs.month, obs.day, obs.hour_of_day, obs.minute_of_hour),reward]]
    df = pd.DataFrame(data, columns = ['Date','reward'])
    load_v=pd.DataFrame([obs.load_v[2]], columns=["Load 3(V)"])
    df=pd.concat([df,load_v],axis=1)
    # Adding line related data
    for i in range(0, num_line):
        str_line_or=("Line Origin %d" % (i+1))
        or_v=pd.DataFrame([obs.v_or[i]], columns=[(str_line_or+"(V)")])
        str_line_ex=("Line Extremity %d" % (i+1))
        ex_v=pd.DataFrame([obs.v_ex[i]], columns=[(str_line_ex+"(V)")])
        df=pd.concat([df,or_v,ex_v],axis=1)
    return df
# RUN THE AGENT:
env = grid2op.make("case5_example") # create environment: power grid, injections, reward function, observation space, action space
env.chronics_handler.tell_id(0) # force the environement to use scenario 1 (set it to scenario 0, but calling env.reset will make it go to scenario 01)
total_reward = 0.0 # initialize reward accumulator
total_steps = int(0) # initialize the counter of steps
obs = env.reset() # obtain first observation
print("Chronics used: {}".format(env.chronics_handler.get_id()))
df_obs = obs_to_df(obs, 0.0) # put relevant observations into dataframe
do_nothing_action = env.helper_action_player({}) # specify the "do-nothing action"
load_v=[]
while True:
        obs, reward, done, info = env.step(do_nothing_action) # run the power grid with the do-nothing action
        df_obs = df_obs.append(obs_to_df(obs, reward), ignore_index=True) # append relevant observations to dataframe
        total_reward += reward
        total_steps += 1
        if np.any(~np.isfinite(obs.load_v)):
            print("I found a nan in load voltages")
        if done:
            break
print("Episode done in %d steps, total reward %.2f" % (total_steps, total_reward))  
#Issue here: Load 3 becomes NaN after some timestamps
plt.plot(df_obs.index, df_obs['Load 3(V)'],label="Load 3(V)")
plt.show()

Also, note that version of pandapower 2.2.0 make the environment really really slow (10 fold increase in the computation of a time step). The pandapower team was made aware of this issue and they fixed it in version 2.2.1. I would recommend using either pandapower 2.1.0 or pandapower 2.2.1 for grid2op related computation, but not 2.2.0.

medhasubramanian commented 4 years ago

Hello @BDonnot Yes, you are correct. I had not checked if the game over signal was true or false. As in the previous version, the game would not be over even though the load was disconnected. Yes, I confirm that I get the same response. Thank you for the clarification! Also, thank you for your comment about the pandapower version; will take it into account.

BDonnot commented 4 years ago

Hello Medha,

I am closing this issue as the problem seems to have been solved. Don't hesitate to reach out if this issue arises again.

Benjamin