Skip to content

Commit

Permalink
Merge pull request #117 from BDonnot/master
Browse files Browse the repository at this point in the history
Upgrade to version 1.0.0
  • Loading branch information
BDonnot authored Jun 24, 2020
2 parents 195fccf + 2005def commit 333b332
Show file tree
Hide file tree
Showing 386 changed files with 19,035 additions and 11,102 deletions.
11 changes: 10 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@ assignees: ''
- Additional system information

## Bug description
A clear and concise description of what the bug is.
<!--A clear and concise description of what the bug is.-->

## How to reproduce
<!--Explain in detail how to reproduce your issue. The easier it will be for us to
reproduce it, the faster we will be able to work on this.-->

### Command line
<!--Ideally, if we execute the following command, the bug will directly be reproduced.
Here put the command line we have to execute-->
```bash
# command line used if any
```

### Code snippet
<!--Expose the python code you want us to test-->
```python
import grid2op

... # Some code
```

## Current output
<!--Describe the output you have-->
```
The output of the code snippet above
```

## Expected output
<!--Describe the output you desire-->
```
The expected output and/or expected behavior description
```
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ assignees: ''
---

## Documentation issue description
A description of what the problem/suggestion is.
<--A description of what the problem/suggestion is.-->

## Suggested modifications
<--Be as concise and clear as possible.
Ideally we could directly copy paste this code in grid2op documentation / notebook etc.
-->
```
Documentation issues are low priority.
Please provide your suggested modifications to increase processing speed.
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ getting_started/path_agents/awesome_agent_logs/
save_class.pickle
test_multiproc.py
test_multiproc2.py
getting_started/saved_agent2_DDDQN_1500/
getting_started/saved_agent2_DDDQN_1500_results/
getting_started/saved_agent_DDDQN_1000_results/
getting_started/saved_agent_DDDQN_100_multi/
getting_started/saved_agent_DDDQN_100_multi_results_multi/
tensorboard
test_sac

# profiling files
**.prof
64 changes: 53 additions & 11 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,72 @@ Change Log
--------------------
- [???] Extensive tests for BridgeReward
- [???] Extensive tests for DistanceReward
- [???] test and doc for opponent
- [???] better logging
- [???] add a "plot action" method
- [???] rationalize the public and private part of the API. Some members now are public but should be private.
- [???] better explanation of the notebook 3 with action silently
- [???] simulate in MultiEnv
- [???] in MultiEnv, when some converter of the observations are used, have each child process to compute
it in parrallel and transfer the resulting data.
- [???] modeled batteries / pumped storage in grid2op (generator but that can be charged / discharged)
- [???] modeled dumps in grid2op (stuff that have a given energy max, and cannot produce more than the available energy)
- [???] fix notebook 5 texts
- [???] properly model interconnecting powerlines
- [???] model curtailment
- [???] model batteries / pumped storage in grid2op (generator but that can be charged / discharged)
- [???] model dumps in grid2op (stuff that have a given energy max, and cannot produce more than the available energy)

[1.0.0] - 2020-06-xx
---------------------
- [BREAKING] `MultiEnv` has been renamed `SingleEnvMultiProcess`
- [BREAKING] `MultiEnv` has been abstracted to `BaseMultiProcessEnv` and the backwards compatible interface is now
`SingleProcessMultiEnv`
- [BREAKING] the `seeds` parameters of the `Runner.run` function has been renamed `env_seeds` and an `agent_seeds`
parameters is now available for fully reproducible experiments.
- [FIXED] a weird effect on `env.reset` that did not reset the state of the previous observation held
by the environment. This could have caused some issue in some corner cases.
- [FIXED] `BaseAction.__iadd__` fixed a bug with change actions `+=` operator reported in
`Issue #116 <https://github.com/rte-france/Grid2Op/issues/116>`_
- [FIXED] `obs.simulate` post-initialized reward behaves like the environment
- [FIXED] `LinesReconnectedReward` fixes reward inverted range
- [FIXED] the `get_all_unitary_topologies_change` now counts only once the "do nothing" action.
- [FIXED] `obs.simulate` could sometime returns "None" when the simulated action lead to a game over. This is no longer
a problem.
- [FIXED] `grid2op.make` will now raise an error if an invalid argument has been passed to it.
- [FIXED] some arguments were not passed correctly to `env.get_kwargs()` or `env.get_params_for_runner()`
- [ADDED] `Issue #110 <https://github.com/rte-france/Grid2Op/issues/110>`_ Adding an agent that is able to reconnect
disconnected powerlines that can be reconnected, see `grid2op.Agent.RecoPowerlineAgent`
- [ADDED] a clearer explanation between illegal and ambiguous action.
- [ADDED] `MultiEnvMultiProcess` as a new multi-process class to run different environments in multiples prallel
processes.
- [ADDED] more control on the environment when using the `grid2op.make` function.
- [ADDED] creation of the MultiMixEnv that allows to have, through a unified interface the possibility to interact
alternatively with one environment or the other. This is especially useful when considering an agent that should
interact in multiple environments.
- [ADDED] possibility to use `simulate` on the current observation.
- [ADDED] the overload of "__getattr__" for environment running in parallel
- [ADDED] capability to change the powerlines on which the opponent attack at the environment initialization
- [UPDATED] `Backend.PandaPowerBackend.apply_action` vectorized backend apply action method for speed.
- [UPDATED] `Issue #111 <https://github.com/rte-france/Grid2Op/issues/111>`_ Converter is better documented to be
more broadly usable.
- [UPDATED] `MultiEnv` has been updated for new use case: Providing different environments configurations on the same
grid and an arbitrary number of processes for each of these.
- [UPDATED] Behaviour of "change_bus" and "set_bus": it is no more possible to affect the bus of a powerline
disconnected.
- [UPDATED] More control about the looping strategy of the `ChronicsHandler` that has been refactored, and can now be
more easily cached (no need to do an expensive reading of the data at each call to `env.reset`)

