Skip to content

Commit

Permalink
Merge pull request #506 from rte-france/dev_1.9.3
Browse files Browse the repository at this point in the history
Dev 1.9.3
  • Loading branch information
BDonnot authored Jul 28, 2023
2 parents 6ed1b28 + ed9c589 commit 57fbb01
Show file tree
Hide file tree
Showing 43 changed files with 4,156 additions and 35 deletions.
170 changes: 170 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: CI

on:
push:
branches:
- '*'
tags:
- 'v*.*.*'

jobs:
manylinux_build:
name: Build linux ${{ matrix.python.name }} wheel
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
strategy:
matrix:
python:
- {
name: cp38,
abi: cp38,
version: '3.8',
}
- {
name: cp39,
abi: cp39,
version: '3.9',
}
- {
name: cp310,
abi: cp310,
version: '3.10',
}
- {
name: cp311,
abi: cp311,
version: '3.11',
}

steps:

- name: Checkout sources
uses: actions/checkout@v1
with:
submodules: true

- name: Setup path
run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade wheel
- name: Build wheel
run: |
python3 setup.py bdist_wheel
# auditwheel repair dist/*.whl # only for compiled code !
- name: Install wheel
run: pip3 install dist/*.whl --user

- name: Check package can be imported
run: |
python3 -c "import grid2op"
python3 -c "from grid2op import *"
python3 -c "from grid2op.Action._backendAction import _BackendAction"
- name: Upload wheel
uses: actions/upload-artifact@v2
with:
name: grid2op-wheel-${{ matrix.config.name }}-${{ matrix.python.name }}
path: dist/*.whl

macos_windows_build:
name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- {
name: darwin,
os: macos-latest,
}
- {
name: windows,
os: windows-2019,
}
python:
- {
name: cp38,
version: '3.8',
}
- {
name: cp39,
version: '3.9',
}
- {
name: cp310,
version: '3.10',
}
- {
name: cp311,
version: '3.11',
}

steps:

- name: Checkout sources
uses: actions/checkout@v1
with:
submodules: true

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python.version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade wheel
- name: Build wheel
run: python setup.py bdist_wheel

- name: Install wheel
shell: bash
run: python -m pip install dist/*.whl --user

- name: Check package can be imported
run: |
python3 -c "import grid2op"
python3 -c "from grid2op import *"
python3 -c "from grid2op.Action._backendAction import _BackendAction"
- name: Build source archive
if: matrix.config.name == 'darwin' && matrix.python.name == 'cp39'
run: python setup.py sdist

- name: Upload wheel
uses: actions/upload-artifact@v2
with:
name: grid2op-wheel-${{ matrix.config.name }}-${{ matrix.python.name }}
path: dist/*.whl

- name: Upload source archive
uses: actions/upload-artifact@v2
if: matrix.config.name == 'darwin' && matrix.python.name == 'cp39'
with:
name: grid2op-sources
path: dist/*.tar.gz

package:
name: Test install
runs-on: ubuntu-latest
needs: [manylinux_build, macos_windows_build]

steps:
- name: Download wheels
uses: actions/download-artifact@v2
with:
path: download

- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: grid2op-wheels
path: |
download/**/*.whl
download/**/*.tar.gz
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ Change Log
- [???] "asynch" multienv
- [???] properly model interconnecting powerlines

