|
11 | 11 | "cell_type": "markdown",
|
12 | 12 | "metadata": {},
|
13 | 13 | "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 | + "```" |
15 | 19 | ]
|
16 | 20 | },
|
17 | 21 | {
|
|
31 | 35 | "cell_type": "markdown",
|
32 | 36 | "metadata": {},
|
33 | 37 | "source": [
|
| 38 | + "**Objectives**\n", |
| 39 | + "\n", |
34 | 40 | "This notebook will cover some basic raw functionality at first, and then how they are encapsulated with easy to use functions.\n",
|
35 | 41 | "\n",
|
36 | 42 | "The recommended way to use these is to through the Runner, and not by getting through the instanciation of class one by one."
|
37 | 43 | ]
|
38 | 44 | },
|
39 | 45 | {
|
40 | 46 | "cell_type": "code",
|
41 |
| - "execution_count": 1, |
| 47 | + "execution_count": 5, |
42 | 48 | "metadata": {},
|
43 | 49 | "outputs": [],
|
44 | 50 | "source": [
|
|
47 | 53 | "import grid2op"
|
48 | 54 | ]
|
49 | 55 | },
|
| 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(\"<\", \"<\")\n", |
| 130 | + " .replace(\">\", \">\").replace(\"&\", \"&\");\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 | + }, |
50 | 211 | {
|
51 | 212 | "cell_type": "markdown",
|
52 | 213 | "metadata": {},
|
53 | 214 | "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." |
55 | 218 | ]
|
56 | 219 | },
|
57 | 220 | {
|
58 | 221 | "cell_type": "markdown",
|
59 | 222 | "metadata": {},
|
60 | 223 | "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 | + "" |
| 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" |
62 | 262 | ]
|
63 | 263 | },
|
64 | 264 | {
|
|
120 | 320 | "cell_type": "markdown",
|
121 | 321 | "metadata": {},
|
122 | 322 | "source": [
|
123 |
| - "### Get a Backend to carry out the computations" |
| 323 | + "### I.B) Get a Backend to carry out the computations" |
124 | 324 | ]
|
125 | 325 | },
|
126 | 326 | {
|
|
153 | 353 | "cell_type": "markdown",
|
154 | 354 | "metadata": {},
|
155 | 355 | "source": [
|
156 |
| - "### Getting the parameters of the game" |
| 356 | + "### I.C) Getting the parameters of the game" |
157 | 357 | ]
|
158 | 358 | },
|
159 | 359 | {
|
|
177 | 377 | "cell_type": "markdown",
|
178 | 378 | "metadata": {},
|
179 | 379 | "source": [
|
180 |
| - "### Building the Environment" |
| 380 | + "### I.D) Building the Environment" |
181 | 381 | ]
|
182 | 382 | },
|
183 | 383 | {
|
|
214 | 414 | "cell_type": "markdown",
|
215 | 415 | "metadata": {},
|
216 | 416 | "source": [
|
217 |
| - "## Creating an Agent" |
| 417 | + "## II) Creating an Agent" |
218 | 418 | ]
|
219 | 419 | },
|
220 | 420 | {
|
|
242 | 442 | "cell_type": "markdown",
|
243 | 443 | "metadata": {},
|
244 | 444 | "source": [
|
245 |
| - "## Assess how the Agent is performing" |
| 445 | + "## III) Assess how the Agent is performing" |
246 | 446 | ]
|
247 | 447 | },
|
248 | 448 | {
|
|
301 | 501 | "cell_type": "markdown",
|
302 | 502 | "metadata": {},
|
303 | 503 | "source": [
|
304 |
| - "## More convenient ways to perform all these operations" |
| 504 | + "## IV) More convenient ways to perform all these operations" |
305 | 505 | ]
|
306 | 506 | },
|
307 | 507 | {
|
|
326 | 526 | "cell_type": "markdown",
|
327 | 527 | "metadata": {},
|
328 | 528 | "source": [
|
329 |
| - "### Using the grid2op.main API" |
| 529 | + "### IV.A) Using the grid2op.main API" |
330 | 530 | ]
|
331 | 531 | },
|
332 | 532 | {
|
|
400 | 600 | "cell_type": "markdown",
|
401 | 601 | "metadata": {},
|
402 | 602 | "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**" |
404 | 604 | ]
|
405 | 605 | },
|
406 | 606 | {
|
|
480 | 680 | },
|
481 | 681 | {
|
482 | 682 | "cell_type": "code",
|
483 |
| - "execution_count": 15, |
| 683 | + "execution_count": 14, |
484 | 684 | "metadata": {},
|
485 | 685 | "outputs": [
|
486 | 686 | {
|
|
503 | 703 | "source": [
|
504 | 704 | "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."
|
505 | 705 | ]
|
| 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 | + ] |
506 | 720 | }
|
507 | 721 | ],
|
508 | 722 | "metadata": {
|
|
0 commit comments