[0.9.4] - 2020-06-12
---------------------
- [FIXED] `Issue #114 <https://github.com/rte-france/Grid2Op/issues/114>`_ the issue concerning the bug for the maintenance.
- [FIXED] `Issue #114 <https://github.com/rte-france/Grid2Op/issues/114>`_ the issue concerning the
bug for the maintenance.


[0.9.3] - 2020-05-29
---------------------
- [FIXED] `Issue #69 <https://github.com/rte-france/Grid2Op/issues/69>`_ MultEnvironment is now working with windows
based OS.
- [ADDED] `Issue #108 <https://github.com/rte-france/Grid2Op/issues/108>`_ Seed is now part of the public agent API.
The notebook has been updated accordingly.
- [ADDED] Some function to disable the `obs.simulate` if wanted. This can lead to around 10~15% performance speed up
in case `obs.simulate` is not used. See `env.deactivate_forecast` and `env.reactivate_forecast`
(related to `Issued #98 <https://github.com/rte-france/Grid2Op/issues/98>`_)
- [UPDATED] the first introductory notebook.
- [UPDATED] possibility to reconnect / disconnect powerline giving its name when using `reconnect_powerline` and
`disconnect_powerline` methods of the action space.
Expand All @@ -34,11 +81,6 @@ Change Log
`Issued #98 <https://github.com/rte-france/Grid2Op/issues/98>`_
- [UPDATED] Added `PlotMatplot` constructor arguments to control display of names and IDs of the grid elements
(gen, load, lines). As suggested in `Issue #106 <https://github.com/rte-france/Grid2Op/issues/106>`_
- [ADDED] `Issue #108 <https://github.com/rte-france/Grid2Op/issues/108>`_ Seed is now part of the public agent API.
The notebook has been updated accordingly.
- [ADDED] Some function to disable the `obs.simulate` if wanted. This can lead to around 10~15% performance speed up
in case `obs.simulate` is not used. See `env.deactivate_forecast` and `env.reactivate_forecast`
(related to `Issued #98 <https://github.com/rte-france/Grid2Op/issues/98>`_)


