Skip to content

Commit

Permalink
trying to fix a weird bug on the jupyter notebook, that works when ru…
Browse files Browse the repository at this point in the history
…n one by one, run when executing the relevant unnit test, but fails when running all unnit tests at once...
  • Loading branch information
BDonnot committed Jun 22, 2021
1 parent 51078b5 commit ec5797b
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 143 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ RUN apt-get update && \
git \
ssh \
tar \
gzip \
ca-certificates
gzip

# Retrieve Grid2Op
RUN git clone https://github.com/BDonnot/Grid2Op
RUN git clone https://github.com/rte-france/Grid2Op

# Install in edit mode for testing
# Install Grid2Op
WORKDIR /Grid2Op
# Use the latest release
RUN git pull
RUN pip3 install -e .[optional]
RUN git remote update
RUN git fetch --all --tags
RUN git checkout "tags/v1.6.0" -b "v1.6.0-branch"
# Install Dependencies
RUN pip3 install .[optional,challenge]
WORKDIR /

# Make port 80 available to the world outside this container
Expand Down
14 changes: 0 additions & 14 deletions getting_started/00_Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,6 @@
"# III Other materials <a class=\"anchor\" id=\"other_mat\"></a>\n",
"Other useful informations are provided in the white paper [Reinforcement Learning for Electricity Network Operation](https://arxiv.org/abs/2003.07339) presented for the L2RPN 2020 Neurips edition."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
224 changes: 180 additions & 44 deletions getting_started/00_SmallExample.ipynb

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions getting_started/01_Grid2opFramework.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,6 @@
"source": [
"Using `make` and `Runner` makes it easy to assess the performance of a trained agent. Besides, the `Runner` has been particularly integrated with other tools and makes it easy to replay and analyse an episode after it is finished. It is the recommended method to use in grid2op for the evaluation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
14 changes: 0 additions & 14 deletions getting_started/03_Action.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1328,20 +1328,6 @@
"combined_action2 = action_redispatch + action_change_bus + action_storage\n",
"print(combined_action2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions getting_started/05_StudyYourAgent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,6 @@
"\n",
"Grid2viz is a package that has been developped to help you visualize the behaviour of your agent. This will be detailed in the notebook [7_PlottingCapabilities](7_PlottingCapabilities.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions getting_started/06_Redispatching_Curtailment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,6 @@
"plt.title(f\"Evolution of the generation of generator {gen_id}\")\n",
"_ = plt.ylabel(f\"Generation for generator {gen_id} (MW)\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
10 changes: 1 addition & 9 deletions getting_started/07_MultiEnv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {},
"source": [
"**Objectives**\n",
Expand Down Expand Up @@ -441,20 +441,12 @@
"Yes there is nothing more to say about it. As long as you use one of the compatible baselines (at the date of writing):\n",
"- [DeepQSimple](https://l2rpn-baselines.readthedocs.io/en/master/DeepQSimple.html)\n",
"- [DuelQSimple](https://l2rpn-baselines.readthedocs.io/en/master/DuelQSimple.html)\n",
"- [SAC](https://l2rpn-baselines.readthedocs.io/en/master/SAC.html)\n",
"- [DuelQLeapNet](https://l2rpn-baselines.readthedocs.io/en/master/DuelQLeapNet.html)\n",
"\n",
"You do not have anything more to do :-)\n",
"\n",
"If you want to use another baseline that does not support this feature, feel free to add an issue in the l2rpn-baselines official github at this adress [https://github.com/rte-france/l2rpn-baselines/issues](https://github.com/rte-france/l2rpn-baselines/issues)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions getting_started/08_PlottingCapabilities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,6 @@
"else:\n",
" print(\"You need to copy paste the command in the cell above to run grid2viz\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions getting_started/09_EnvironmentModifications.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,6 @@
"print(\"The powerline will be unavailble for again {} time steps.\"\\\n",
" \"\".format(obs.time_before_cooldown_line[line_id_opp]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 0 additions & 7 deletions getting_started/10_StorageUnits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@
"obs6, reward6, done6, info6 = env.step(env.action_space())\n",
"print(f\"the sum of redispatching at this step is {obs6.actual_dispatch.sum():.2f} MW\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
57 changes: 43 additions & 14 deletions grid2op/tests/test_notebooks_getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.

import shutil
import copy
try:
import shutil
import copy

import pdb
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
from grid2op.tests.helper_path_test import *
import os
import unittest
import time
import warnings
CAN_COMPUTE = None
except ImportError as exc_:
CAN_COMPUTE = exc_

import pdb
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
from grid2op.tests.helper_path_test import *
import os
import unittest
import time

# TODO check these tests, they don't appear to be working

import warnings
warnings.simplefilter("error")
NOTEBOOK_PATHS = os.path.abspath(os.path.join(PATH_DATA_TEST, "../../getting_started"))
VERBOSE_TIMER = False

Expand Down Expand Up @@ -129,73 +130,101 @@ def _check_for_baselines(self):
self.skipTest("l2rpn baseline is not available")

def test_notebook0_1(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook0_1")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "00_SmallExample.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook1(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook1")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "01_Grid2opFramework.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook2(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook2")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "02_Observation.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook3(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook3")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "03_Action.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook4(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
self._check_for_baselines()
raii_ = RAII_tf_log()
timer = RAII_Timer("test_notebook4")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "04_TrainingAnAgent.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook5(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook5")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "05_StudyYourAgent.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook6(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook6")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "06_Redispatching_Curtailment.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook7(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
self._check_for_baselines()
raii_ = RAII_tf_log()
timer = RAII_Timer("test_notebook7")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "07_MultiEnv.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook8(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")

# display notebook, might not be super usefull to test it in the unit test (saves another 1-2 minutes)
return
timer = RAII_Timer("test_notebook8")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "08_PlottingCapabilities.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook9(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook9")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "09_EnvironmentModifications.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook10(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
timer = RAII_Timer("test_notebook10")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "10_StorageUnits.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook_aub(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")
raii_ = RAII_tf_log()
timer = RAII_Timer("test_notebook_aub")
notebook_filename = os.path.join(NOTEBOOK_PATHS, "AUB_EECE699_20201103_ReinforcementLearningApplication.ipynb")
self._aux_funct_notebook(notebook_filename)

def test_notebook_ieeebda(self):
if CAN_COMPUTE is not None:
self.skipTest(f"{CAN_COMPUTE}")

# this test takes 3 mins alone, for a really small benefit, so i skip it for sake of time
return
self._check_for_baselines()
Expand Down

0 comments on commit ec5797b

Please sign in to comment.