-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from BDonnot/l2rpn2019
Fixing import bug
- Loading branch information
Showing
17 changed files
with
306 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Learning to Run, 2019 edition | ||
|
||
This folder present all the informations needed to reproduce the L2RPN competition locally. | ||
It has helpers to download the data, as well as pre-defined scripts to run locally an agent on | ||
conditions that are as close as possible to the codalab environment. | ||
|
||
It also has the getting started notebooks for this previous competition. | ||
|
||
TODO: add getting started of the competition, plus the notebooks to make agent run locally. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import sys | ||
import grid2op | ||
import grid2op.main | ||
import argparse | ||
|
||
import pdb | ||
|
||
from grid2op.ChronicsHandler import GridStateFromFileWithForecasts | ||
from grid2op.Runner import Runner | ||
from grid2op.Reward import L2RPNReward | ||
from grid2op.Settings_L2RPN2019 import L2RPN2019_DICT_NAMES, L2RPN2019_CASEFILE | ||
from grid2op.Settings_L2RPN2019 import ReadPypowNetData | ||
|
||
from datetime import timedelta | ||
import numpy as np | ||
import pandas as pd | ||
import copy | ||
|
||
|
||
PATH_DATA_DEFAULT = os.path.abspath(os.path.join("data", "data_l2rpn_2019")) | ||
PATH_DATA = PATH_DATA_DEFAULT | ||
if not os.path.exists(os.path.join("l2rpn2019_utils", "data_location.py")): | ||
# the script to download the data has been used, so i use that to retrieve where it has been installed | ||
try: | ||
from l2rpn2019_utils.data_location import L2RPN_TRAINING_SET as PATH_DATA | ||
except Exception as e: | ||
# impossible to load the data | ||
pass | ||
|
||
# todo add confirmation to download data | ||
|
||
|
||
def make_env(path_data=PATH_DATA): | ||
env = grid2op.make("l2rpn_2019", chronics_class=path_data) | ||
return env | ||
|
||
|
||
def get_submitted_controller(submission_dir): | ||
sys.path.append(submission_dir) | ||
try: | ||
import submission | ||
except ImportError: | ||
raise ImportError('The submission folder provided (\"{}\") should contain a file submission.py containing your ' | ||
'controler named as the class Submission.'.format(submission_dir)) | ||
|
||
try: | ||
submitted_controler = submission.Submission | ||
except: | ||
raise Exception('Did not find a class named Submission within submission.py; your submission controler should' | ||
' be a class named Submission in submission.py file directly within the ZIP submission file.') | ||
return submitted_controler | ||
|
||
|
||
def main(path_save=None, | ||
submission_dir=".", | ||
nb_episode=1, | ||
nb_process=1, | ||
path_chronics=PATH_DATA, | ||
path_parameters=None): | ||
|
||
if path_save is not None: | ||
path_save = os.path.abspath(path_save) | ||
else: | ||
path_save = None | ||
|
||
submitted_controler = get_submitted_controller(submission_dir) | ||
|
||
res = grid2op.main.main(nb_episode=nb_episode, | ||
agent_class=submitted_controler, | ||
path_casefile=L2RPN2019_CASEFILE, | ||
path_chronics=path_chronics, | ||
names_chronics_to_backend=L2RPN2019_DICT_NAMES, | ||
gridStateclass_kwargs={"gridvalueClass": ReadPypowNetData}, | ||
reward_class=L2RPNReward, | ||
path_save=path_save, | ||
nb_process=nb_process, | ||
path_parameters=path_parameters) | ||
if path_save is not None: | ||
print("Done and data saved in : \"{}\"".format(path_save)) | ||
return res | ||
|
||
|
||
def get_runner(path_chronics=PATH_DATA, | ||
submission_dir="."): | ||
submitted_controler = get_submitted_controller(submission_dir) | ||
runner = Runner(init_grid_path=L2RPN2019_CASEFILE, | ||
path_chron=path_chronics, | ||
names_chronics_to_backend=L2RPN2019_DICT_NAMES, | ||
gridStateclass_kwargs={"gridvalueClass": ReadPypowNetData}, | ||
rewardClass=L2RPNReward, | ||
agentClass=submitted_controler) | ||
return runner | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
This utility file helps downloading the data for the L2RPN 2019. | ||
Data are stored as a github "release" accessible at the url: | ||
`https://github.com/BDonnot/Grid2Op/releases/download/data_l2rpn_2019/data_l2rpn_2019.tar.bz2` | ||
Once downloaded, the dataset is uncompressed. It is composed of the exact same files provided for the first edition of | ||
the 2019 L2RPN challenge. There are 1004 chronics of 4 weeks corresponding to january for the fictive grid used | ||
for this competition. | ||
This script works on MacOs, Linux and windows. | ||
""" | ||
import os | ||
import argparse | ||
import io | ||
import sys | ||
from tqdm import tqdm | ||
import re | ||
|
||
import tarfile | ||
|
||
import pdb | ||
try: | ||
import urllib.request | ||
except Exception as e: | ||
raise RuntimeError("Impossible to find library urllib. Please install it.") | ||
|
||
URL = "https://github.com/BDonnot/Grid2Op/releases/download/data_l2rpn_2019/data_l2rpn_2019.tar.bz2" | ||
DEFAULT_PATH_DATA = "data" | ||
|
||
|
||
class DownloadProgressBar(tqdm): | ||
""" | ||
This class is here to show the progress bar when downloading this dataset | ||
""" | ||
def update_to(self, b=1, bsize=1, tsize=None): | ||
if tsize is not None: | ||
self.total = tsize | ||
self.update(b * bsize - self.n) | ||
|
||
|
||
def download_url(url, output_path): | ||
""" | ||
This function download the file located at 'url' and save it to 'output_path' | ||
Parameters | ||
---------- | ||
url: ``str`` | ||
The url of the file to download | ||
output_path: ``str`` | ||
The path where the data will be stored. | ||
""" | ||
with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t: | ||
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Launch the evaluation of the Grid2Op ("Grid To Operate") code.') | ||
parser.add_argument('--path_save', default=DEFAULT_PATH_DATA, type=str, | ||
help='The path where the data will be downloaded.') | ||
args = parser.parse_args() | ||
path_data = args.path_save | ||
|
||
if not os.path.exists(path_data): | ||
print("Creating path \"{}\" where l2rpn2019 data will be downloaded".format(path_data)) | ||
os.mkdir(path_data) | ||
output_path = os.path.abspath(os.path.join(path_data, "data_l2rpn_2019.tar.bz2")) | ||
|
||
# download the data (with progress bar) | ||
print("downloading the training data, this may take a while.") | ||
download_url(URL, output_path) | ||
|
||
tar = tarfile.open(output_path, "r:bz2") | ||
print("Extract the tar archive in {}".format(path_data)) | ||
tar.extractall(path_data) | ||
tar.close() | ||
file_location = os.path.split(os.path.abspath(__file__))[0] | ||
output_path_str = re.sub("\\\\", "\\\\\\\\", output_path) | ||
with open(os.path.join(file_location, "data_location.py"), "w") as f: | ||
f.write("# This file has been automatically generated by 'download_training_data.py' do not modify it, " | ||
"nor remove it.\n# If you want to download the training data again, run " | ||
"'python l2rpn2019_utils/download_training_data.py'\n\n\n" | ||
"L2RPN_TRAINING_SET = '{}'\n".format(output_path_str)) |
Oops, something went wrong.