[0.9.2] - 2020-05-26
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Documentation Status](https://readthedocs.org/projects/grid2op/badge/?version=latest)](https://grid2op.readthedocs.io/en/latest/?badge=latest)
[![circleci](https://circleci.com/gh/BDonnot/Grid2Op.svg?style=shield)](https://circleci.com/gh/BDonnot/Grid2Op)
[![discord](https://discord.com/api/guilds/698080905209577513/embed.png)]( https://discord.gg/cYsYrPT)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/rte-france/Grid2Op/master)

Grid2Op is a plateform, built with modularity in mind, that allows to perform powergrid operation.
And that's what it stands for: Grid To Operate.
Expand Down Expand Up @@ -147,6 +148,9 @@ interesting part of this framework:
environment. But you also have the possibility to post process an agent and make some movies out of it, and we also
developed a Graphical User Interface (GUI) called "[grid2viz](https://github.com/mjothy/grid2viz)" that allows
to perform in depth study of your agent's behaviour on different scenarios and even to compare it with baselines.
* [9_nvironmentModifications](getting_started/9_EnvironmentModifications.ipynb) elaborates on the maintenance, hazards
and attacks. All three of these represents external events that can disconnect some powerlines. This notebook
covers how to spot when such things happened and what can be done when the maintenance or the attack is over.

Try them out in your own browser without installing
anything with the help of mybinder:
Expand Down
138 changes: 13 additions & 125 deletions _profiling/profiler_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import os

from grid2op import make
from grid2op.Agent import AgentWithConverter
from grid2op.Parameters import Parameters
from grid2op.Converter import IdToAct
from grid2op.Rules import AlwaysLegal
from grid2op.Backend import PandaPowerBackend
import cProfile

from utils_benchmark import run_env, str2bool
from utils_benchmark import run_env, str2bool, ProfileAgent

try:
from lightsim2grid.LightSimBackend import LightSimBackend
Expand All @@ -39,126 +38,11 @@
MAX_TS = 1000


class TestAgent(AgentWithConverter):
class TestAgent(ProfileAgent):
def __init__(self, action_space, env_name, action_space_converter=IdToAct, **kwargs_converter):
AgentWithConverter.__init__(self, action_space, action_space_converter=action_space_converter, **kwargs_converter)
self.action_space.all_actions = []

# do nothing
all_actions_tmp = [action_space()]

# powerline switch: disconnection
for i in range(action_space.n_line):
if env_name == "rte_case14_realistic":
if i == 18:
continue
elif env_name == "rte_case5_example":
pass
elif env_name == "rte_case118_example":
if i == 6:
continue
if i == 26:
continue
if i == 72:
continue
if i == 73:
continue
if i == 80:
continue
if i == 129:
continue
if i == 140:
continue
if i == 176:
continue
if i == 177:
continue
all_actions_tmp.append(action_space.disconnect_powerline(line_id=i))

# other type of actions
all_actions_tmp += action_space.get_all_unitary_topologies_set(action_space)
# self.action_space.all_actions += action_space.get_all_unitary_redispatch(action_space)

if env_name == "rte_case14_realistic":
# remove action that makes the powerflow diverge
breaking_acts = [action_space({"set_bus": {"lines_or_id": [(7,2), (8,1), (9,1)],
"lines_ex_id": [(17,2)],
"generators_id": [(2,2)],
"loads_id": [(4,1)]}}),
action_space({"set_bus": {"lines_or_id": [(10, 2), (11, 1), (19,2)],
"lines_ex_id": [(16, 2)],
"loads_id": [(5, 1)]}}),
action_space({"set_bus": {"lines_or_id": [(5, 1)],
"lines_ex_id": [(2, 2)],
"generators_id": [(1, 2)],
"loads_id": [(1, 1)]}}),
action_space({"set_bus": {"lines_or_id": [(6, 2), (15, 2), (16, 1)],
"lines_ex_id": [(3, 2), (5, 2)],
"loads_id": [(2, 1)]}}),
action_space({"set_bus": {"lines_or_id": [(18, 1)],
"lines_ex_id": [(15, 2), (19, 2)],
}})
]
elif env_name == "rte_case118_example":
breaking_acts = [action_space({"set_bus": {"lines_or_id": [(100, 2), (129, 1), (173, 2)],
# "lines_ex_id": [(17,2)],
"generators_id": [(2, 2)],
"loads_id": [(6, 1)]
}}),
action_space({"set_bus": {"lines_or_id": [(100, 2), (129, 1), (173, 2)],
# "lines_ex_id": [(17,2)],
"generators_id": [(2, 2)],
"loads_id": [(6, 2)]
}}),
action_space({"set_bus": {"lines_or_id": [(100, 2), (129, 1), (173, 2)],
# "lines_ex_id": [(17,2)],
"generators_id": [(2, 1)],
"loads_id": [(6, 1)]
}}),
action_space({"set_bus": {"lines_or_id": [(140, 1)],
"lines_ex_id": [(129, 2)],
# "generators_id": [(2, 1)],
# "loads_id": [(6, 1)]
}}),
action_space({"set_bus": {"lines_or_id": [(57, 2), (80, 1), (83, 2)],
"lines_ex_id": [(2, 2), (13, 2), (24, 2), (35, 2)],
"generators_id": [(6, 2)],
"loads_id": [(8, 2)]
}}),
action_space({"set_bus": {"lines_or_id": [(57, 2), (80, 1), (83, 2)],
"lines_ex_id": [(2, 2), (13, 2), (24, 2), (35, 2)],
"generators_id": [(6, 2)],
"loads_id": [(8, 1)]
}}),
action_space({"set_bus": {"lines_or_id": [(57, 2), (80, 1), (83, 2)],
"lines_ex_id": [(2, 2), (13, 2), (24, 2), (35, 2)],
"generators_id": [(6, 1)],
"loads_id": [(8, 2)]
}}),
action_space({"set_bus": {"lines_or_id": [(57, 2), (80, 1), (83, 2)],
"lines_ex_id": [(2, 2), (13, 2), (24, 2), (35, 2)],
"generators_id": [(6, 1)],
"loads_id": [(8, 1)]
}}),
]
else:
breaking_acts = [action_space({"set_bus": {"lines_or_id": [(0,2), (1,2), (2,2), (3,1)],
"generators_id": [(0,1)],
"loads_id": [(0,1)]}}),
]

# filter out actions that break everything
all_actions = []
for el in all_actions_tmp:
if not el in breaking_acts:
all_actions.append(el)

# set the action to the action space
self.action_space.all_actions = all_actions

# add the action "reset everything to 1 bus"
self.action_space.all_actions.append(action_space({"set_bus": np.ones(action_space.dim_topo, dtype=np.int),
"set_line_status": np.ones(action_space.n_line, dtype=np.int)}))
ProfileAgent.__init__(self, action_space, env_name=env_name,
action_space_converter=action_space_converter, **kwargs_converter)

self.nb_act_done = 0
self.act_this = True

Expand All @@ -174,7 +58,7 @@ def my_act(self, transformed_obs, reward, done=False):
return res


def main(max_ts, name, use_lightsim=False):
def main(max_ts, name, use_lightsim=False, test_env=True):
param = Parameters()
if use_lightsim:
if light_sim_avail:
Expand All @@ -186,7 +70,7 @@ def main(max_ts, name, use_lightsim=False):

param.init_from_dict({"NO_OVERFLOW_DISCONNECTION": True})

env_klu = make(name, backend=backend, param=param, gamerules_class=AlwaysLegal, test=True)
env_klu = make(name, backend=backend, param=param, gamerules_class=AlwaysLegal, test=test_env)
agent = TestAgent(action_space=env_klu.action_space, env_name=name)

cp = cProfile.Profile()
Expand All @@ -209,11 +93,15 @@ def main(max_ts, name, use_lightsim=False):
help='Maximum number of time steps for which the benchamark will be run.')
parser.add_argument("--use_ls", type=str2bool, nargs='?',
const=True, default=False,
help="Activate nice mode.")
help="Use the LightSim2Grid Backend.")
parser.add_argument("--no_test", type=str2bool, nargs='?',
const=True, default=False,
help="Do not use a test environment for the profiling (default to False: meaning you use a test env)")

args = parser.parse_args()

max_ts = int(args.number)
name = str(args.name)
use_ls = args.use_ls
main(max_ts, name, use_lightsim=use_ls)
test_env = not args.no_test
main(max_ts, name, use_lightsim=use_ls, test_env=test_env)
Loading

0 comments on commit 333b332

Please sign in to comment.