Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to version 1.7.0 #309

Merged
merged 126 commits into from
Apr 29, 2022
Merged
Changes from 1 commit
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
e4ab5c5
fixing issue rte-france#281
BDonnot Jan 25, 2022
8752708
fixing issue rte-france#282
BDonnot Jan 25, 2022
4befde9
fixing rte-france#283
BDonnot Jan 25, 2022
ffdcbe4
making difference between env_path and grid_path in Environment
BDonnot Jan 26, 2022
b34fc3b
fixing broken tests
BDonnot Jan 26, 2022
6ea4a5b
Merge pull request #147 from BDonnot/bd_dev
BDonnot Jan 27, 2022
1a13dab
Merge pull request #284 from BDonnot/master
BDonnot Jan 27, 2022
53a98c7
fixing rte-france#285
BDonnot Jan 27, 2022
c3af41a
fix a typo in a property definition
BDonnot Jan 27, 2022
415b0c0
fix another typo in a property definition
BDonnot Jan 27, 2022
b698d25
a few modif i need to integrate properly [skip ci]
BDonnot Feb 2, 2022
c7ae389
adding an exception to the error message of the environment
BDonnot Feb 3, 2022
99a9b41
update the changelog [skip ci]
BDonnot Feb 7, 2022
4a70c57
fixing bug rte-france#286
BDonnot Feb 7, 2022
c405668
fixing broken tests
BDonnot Feb 7, 2022
53035a1
Merge pull request #148 from BDonnot/bd_dev
BDonnot Feb 7, 2022
f76069a
Merge pull request #287 from BDonnot/master
BDonnot Feb 7, 2022
9f4d881
adding seeds in the gym compat to make tests reproducible
BDonnot Feb 8, 2022
15d943e
fix a bug of the shunts in the update_from_obs and start to add simul…
BDonnot Feb 8, 2022
316987f
adding attributes to the observation: gen_margin_up and gen_margin_down
BDonnot Feb 9, 2022
149619f
adding icaps env in the doc
BDonnot Feb 9, 2022
79e3833
adding some tests for the simulator, need more tests then documentation
BDonnot Feb 9, 2022
6cdd4e1
adding some tests for the simulator, need more tests then documentation
BDonnot Feb 9, 2022
06cd667
adding an 'automaton' in the enviornment to improve resiliency when h…
BDonnot Feb 10, 2022
70e2ba1
trying to add an option to limit the curtailment to make the redispat…
BDonnot Feb 10, 2022
51b81b8
limit curtailment starts to work on some simple cases
BDonnot Feb 11, 2022
71d477d
passing more tests for the extreme curtailment
BDonnot Feb 11, 2022
19d474f
quite robust tests for the redispatching in extreme cases
BDonnot Feb 11, 2022
64db946
adding some tests for the correct implementation of slack power needed
BDonnot Feb 11, 2022
79ba5dc
identify the possible location of the bug in the tests [skip ci]
BDonnot Feb 11, 2022
526d08c
one more case taken into account when limiting curtailment
BDonnot Feb 15, 2022
f3bd27c
adding new test env, moving _ObsEnv [skip ci]
BDonnot Feb 15, 2022
b3121f0
adding support for max_iter in the pandapowerr backend
BDonnot Feb 16, 2022
8d448a6
progressing in limiting the storage unit actions, some tests does not…
BDonnot Feb 16, 2022
3177b3a
still a weird bug when both storage and curtailment are limited [skip…
BDonnot Feb 16, 2022
f49c9ef
all tests work, will refacto the step functions now
BDonnot Feb 17, 2022
d08d36b
finishing the refactoring of env.step and to code the limit of curtai…
BDonnot Feb 17, 2022
e9a92bc
fixing tests for sonarcloud
BDonnot Feb 18, 2022
3edc78c
fixing broken tests for the environment
BDonnot Feb 18, 2022
43e9304
adding some tests and storage units support in the Simulator
BDonnot Feb 18, 2022
48f5646
adding a utility to plot and possibility to create an env without the…
BDonnot Mar 14, 2022
84da515
Merge branch 'bd_dev' of https://github.com/bdonnot/grid2op into bd_dev
BDonnot Mar 14, 2022
93429cf
update changelog
BDonnot Mar 14, 2022
488b358
Merge branch 'bd_dev' of https://github.com/bdonnot/grid2op into bd_dev
BDonnot Mar 14, 2022
027a183
start to add the method to generate data from grid2op [skipci]
BDonnot Mar 17, 2022
a1299f9
fix a bug in networkx
BDonnot Mar 22, 2022
35b6370
fixing conflict
BDonnot Mar 22, 2022
5a6c4ea
adding a seed to a test that appear random
BDonnot Mar 22, 2022
205f5d9
adding python 3.10 in circleci tests
BDonnot Mar 22, 2022
d4eb4be
adding the start of a doc for the simulator [skip ci]
BDonnot Mar 22, 2022
9a7f1cd
formatting the code with black
BDonnot Mar 23, 2022
e651956
adding documentation to the simulator class
BDonnot Mar 23, 2022
5ee45e3
improving code quality for sonarcloud
BDonnot Mar 23, 2022
754c934
Merge pull request #149 from BDonnot/bd_dev
BDonnot Mar 23, 2022
485c058
Merge pull request #292 from BDonnot/master
BDonnot Mar 24, 2022
cb53b70
fix a bug in runner for max_iter
BDonnot Mar 29, 2022
b45cad6
fix the test grid to silence lightsim2grid warnings
BDonnot Mar 29, 2022
b4967cc
improve the hashing of the environments
BDonnot Mar 29, 2022
0bd5efe
adding explicit action / observation classes for the competition envi…
BDonnot Mar 29, 2022
3f7638e
adding support for changing the opponent space type
BDonnot Mar 29, 2022
41b6a34
silence lightsim2grid warnings for l2rpn_* envs
BDonnot Mar 29, 2022
c98b03f
Merge pull request #150 from BDonnot/bd_dev
BDonnot Mar 30, 2022
aa7221f
Merge pull request #295 from BDonnot/master
BDonnot Mar 30, 2022
b1d86db
adding l2rpn_utils module for dedicated action / observation class fo…
BDonnot Mar 30, 2022
6decea7
Improving error message when environment cannot be updated [skip ci]
BDonnot Mar 30, 2022
a6af965
Merge pull request #151 from BDonnot/bd_dev
BDonnot Mar 30, 2022
7385d88
Merge pull request #296 from BDonnot/master
BDonnot Mar 30, 2022
1580f9c
fix the computation of the reward and scores - bug due to conversion …
BDonnot Mar 30, 2022
ed5931c
adding another thing to do before release [skip ci]
BDonnot Mar 30, 2022
94b5ece
start to add a method to limit the curtailment / storage of an action…
BDonnot Apr 1, 2022
d9f9244
fix two small
Apr 2, 2022
af15164
fix two small malformations
Apr 2, 2022
4b25843
Merge branch 'dev_1.6.6' of github.com:mowang111/Grid2Op into dev_1.6.6
Apr 2, 2022
babb17d
test past for limiting curtailment down [skip ci]
BDonnot Apr 4, 2022
b96f28a
adding functionality to limit the storage / curtailment in the action
BDonnot Apr 4, 2022
0f3d746
Merge pull request #299 from mowang111/dev_1.6.6
BDonnot Apr 4, 2022
819c1d8
improve readme.md [skip ci]
BDonnot Apr 4, 2022
21fcd85
Merge remote-tracking branch 'upstream/dev_1.6.6' into bd_dev
BDonnot Apr 4, 2022
afc83e1
improve readme and notebook on action [skip ci]
BDonnot Apr 5, 2022
82a0a10
adding the doc of act.limit_curtail_storage [skip ci]
BDonnot Apr 5, 2022
43b8ceb
adding some typing for the BaseAction [skip ci]
BDonnot Apr 5, 2022
bcbfd4f
adding a method to compute the chronix 'on the fly' using chronix2gri…
BDonnot Apr 6, 2022
2ddc6df
[skip ci] adding a first dev version of l2rpn 2022, adding some tests…
BDonnot Apr 7, 2022
fb201e4
make sure tests are made for the new functionalities
BDonnot Apr 8, 2022
0a09437
fixing a first bug of config.yaml
BDonnot Apr 8, 2022
d740eff
fixing a second bug of config.yaml
BDonnot Apr 8, 2022
5afa9c5
fixing a second bug of config.yaml 2
BDonnot Apr 8, 2022
a2651ac
fixing a second bug of config.yaml 3
BDonnot Apr 8, 2022
1d7761f
fixing a second bug of config.yaml 4
BDonnot Apr 8, 2022
787811b
fixing a second bug of config.yaml 5
BDonnot Apr 8, 2022
b355e88
fixing a second bug of config.yaml 6
BDonnot Apr 8, 2022
d96b5e1
fixing a second bug of config.yaml 7
BDonnot Apr 8, 2022
5f8ff8a
fixing a second bug of config.yaml 8
BDonnot Apr 8, 2022
abc01f1
fixing a second bug of config.yaml 9
BDonnot Apr 8, 2022
05038d7
fixing a second bug of config.yaml 10
BDonnot Apr 8, 2022
58b9671
fixing a second bug of config.yaml 11
BDonnot Apr 8, 2022
2349042
fixing a second bug of config.yaml 12
BDonnot Apr 8, 2022
6b66609
fixing a second bug of config.yaml 13
BDonnot Apr 8, 2022
ebeda0a
fixing a second bug of config.yaml 14
BDonnot Apr 8, 2022
52009a9
fixing a second bug of config.yaml 15
BDonnot Apr 8, 2022
a310539
fixing a second bug of config.yaml 16
BDonnot Apr 8, 2022
1df8f62
fixing a second bug of config.yaml 17
BDonnot Apr 8, 2022
bb4e74f
fixing a second bug of config.yaml 18
BDonnot Apr 8, 2022
56608b9
fixing broken tests
BDonnot Apr 12, 2022
ba52a7e
fix test and add doc for the new chronix class and improve some docs
BDonnot Apr 12, 2022
d3a6664
updating the changelog [skip ci]
BDonnot Apr 12, 2022
0e171c3
update config of l2rpn_wcci_2022 test env [skip ci]
BDonnot Apr 12, 2022
cbb4fed
resetting the chronix2grid dependency to master instead of bd-dev [sk…
BDonnot Apr 12, 2022
9cca5ba
refactoring the fromChronixGrid class to reduce copy paste
BDonnot Apr 12, 2022
d468241
Merge pull request #152 from BDonnot/bd_dev
BDonnot Apr 12, 2022
06b7848
Merge pull request #300 from BDonnot/master
BDonnot Apr 12, 2022
a07e87b
fix a bug when limiting the action automatically in the env
BDonnot Apr 22, 2022
87f305d
Merge pull request #153 from BDonnot/bd_dev
BDonnot Apr 22, 2022
b9c9fc9
Merge pull request #306 from BDonnot/master
BDonnot Apr 22, 2022
16a9c4e
introducing basic compatibility with 'new' openai reset api [skip ci]
BDonnot Apr 22, 2022
98bc50c
finishing the notebook 4 on the training agent
BDonnot Apr 26, 2022
8431630
adding readme [skip ci]
BDonnot Apr 26, 2022
7e1cd77
adapting the redispatching algorithm, fixing the notebook 4, 5 and 6 …
BDonnot Apr 26, 2022
d5bcc63
updating the last notebooks with more up to date information
BDonnot Apr 27, 2022
02f4026
adapt tests for modification of redispatching algorithm
BDonnot Apr 28, 2022
42797cb
update the changelog [skip ci]
BDonnot Apr 28, 2022
0f2f7a9
Merge pull request #154 from BDonnot/bd_dev
BDonnot Apr 28, 2022
5997b0a
Merge pull request #308 from BDonnot/master
BDonnot Apr 28, 2022
b4a7310
fixing rte-france#310 rte-france#311 and add tests for env.generate_c…
BDonnot Apr 29, 2022
056eb47
Merge pull request #155 from BDonnot/bd_dev
BDonnot Apr 29, 2022
823046f
Merge pull request #312 from BDonnot/master
BDonnot Apr 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding documentation to the simulator class
BDonnot committed Mar 23, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e6519564de50046b7681723959eb167590cb073e
62 changes: 60 additions & 2 deletions docs/simulator.rst
Original file line number Diff line number Diff line change
@@ -15,6 +15,14 @@ is independant of the one used by the environment.

This can for example be used for "model based reinforcement learning" or to assess the "validity" of an action in some "more extreme" conditions.

It behaves similarly to `env.step(...)` or `obs.simulate(...)` with a few key differences:

- you can "chain" the call to simulator: `simulator.predict(...).predict(...).predict(...)`
- it does not take into account the "time": no cooldown on lines nor substation, storage
"state of charge" (energy) does not decrease when you use them
- no automatic line disconnection: lines are not disconnected when they are above their limit
- no opponent will act on the grid

Usage
------

@@ -23,7 +31,7 @@ You can use it to assess if the grid state is "resilient enough" if the loads an
.. code-block:: python

import grid2op
env_name = ... # any environment name available
env_name = ... # any environment name available (eg. "l2rpn_case14_sandbox")
env = grid2op.make(env_name)

obs = env.reset()
@@ -36,14 +44,18 @@ You can use it to assess if the grid state is "resilient enough" if the loads an
gen_p_stressed = obs.gen_p * 1.05
do_nothing = env.action_space()
simulator_stressed = simulator.predict(act=do_nothing, new_gen_p=gen_p_stressed, new_load_p=load_p_stressed)
if not simulator_stressed.converged:
# the solver fails to find a solution for this action
# you are likely to run into trouble if you use that...
... # do something
obs_stressed = simulator_stressed.current_obs

You can also "chain" the call to simulators, usefull for "model based" strategies

.. code-block:: python

import grid2op
env_name = ... # any environment name available
env_name = ... # any environment name available (eg. "l2rpn_case14_sandbox")
env = grid2op.make(env_name)

obs = env.reset()
@@ -56,13 +68,59 @@ You can also "chain" the call to simulators, usefull for "model based" strategie
gen_p_stressed = obs.gen_p * 1.05
do_nothing = env.action_space()
simulator_stressed = simulator.predict(act=do_nothing, new_gen_p=gen_p_stressed, new_load_p=load_p_stressed)
if not simulator_stressed.converged:
# the solver fails to find a solution for this action
# you are likely to run into trouble if you use that...
... # do something

act1 = ...
simulator_afteract1 = simulator_stressed.predict(act=act1)
act2 = ...
simulator_afteract2 = simulator_stressed.predict(act=act2)
# etc.

Another use (though you might need to use dedicated tools for such purpose such as
https://lightsim2grid.readthedocs.io/en/latest/security_analysis.html ) is to check whether your grid is "N-1 secure" which means
that if a powerline were to be disconnected (for example by the opponent) then the state it is in would not
be too dangerous:

.. code-block:: python

import numpy as np
import grid2op
env_name = ... # any environment name available (eg. "l2rpn_case14_sandbox")
env = grid2op.make(env_name)

obs = env.reset()

#### later in the code, for example in an Agent:
simulator = obs.get_simulator()
act1 = ... # the action your agent has selected
simulator_afteract1 = simulator.predict(act=act1)

for line_id in range(obs.n_line):
act_disco_line = env.action_space()
act_disco_line.set_line_status = [(line_id, -1)]
sim_after_disco_line = simulator_afteract1.predict(act_disco_line)
if sim_after_disco_line.converged:
obs_after_disco = sim_after_disco_line.current_obs
# and for example check the current on all line is bellow the limit
if np.any(obs_after_disco.rho > 1.):
# your action does not make the grid "N-1" safe,
# because if you disconnect line `line_id` you got some overflow
... # do something
else:
# the simulator has not found any solution, it is likely that this will lead
# to a game over in "real time"
# your grid is not "N-1" safe because disconnection of line `line_id` lead
# to a non feasible grid state
... # do something

.. warning::
This module is still under development, if you need any functionality, let us know with a github "feature request"
(https://github.com/rte-france/Grid2Op/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=)


Detailed Documentation by class
--------------------------------
.. automodule:: grid2op.simulator
126 changes: 126 additions & 0 deletions grid2op/simulator/simulator.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,20 @@


class Simulator(object):
"""This class represents a "simulator". It allows to check the impact on this or that on th powergrid, quite
like what human operators have at their disposal in control rooms.

It behaves similarly to `env.step(...)` or `obs.simulate(...)` with a few key differences:

- you can "chain" the call to simulator: `simulator.predict(...).predict(...).predict(...)`
- it does not take into account the "time": no cooldown on lines nor substation, storage
"state of charge" (energy) does not decrease when you use them
- no automatic line disconnection: lines are not disconnected when they are above their limit
- no opponent will act on the grid

Please see the documentation for usage examples.

"""
def __init__(
self, backend: Optional[Backend], env: Optional[BaseEnv] = None, tol_redisp=1e-6
):
@@ -58,13 +72,33 @@ def __init__(

@property
def converged(self) -> bool:
"""

Returns
-------
bool
Whether or not the powerflow has converged
"""
return self._converged

@converged.setter
def converged(self, values):
raise SimulatorError("Cannot set this property.")

def copy(self) -> "Simulator":
"""Allows to perform a (deep) copy of the simulator.

Returns
-------
Simulator
A (deep) copy of the simulator you want to copy.

Raises
------
SimulatorError
In case the simulator is not initialized.

"""
if self.current_obs is None:
raise SimulatorError(
"Impossible to copy a non initialized Simulator. "
@@ -76,6 +110,29 @@ def copy(self) -> "Simulator":
return res

def change_backend(self, backend: Backend):
"""You can use this function in case you want to change the "solver" use to perform the computation.

For example, you could use a machine learning based model to do the computation (to accelerate them), provided
that you have at your disposal such an algorithm.

.. warning::
The backend you pass as argument should be initialized with the same grid as the one currently in use.

Notes
-----
Once changed, all the "simulator" that "derived" from this simulator will use the same backend types.

Parameters
----------
backend : Backend
Another grid2op backend you can use to perform the computation.

Raises
------
SimulatorError
When you do not pass a correct backend.

"""
if not isinstance(backend, Backend):
raise SimulatorError(
"when using change_backend function, the backend should"
@@ -86,6 +143,27 @@ def change_backend(self, backend: Backend):
self.set_state(obs=self.current_obs)

def change_backend_type(self, backend_type: type, grid_path: os.PathLike, **kwargs):
"""It allows to change the type of the backend used

Parameters
----------
backend_type : type
The new backend type
grid_path : os.PathLike
The path from where to load the powergrid
kwargs:
Extra arguments used to build the backend.

Notes
-----
Once changed, all the "simulator" that "derived" from this simulator will use the same backend types.

Raises
------
SimulatorError
if something went wrong (eg you do not pass a type, your type does not inherit from Backend, the file
located at `grid_path` does not exists etc.)
"""
if not isinstance(backend_type, type):
raise SimulatorError(
"when using change_backend_type function, the backend_type should"
@@ -119,6 +197,30 @@ def set_state(
new_load_p: np.ndarray = None,
new_load_q: np.ndarray = None,
):
"""Set the state of the simulator to a given state described by an observation (and optionally some
new loads and generation)

Parameters
----------
obs : Optional[BaseObservation], optional
The observation to get the state from, by default None
do_powerflow : bool, optional
Whether to use the underlying backend to get a consistent state after
this modification or not, by default True
new_gen_p : np.ndarray, optional
new generator active setpoint, by default None
new_gen_v : np.ndarray, optional
new generator voltage setpoint, by default None
new_load_p : np.ndarray, optional
new load active consumption, by default None
new_load_q : np.ndarray, optional
new load reactive consumption, by default None

Raises
------
SimulatorError
In case the current simulator is not initialized.
"""

if obs is not None:
self.current_obs = obs.copy()
@@ -364,6 +466,29 @@ def predict(
new_load_q: np.ndarray = None,
do_copy: bool = True,
) -> "Simulator":
"""Predict the state of the grid after a given action has been taken.

Parameters
----------
act : BaseAction
The action you want to take
new_gen_p : np.ndarray, optional
the new production active setpoint, by default None
new_gen_v : np.ndarray, optional
the new production voltage setpoint, by default None
new_load_p : np.ndarray, optional
the new consumption active values, by default None
new_load_q : np.ndarray, optional
the new consumption reactive values, by default None
do_copy : bool, optional
Whether to make a copy or not, by default True

Returns
-------
Simulator
The new simulator representing the grid state after the simulation of the action.

"""
# init the result
if do_copy:
res = self.copy()
@@ -434,6 +559,7 @@ def predict(
return res

def close(self):
"""close the underlying backend"""
if hasattr(self, "backend") and self.backend is not None:
self.backend.close()
self.backend = None
2 changes: 1 addition & 1 deletion grid2op/tests/test_MakeEnv.py
Original file line number Diff line number Diff line change
@@ -755,7 +755,7 @@ def test_hash(self):
hash_this_env = _hash_env(path_)
assert (
hash_this_env.hexdigest()
== "35791e669b84c5da16061ab6aaf3f4748d32871a16fd97ebfc7acbf83104dbc00bc7878481fe35e14236f14eb86610700734f756295675dd5d8d0d918cec3770"
== "bec981458530b8f238b014c6303622c78f8aee2fbbbedaf6449cf30da6487cd8d175e1e765f21f9a4db5269e4bed3f061f1bf97ed5f387e48463a26a86e96df2"
), f"wrong hash digest. It's \n\t{hash_this_env.hexdigest()}"