Be aware that this notebook, as well as the plotting capabilities in grid2op are a work in progress. This notebook will change, and some function might change name in future major grid2op release.
With the module "grid2op.Plot" (more information on the official documentation here) we offer some possibility to inspect visually (aka plot) some informations about the state of the powergrid.
This module counts today 3 "base" classes:
PlotPyGamethat uses the "pygame" lirabrie to plot information about the powergrid. This library is particularly suited for making videos, looking at the temporal dynamics of the grid etc. It is not recommended to use it for studying a particular step.
PlotMatplotlibwhich uses the well-known matplotlib python library to render the plot. Matplotlib being the most used plotting library in python, we decided to add its support in grid2op.
PlotPlotlythat uses the plotply librairy. As opposed to pygame, plotly is particularly suited for making in depth study of some particular time step.
It is not recommended to use any of these. Rather, we developped two higher level classes:
Plottingthat will allow easier manipulation of the "base" classes above mentionned. This should be the main class using for studying the behaviour of your agent as of version 0.7.0.
EpisodeReplaywhich uses the "PlotPyGame" class and is used to render a movie "as a gif or a mp4 file mainly for communication about the results of your agent
env.renderwhich is the familiar method for all people used to the open ai gym framework.
We want to emphasize that for now, the results of the plottings are not always aesthetically pleasing. We are working on improving this for the next releases of grid2op.
Last but not least, a package called
grid2viz has been developped to help you diagnose in depth the behaviour of your agent. This package is much more advance than all the methods presented above and we highly recommend its usage to get the best of your agents!
import matplotlib.pyplot as plt # pip install matplotlib import seaborn as sns # pip install seaborn import pygame # pip install pygame import plotly.graph_objects as go # pip install plotly import imageio # pip install imageio import imageio_ffmpeg # pip install imageio-ffmpeg
pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html
This notebook will not work if one of the 6 packages above cannot be imported. We then highly recommend you to install them on your machine. (we put the pip command to install them if you have any trouble)
import grid2op env = grid2op.make()
/home/benjamin/Documents/grid2op_test/getting_started/grid2op/MakeEnv.py:686: UserWarning: Your are using only 2 chronics for this environment. More can be download by running, from a command line: python -m grid2op.download --name "case14_realistic" --path_save PATH\WHERE\YOU\WANT\TO\DOWNLOAD\DATA
As we already said, the "Plot.Plotting" module can help render a powergrid using 3 different methods: pygame, matplotlib or plotly. The display method is defined when you create a "plotting" object as shown bellow.
All functions exposed here are available for pygame, plotly and matplotlib. Fill free to switch from one to the other in order to see the differences.
The next cell will plot the names of each object on the powergrid, as well as their id.
from grid2op.Plot import Plotting plot_helper = Plotting(env.observation_space, display_mod="matplotlib" # all available values are : "matplotlib", "pygame" or "plotly" ) plot_helper.plot_layout()
/home/benjamin/Documents/grid2op_test/getting_started/grid2op/Plot/Plotting.py:47: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
(<Figure size 1080x1080 with 1 Axes>, <matplotlib.axes._subplots.AxesSubplot at 0x7f3182b9a5f8>)
It is also possible to display some "external" information on this layout, for example, you can plot the thermal limit of each powerlines:
(<Figure size 1080x1080 with 1 Axes>, <matplotlib.axes._subplots.AxesSubplot at 0x7f3183253908>)
The argument "line_info" shows that you want to plot information about powerlines (here the thermal limit). The argument "colormap=line" is present to indicate you want to color differently the different values on the powerlines. As you can notice, the higher thermal limit are displayed in a darker color.
It is also possible to display information abouts loads, generators or substation in the same manner.
For this part, we highly recommend to use "plotly" method, as it allows more user interactions than a bare matplotlib figure, for example it is possible to zoom in or out.
plot_helper = Plotting(env.observation_space, display_mod="plotly" # all available values are : "matplotlib", "pygame" or "plotly" ) obs = env.reset() _ = plot_helper.plot_obs(obs)