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

Fix issue #126: #99

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Change Log
- [FIXED] `Issue #133 <https://github.com/rte-france/Grid2Op/issues/133>`_: Missing positional argument `space_prng` in `Action.SerializableActionSpace`
- [FIXED] `Issue #131 <https://github.com/rte-france/Grid2Op/issues/131>`_: Forecast values are accessible without needing to call `obs.simulate` beforehand.
- [FIXED] `Issue #134 <https://github.com/rte-france/Grid2Op/issues/134>`_: Backend iadd actions with lines extremities disconnections (set -1)
- [FIXED] issue `Issue 122 <https://github.com/rte-france/Grid2Op/issues/125>`_
- [FIXED] issue `Issue #125 <https://github.com/rte-france/Grid2Op/issues/125>`_
- [FIXED] issue `Issue #126 <https://github.com/rte-france/Grid2Op/issues/126>`_ Loading runner logs no longer checks environment actions ambiguity

[1.1.1] - 2020-07-07
---------------------
Expand Down
3 changes: 3 additions & 0 deletions grid2op/Action/_BackendAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def all_changed(self):
# self.shunt_q.all_changed()
# self.shunt_bus.all_changed()

def set_redispatch(self, new_redispatching):
self.prod_p.change_val(new_redispatching)

def __iadd__(self, other):
"""
other: a grid2op action standard
Expand Down
6 changes: 1 addition & 5 deletions grid2op/Environment/BaseEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,8 @@ def step(self, action):
self._backend_action += action
action._redispatch[:] = init_disp

self.env_modification._redispatch[:] = self.actual_dispatch
self._backend_action += self.env_modification

# action, for redispatching is composed of multiple actions, so basically i won't check
# ramp_min and ramp_max
self.env_modification._single_act = False
self._backend_action.set_redispatch(self.actual_dispatch)

# now get the new generator voltage setpoint
voltage_control_act = self._voltage_control(action, prod_v_chronics)
Expand Down
14 changes: 8 additions & 6 deletions grid2op/Episode/EpisodeData.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def __init__(self,
"observations")
self.env_actions = CollectionWrapper(env_actions,
helper_action_env,
"env_actions")
"env_actions",
check_legit=False)
# gives a unique game over for everyone
# TODO this needs testing!
action_go = self.actions._game_over
Expand Down Expand Up @@ -218,7 +219,7 @@ def __len__(self):
def from_disk(cls, agent_path, name=str(1)):

if agent_path is None:
raise Grid2OpException("A path to an episode should be provided, please call \"from_disck\" with "
raise Grid2OpException("A path to an episode should be provided, please call \"from_disk\" with "
"\"agent_path other\" than None")
episode_path = os.path.abspath(os.path.join(agent_path, name))

Expand Down Expand Up @@ -269,7 +270,7 @@ def from_disk(cls, agent_path, name=str(1)):
observation_space=observation_space,
action_space=action_space,
helper_action_env=helper_action_env,
path_save=agent_path,
path_save=None, # No save when reading
attack=attack,
attack_space=attack_space,
name=name,
Expand Down Expand Up @@ -457,7 +458,7 @@ class CollectionWrapper:

"""

def __init__(self, collection, helper, collection_name):
def __init__(self, collection, helper, collection_name, check_legit=True):
self.collection = collection
if not hasattr(helper, "from_vect"):
raise Grid2OpException(f"Object {helper} must implement a "
Expand All @@ -470,8 +471,9 @@ def __init__(self, collection, helper, collection_name):
self.objects = []
for i, elem in enumerate(self.collection):
try:
self.objects.append(
self.helper.from_vect(self.collection[i, :]))
collection_obj = self.helper.from_vect(self.collection[i, :],
check_legit=check_legit)
self.objects.append(collection_obj)
except AmbiguousAction:
self._game_over = i
break
Expand Down
4 changes: 2 additions & 2 deletions grid2op/Observation/CompleteObservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def update(self, env, with_forecast=True):
self.target_dispatch[:] = env.target_dispatch
self.actual_dispatch[:] = env.actual_dispatch

def from_vect(self, vect):
def from_vect(self, vect, check_legit=True):
"""
Convert back an observation represented as a vector into a proper observation.

Expand All @@ -196,7 +196,7 @@ def from_vect(self, vect):
# reset the matrices
self._reset_matrices()
# and ensure everything is reloaded properly
super().from_vect(vect)
super().from_vect(vect, check_legit=check_legit)

def to_dict(self):
"""
Expand Down
6 changes: 4 additions & 2 deletions grid2op/Space/GridObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _assign_attr_from_name(self, attr_nm, vect):
def check_space_legit(self):
pass

def from_vect(self, vect):
def from_vect(self, vect, check_legit=True):
"""
Convert a GridObjects, represented as a vector, into an GridObjects object.

Expand Down Expand Up @@ -602,7 +602,9 @@ def from_vect(self, vect):
tmp = vect[prev_:(prev_ + sh)].astype(dt)
self._assign_attr_from_name(attr_nm, tmp)
prev_ += sh
self.check_space_legit()

if check_legit:
self.check_space_legit()

def size(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions grid2op/Space/SerializableSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def size(self):
"""
return self.n

def from_vect(self, obj_as_vect):
def from_vect(self, obj_as_vect, check_legit=True):
"""
Convert an action, represented as a vector to a valid :class:`BaseAction` instance

Expand All @@ -210,7 +210,7 @@ def from_vect(self, obj_as_vect):

"""
res = copy.deepcopy(self._template_obj)
res.from_vect(obj_as_vect)
res.from_vect(obj_as_vect, check_legit=check_legit)
return res

def extract_from_vect(self, obj_as_vect, attr_name):
Expand Down
45 changes: 45 additions & 0 deletions grid2op/tests/issue_126.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
import warnings
import grid2op
from grid2op.Agent import DeltaRedispatchRandomAgent
from grid2op.Runner import Runner
from grid2op import make
from grid2op.Episode import EpisodeData
import os
import numpy as np
import tempfile

class Issue126Tester(unittest.TestCase):

def test_issue_126(self):
with tempfile.TemporaryDirectory() as tmpdirname:
#run redispatch agent on one scenario for 100 timesteps
dataset = "rte_case14_realistic"
nb_episode=1
nb_timesteps=100

with warnings.catch_warnings():
warnings.filterwarnings("ignore")
env = make(dataset)
agent = DeltaRedispatchRandomAgent(env.action_space)
runner = Runner(**env.get_params_for_runner(),
agentClass=None,
agentInstance=agent)
nb_episode=1
res = runner.run(nb_episode=nb_episode,
path_save=tmpdirname,
nb_process=1,
max_iter=nb_timesteps,
env_seeds=[0],
agent_seeds=[0],
pbar=False)

episode_data = EpisodeData.from_disk(tmpdirname, '000')

assert len(episode_data.actions.objects) == nb_timesteps
assert len(episode_data.observations.objects) == (nb_timesteps + 1)
assert len(episode_data.actions) == nb_timesteps
assert len(episode_data.observations) == (nb_timesteps + 1)

if __name__ == "__main__":
unittest.main()