[1.9.3] - 2023-07-28
---------------------
- [BREAKING] the "chronix2grid" dependency now points to chronix2grid and not to the right branch
this might cause an issue if you install `grid2op[chronix2grid]` for the short term
- [BREAKING] force key-word arguments in `grid2op.make` except for the first one (env name), see
[rte-france#503](https://github.com/rte-france/Grid2Op/issues/503)
- [FIXED] a bug preventing to use storage units in "sim2real" environment (when the
grid for forecast is not the same as the grid for the environment)
- [ADDED] a CI to test package can be installed and loaded correctly on windows, macos and line_ex_to_sub_pos
for python 3.8, 3.9, 3.10 and 3.11
- [ADDED] possibility to change the "soft_overflow_threshold" in the parameters (like
the "hard_overflow_threshold" but for delayed protections).
See `param.SOFT_OVERFLOW_THRESHOLD`
- [ADDED] the `gym_env.observation_space.get_index(attr_nm)` for `BoxGymObsSpace` that allows to retrieve which index
of the observation represents which attribute.

[1.9.2] - 2023-07-26
---------------------
- [BREAKING] rename with filename starting with lowercase all the files in the "`Backend`", "`Action`" and
Expand Down
2 changes: 1 addition & 1 deletion grid2op/Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def next_grid_state(self, env, is_dc=False):
while True:
# simulate the cascading failure
lines_flows = 1.0 * self.get_line_flow()
thermal_limits = self.get_thermal_limit()
thermal_limits = self.get_thermal_limit() * env._parameters.SOFT_OVERFLOW_THRESHOLD # SOFT_OVERFLOW_THRESHOLD new in grid2op 1.9.3
lines_status = self.get_line_status()

# a) disconnect lines on hard overflow (that are still connected)
Expand Down
23 changes: 14 additions & 9 deletions grid2op/MakeEnv/Make.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import os
import warnings
import pkg_resources
from typing import Union, Optional
import logging

from grid2op.Environment import Environment
from grid2op.MakeEnv.MakeFromPath import make_from_dataset_path, ERR_MSG_KWARGS
Expand Down Expand Up @@ -265,26 +267,30 @@ def _aux_make_multimix(


def make(
dataset=None,
test=False,
logger=None,
experimental_read_from_local_dir=False,
_add_to_name="",
_compat_glop_version=None,
dataset : Union[str, os.PathLike]=None,
*,
test : bool=False,
logger: Optional[logging.Logger]=None,
experimental_read_from_local_dir : bool=False,
_add_to_name : str="",
_compat_glop_version : Optional[str]=None,
**kwargs
) -> Environment:
"""
This function is a shortcut to rapidly create some (pre defined) environments within the grid2op Framework.
This function is a shortcut to rapidly create some (pre defined) environments within the grid2op framework.
Other environments, with different powergrids will be made available in the future and will be easily downloadable
using this function.
It mimic the `gym.make` function.
.. versionchanged:: 1.9.3
Remove the possibility to use this function with arguments (force kwargs)
Parameters
----------
dataset: ``str``
dataset: ``str`` or path
Name of the environment you want to create
test: ``bool``
Expand Down Expand Up @@ -334,7 +340,6 @@ def make(
downloaded from the internet, sizes vary per dataset.
"""

if _force_test_dataset():
if not test:
warnings.warn(f"The environment variable \"{_VAR_FORCE_TEST}\" is defined so grid2op will be forced in \"test\" mode. "
Expand Down
2 changes: 1 addition & 1 deletion grid2op/Observation/observationSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _create_obs_env(self, env):
def _aux_create_backend(self, env, observation_bk_class, observation_bk_kwargs, path_grid_for):
if observation_bk_kwargs is None:
observation_bk_kwargs = env.backend._my_kwargs
observation_bk_class_used = observation_bk_class.init_grid(env.backend)
observation_bk_class_used = observation_bk_class.init_grid(type(env.backend))
self._backend_obs = observation_bk_class_used(**observation_bk_kwargs)
self._backend_obs.set_env_name(env.name)
self._backend_obs.load_grid(path_grid_for)
Expand Down
34 changes: 34 additions & 0 deletions grid2op/Parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class Parameters:
HARD_OVERFLOW_THRESHOLD is 2.0, then if the flow on the powerline reaches 2 * 150 = 300.0 the powerline
the powerline is automatically disconnected.
SOFT_OVERFLOW_THRESHOLD: ``float``
.. versionadded:: 1.9.3
Threshold above which delayed protection are triggered. A line with its current bellow `SOFT_OVERFLOW_THRESHOLD * thermal_limit`
then nothing happens. If it's above the delay start. And if it's above `SOFT_OVERFLOW_THRESHOLD * thermal_limit`
for more than :attr:`NB_TIMESTEP_OVERFLOW_ALLOWED` consecutive steps.
ENV_DC: ``bool``
Whether or not making the simulations of the environment in the "direct current" approximation. This can be
usefull for early training of agent, as this mode is much faster to compute than the corresponding
Expand Down Expand Up @@ -171,6 +178,8 @@ def __init__(self, parameters_path=None):
# for example setting "HARD_OVERFLOW_THRESHOLD = 2" is equivalent, if a powerline has a thermal limit of
# 243 A, to disconnect it instantly if it has a powerflow higher than 2 * 243 = 486 A
self.HARD_OVERFLOW_THRESHOLD = dt_float(2.0)

self.SOFT_OVERFLOW_THRESHOLD = dt_float(1.0)

# are the powerflow performed by the environment in DC mode (dc powerflow) or AC (ac powerflow)
self.ENV_DC = False
Expand Down Expand Up @@ -296,6 +305,9 @@ def init_from_dict(self, dict_):

if "HARD_OVERFLOW_THRESHOLD" in dict_:
self.HARD_OVERFLOW_THRESHOLD = dt_float(dict_["HARD_OVERFLOW_THRESHOLD"])

if "SOFT_OVERFLOW_THRESHOLD" in dict_:
self.SOFT_OVERFLOW_THRESHOLD = dt_float(dict_["SOFT_OVERFLOW_THRESHOLD"])

if "ENV_DC" in dict_:
self.ENV_DC = Parameters._isok_txt(dict_["ENV_DC"])
Expand Down Expand Up @@ -390,6 +402,7 @@ def to_dict(self):
res["NB_TIMESTEP_OVERFLOW_ALLOWED"] = int(self.NB_TIMESTEP_OVERFLOW_ALLOWED)
res["NB_TIMESTEP_RECONNECTION"] = int(self.NB_TIMESTEP_RECONNECTION)
res["HARD_OVERFLOW_THRESHOLD"] = float(self.HARD_OVERFLOW_THRESHOLD)
res["SOFT_OVERFLOW_THRESHOLD"] = float(self.SOFT_OVERFLOW_THRESHOLD)
res["ENV_DC"] = bool(self.ENV_DC)
res["FORECAST_DC"] = bool(self.FORECAST_DC)
res["MAX_SUB_CHANGED"] = int(self.MAX_SUB_CHANGED)
Expand Down Expand Up @@ -529,6 +542,27 @@ def check_valid(self):
"HARD_OVERFLOW_THRESHOLD < 1., this should be >= 1. (use env.set_thermal_limit "
"to modify the thermal limit)"
)

try:
self.SOFT_OVERFLOW_THRESHOLD = float(
self.SOFT_OVERFLOW_THRESHOLD
) # to raise if numpy array
self.SOFT_OVERFLOW_THRESHOLD = dt_float(self.SOFT_OVERFLOW_THRESHOLD)
except Exception as exc_:
raise RuntimeError(
f'Impossible to convert SOFT_OVERFLOW_THRESHOLD to float with error \n:"{exc_}"'
)
if self.SOFT_OVERFLOW_THRESHOLD < 1.0:
raise RuntimeError(
"SOFT_OVERFLOW_THRESHOLD < 1., this should be >= 1. (use env.set_thermal_limit "
"to modify the thermal limit)"
)
if self.SOFT_OVERFLOW_THRESHOLD >= self.HARD_OVERFLOW_THRESHOLD:
raise RuntimeError(
"self.SOFT_OVERFLOW_THRESHOLD >= self.HARD_OVERFLOW_THRESHOLD this would that the"
"soft overflow would be deactivated. It's not possible at the moment."
)

try:
if not isinstance(self.ENV_DC, (bool, dt_bool)):
raise RuntimeError("NO_OVERFLOW_DISCONNECTION should be a boolean")
Expand Down
7 changes: 5 additions & 2 deletions grid2op/Runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import warnings
import copy
from multiprocessing import Pool
from typing import Tuple, Optional, List
from typing import Tuple, Optional, List, Union

from grid2op.Environment import BaseEnv
from grid2op.Action import BaseAction, TopologyAction, DontAct
Expand Down Expand Up @@ -41,7 +41,10 @@
# so i force the usage of the "starmap" stuff even if there is one process on windows
from grid2op._glop_platform_info import _IS_WINDOWS, _IS_LINUX, _IS_MACOS

runner_returned_type = Tuple[str, str, float, int, int, Optional[EpisodeData], Optional[int]]
runner_returned_type = Union[Tuple[str, str, float, int, int],
Tuple[str, str, float, int, int, EpisodeData],
Tuple[str, str, float, int, int, EpisodeData, int]]

# TODO have a vectorized implementation of everything in case the agent is able to act on multiple environment
# at the same time. This might require a lot of work, but would be totally worth it!
# (especially for Neural Net based agents)
Expand Down
14 changes: 10 additions & 4 deletions grid2op/Space/GridObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ class GridObjects:
alertable_line_names = [] # name of each line to produce an alert on # TODO
alertable_line_ids = []

# test
_IS_INIT = False

def __init__(self):
"""nothing to do when an object of this class is created, the information is held by the class attributes"""
pass
Expand Down Expand Up @@ -663,7 +666,7 @@ def _clear_class_attribute(cls):
cls.attr_nan_list_set = set()

# class been init
# __is_init = False
cls._IS_INIT = False

# name of the objects
cls.env_name = "unknown"
Expand Down Expand Up @@ -1255,8 +1258,9 @@ def _init_class_attr(self, obj=None):
setattr(cls, attr_nm, attr)

def _compute_pos_big_topo(self):
# TODO move the object attribute as class attribute !
self._init_class_attr()
# move the object attribute as class attribute !
if not type(self)._IS_INIT:
self._init_class_attr()
cls = type(self)
cls._compute_pos_big_topo_cls()

Expand Down Expand Up @@ -2702,7 +2706,9 @@ def init_grid(cls, gridobj, force=False, extra_name=None, force_module=None):
else:
# i am the original class from grid2op
res_cls._INIT_GRID_CLS = cls


res_cls._IS_INIT = True

res_cls._compute_pos_big_topo_cls()
res_cls.process_shunt_satic_data()
if res_cls.glop_version != grid2op.__version__:
Expand Down
Loading

0 comments on commit 57fbb01

Please sign in to comment.