Skip to content

Commit ce029a7

Browse files
committed
adding more notebooks in getting_started, fix some bugs in Observations, adding logos
1 parent 6e6dbbc commit ce029a7

21 files changed

+1325
-195
lines changed

getting_started/basic_functionalities.ipynb getting_started/0_basic_functionalities.ipynb

+227-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"***Disclaimer***: This file referenced some files in other directories. In order to have working cross referencing it's recommended to start the notebook server from the root directory (`Grid2Op`) of the package and __not__ in the `getting_started` sub directory."
14+
"***Disclaimer***: This file referenced some files in other directories. In order to have working cross referencing it's recommended to start the notebook server from the root directory (`Grid2Op`) of the package and __not__ in the `getting_started` sub directory:\n",
15+
"```bash\n",
16+
"cd Grid2Op\n",
17+
"jupyter notebook\n",
18+
"```"
1519
]
1620
},
1721
{
@@ -31,14 +35,16 @@
3135
"cell_type": "markdown",
3236
"metadata": {},
3337
"source": [
38+
"**Objectives**\n",
39+
"\n",
3440
"This notebook will cover some basic raw functionality at first, and then how they are encapsulated with easy to use functions.\n",
3541
"\n",
3642
"The recommended way to use these is to through the Runner, and not by getting through the instanciation of class one by one."
3743
]
3844
},
3945
{
4046
"cell_type": "code",
41-
"execution_count": 1,
47+
"execution_count": 5,
4248
"metadata": {},
4349
"outputs": [],
4450
"source": [
@@ -47,18 +53,212 @@
4753
"import grid2op"
4854
]
4955
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 8,
59+
"metadata": {},
60+
"outputs": [
61+
{
62+
"data": {
63+
"text/html": [
64+
"<div id=\"my_id_menu_nb\">run previous cell, wait for 2 seconds</div>\n",
65+
"<script>\n",
66+
"function repeat_indent_string(n){\n",
67+
" var a = \"\" ;\n",
68+
" for ( ; n > 0 ; --n)\n",
69+
" a += \" \";\n",
70+
" return a;\n",
71+
"}\n",
72+
"// look up into all sections and builds an automated menu //\n",
73+
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item, begin_format, end_format) {\n",
74+
" var anchors = document.getElementsByClassName(\"section\");\n",
75+
" if (anchors.length == 0) {\n",
76+
" anchors = document.getElementsByClassName(\"text_cell_render rendered_html\");\n",
77+
" }\n",
78+
" var i,t;\n",
79+
" var text_menu = begin;\n",
80+
" var text_memo = \"<pre>\\nlength:\" + anchors.length + \"\\n\";\n",
81+
" var ind = \"\";\n",
82+
" var memo_level = 1;\n",
83+
" var href;\n",
84+
" var tags = [];\n",
85+
" var main_item = 0;\n",
86+
" var format_open = 0;\n",
87+
" for (i = 0; i <= llast; i++)\n",
88+
" tags.push(\"h\" + i);\n",
89+
"\n",
90+
" for (i = 0; i < anchors.length; i++) {\n",
91+
" text_memo += \"**\" + anchors[i].id + \"--\\n\";\n",
92+
"\n",
93+
" var child = null;\n",
94+
" for(t = 0; t < tags.length; t++) {\n",
95+
" var r = anchors[i].getElementsByTagName(tags[t]);\n",
96+
" if (r.length > 0) {\n",
97+
"child = r[0];\n",
98+
"break;\n",
99+
" }\n",
100+
" }\n",
101+
" if (child == null) {\n",
102+
" text_memo += \"null\\n\";\n",
103+
" continue;\n",
104+
" }\n",
105+
" if (anchors[i].hasAttribute(\"id\")) {\n",
106+
" // when converted in RST\n",
107+
" href = anchors[i].id;\n",
108+
" text_memo += \"#1-\" + href;\n",
109+
" // passer à child suivant (le chercher)\n",
110+
" }\n",
111+
" else if (child.hasAttribute(\"id\")) {\n",
112+
" // in a notebook\n",
113+
" href = child.id;\n",
114+
" text_memo += \"#2-\" + href;\n",
115+
" }\n",
116+
" else {\n",
117+
" text_memo += \"#3-\" + \"*\" + \"\\n\";\n",
118+
" continue;\n",
119+
" }\n",
120+
" var title = child.textContent;\n",
121+
" var level = parseInt(child.tagName.substring(1,2));\n",
122+
"\n",
123+
" text_memo += \"--\" + level + \"?\" + lfirst + \"--\" + title + \"\\n\";\n",
124+
"\n",
125+
" if ((level < lfirst) || (level > llast)) {\n",
126+
" continue ;\n",
127+
" }\n",
128+
" if (title.endsWith('¶')) {\n",
129+
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\")\n",
130+
" .replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\");\n",
131+
" }\n",
132+
" if (title.length == 0) {\n",
133+
" continue;\n",
134+
" }\n",
135+
"\n",
136+
" while (level < memo_level) {\n",
137+
" text_menu += end_format + \"</ul>\\n\";\n",
138+
" format_open -= 1;\n",
139+
" memo_level -= 1;\n",
140+
" }\n",
141+
" if (level == lfirst) {\n",
142+
" main_item += 1;\n",
143+
" }\n",
144+
" if (keep_item != -1 && main_item != keep_item + 1) {\n",
145+
" // alert(main_item + \" - \" + level + \" - \" + keep_item);\n",
146+
" continue;\n",
147+
" }\n",
148+
" while (level > memo_level) {\n",
149+
" text_menu += \"<ul>\\n\";\n",
150+
" memo_level += 1;\n",
151+
" }\n",
152+
" text_menu += repeat_indent_string(level-2);\n",
153+
" text_menu += begin_format + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
154+
" format_open += 1;\n",
155+
" }\n",
156+
" while (1 < memo_level) {\n",
157+
" text_menu += end_format + \"</ul>\\n\";\n",
158+
" memo_level -= 1;\n",
159+
" format_open -= 1;\n",
160+
" }\n",
161+
" text_menu += send;\n",
162+
" //text_menu += \"\\n\" + text_memo;\n",
163+
"\n",
164+
" while (format_open > 0) {\n",
165+
" text_menu += end_format;\n",
166+
" format_open -= 1;\n",
167+
" }\n",
168+
" return text_menu;\n",
169+
"};\n",
170+
"var update_menu = function() {\n",
171+
" var sbegin = \"\";\n",
172+
" var sformat = '<a href=\"#__HREF__\">__TITLE__</a>';\n",
173+
" var send = \"\";\n",
174+
" var begin_format = '<li>';\n",
175+
" var end_format = '</li>';\n",
176+
" var keep_item = -1;\n",
177+
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item,\n",
178+
" begin_format, end_format);\n",
179+
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
180+
" menu.innerHTML=text_menu;\n",
181+
"};\n",
182+
"window.setTimeout(update_menu,2000);\n",
183+
" </script>"
184+
],
185+
"text/plain": [
186+
"<IPython.core.display.HTML object>"
187+
]
188+
},
189+
"execution_count": 8,
190+
"metadata": {},
191+
"output_type": "execute_result"
192+
}
193+
],
194+
"source": [
195+
"res = None\n",
196+
"try:\n",
197+
" from jyquickhelper import add_notebook_menu\n",
198+
" res = add_notebook_menu()\n",
199+
"except ModuleNotFoundError:\n",
200+
" print(\"Impossible to automatically add a menu / table of content to this notebook.\\nYou can download \\\"jyquickhelper\\\" package with: \\n\\\"pip install jyquickhelper\\\"\")\n",
201+
"res"
202+
]
203+
},
204+
{
205+
"cell_type": "markdown",
206+
"metadata": {},
207+
"source": [
208+
"## 0) Summary of RL method"
209+
]
210+
},
50211
{
51212
"cell_type": "markdown",
52213
"metadata": {},
53214
"source": [
54-
"## Creating an Environement: Step by Step explanation of the basic classes of this package"
215+
"Though the `Grid2Op` package can be used to perform many different tasks, these set of notebooks will be focused on the machine learning part, and its usage in a Reinforcement learning framework. \n",
216+
"\n",
217+
"The reinforcement learning is a framework that allows to train \"agent\" to solve time dependant domain. We tried to cast the grid operation planning into this framework. The package `Grid2Op` was inspired by it."
55218
]
56219
},
57220
{
58221
"cell_type": "markdown",
59222
"metadata": {},
60223
"source": [
61-
"### Get Data to feed the powergrid"
224+
"In a reinforcement learning (RL), there are 2 distinct entities:\n",
225+
"* **Environment**: is a modeling of the \"world\" in which the *agent* takes some *actions* to achieve some pre definite objectives.\n",
226+
"* **Agent**: will do actions on the environment that will have consequences.\n",
227+
"\n",
228+
"These 2 entities exchange 3 main type of information:\n",
229+
"* **Action**: it's an information sent by the Agent that will modify the internal state of the environment.\n",
230+
"* **State** / **Observation**: is the (partial) view of the environment by the Agent. The Agent receive a new state after each actions. He can use the observation (state) at time step *t* to take the action at time *t*.\n",
231+
"* **Reward**: is the score received by the agent for the previous action.\n",
232+
"\n",
233+
"A schematic representaiton of this is shown in the figure bellow:"
234+
]
235+
},
236+
{
237+
"cell_type": "markdown",
238+
"metadata": {},
239+
"source": [
240+
"![title](img/reinforcement-learning.jpg)"
241+
]
242+
},
243+
{
244+
"cell_type": "markdown",
245+
"metadata": {},
246+
"source": [
247+
"In this notebook, we will develop a simple Agent that takes some action (powerline disconnection) based on the observation of the environment."
248+
]
249+
},
250+
{
251+
"cell_type": "markdown",
252+
"metadata": {},
253+
"source": [
254+
"## I) Creating an Environement: Step by Step explanation of the basic classes of this package"
255+
]
256+
},
257+
{
258+
"cell_type": "markdown",
259+
"metadata": {},
260+
"source": [
261+
"### I.A) Get Data to feed the powergrid"
62262
]
63263
},
64264
{
@@ -120,7 +320,7 @@
120320
"cell_type": "markdown",
121321
"metadata": {},
122322
"source": [
123-
"### Get a Backend to carry out the computations"
323+
"### I.B) Get a Backend to carry out the computations"
124324
]
125325
},
126326
{
@@ -153,7 +353,7 @@
153353
"cell_type": "markdown",
154354
"metadata": {},
155355
"source": [
156-
"### Getting the parameters of the game"
356+
"### I.C) Getting the parameters of the game"
157357
]
158358
},
159359
{
@@ -177,7 +377,7 @@
177377
"cell_type": "markdown",
178378
"metadata": {},
179379
"source": [
180-
"### Building the Environment"
380+
"### I.D) Building the Environment"
181381
]
182382
},
183383
{
@@ -214,7 +414,7 @@
214414
"cell_type": "markdown",
215415
"metadata": {},
216416
"source": [
217-
"## Creating an Agent"
417+
"## II) Creating an Agent"
218418
]
219419
},
220420
{
@@ -242,7 +442,7 @@
242442
"cell_type": "markdown",
243443
"metadata": {},
244444
"source": [
245-
"## Assess how the Agent is performing"
445+
"## III) Assess how the Agent is performing"
246446
]
247447
},
248448
{
@@ -301,7 +501,7 @@
301501
"cell_type": "markdown",
302502
"metadata": {},
303503
"source": [
304-
"## More convenient ways to perform all these operations"
504+
"## IV) More convenient ways to perform all these operations"
305505
]
306506
},
307507
{
@@ -326,7 +526,7 @@
326526
"cell_type": "markdown",
327527
"metadata": {},
328528
"source": [
329-
"### Using the grid2op.main API"
529+
"### IV.A) Using the grid2op.main API"
330530
]
331531
},
332532
{
@@ -400,7 +600,7 @@
400600
"cell_type": "markdown",
401601
"metadata": {},
402602
"source": [
403-
"This is particularly suited to evaluate different agents, for example we can quickly evaluate a second agent. This Agent will simulate the effect of disconnecting each powerline on the powergrid and take the best action found (its execution can take a long time, depending on the scenario and the amount of powerlines on the grid)."
603+
"This is particularly suited to evaluate different agents, for example we can quickly evaluate a second agent. This Agent will simulate the effect of disconnecting each powerline on the powergrid and take the best action found (its execution can take a long time, depending on the scenario and the amount of powerlines on the grid). **The execution of the code below can take a few minutes**"
404604
]
405605
},
406606
{
@@ -480,7 +680,7 @@
480680
},
481681
{
482682
"cell_type": "code",
483-
"execution_count": 15,
683+
"execution_count": 14,
484684
"metadata": {},
485685
"outputs": [
486686
{
@@ -503,6 +703,20 @@
503703
"source": [
504704
"All the informations saved are showed above. For more information about them, please don't hesitate to read the documentation of [Runner](../documentation/html/runner.html) (if compiled locally) or consult the [Runner.py](../grid2op/Runner.py) file."
505705
]
706+
},
707+
{
708+
"cell_type": "markdown",
709+
"metadata": {},
710+
"source": [
711+
"### IV.B) Using the Runner class"
712+
]
713+
},
714+
{
715+
"cell_type": "markdown",
716+
"metadata": {},
717+
"source": [
718+
"**coming soon**"
719+
]
506720
}
507721
],
508722
"metadata": {

0 commit comments

Comments
 (0)