Tutorial 1: Grid2Op integration with existing frameworks
Closed this issue · 2 comments
Environment
- Grid2op version:
1.10.1
- System:
windows
- Python 3.10.14
Bug description
Modification of observation space. When scaling the action from MW values to [0,1], there is a problem accessing the dictionary with the given tutorial, see error message in screenshot below.
I tried solving by:
I solved it in my local copy by modifying from
"ob_space = ob_space.reencode_space("load_p",
ScalerAttrConverter(substract=obs_gym["load_p"],
divide=0.5 * obs_gym["load_p"]
)
)
"
to:
ob_space = ob_space.reencode_space("load_p",
ScalerAttrConverter(substract=obs_gym **[0]** ["load_p"],
divide=0.5 * obs_gym **[0]** ["load_p"]
)
)
"
Reproduction of error
The error can be reproduced by executing the tutorial 11 "Integration with existing frameworks". This is the code in the marked cell in .ipynb notebook:
from grid2op.gym_compat import ScalerAttrConverter
from gym.spaces import Box
ob_space = env_gym.observation_space
ob_space = ob_space.reencode_space("actual_dispatch",
ScalerAttrConverter(substract=0.,
divide=env_glop.gen_pmax
)
)
ob_space = ob_space.reencode_space("gen_p",
ScalerAttrConverter(substract=0.,
divide=env_glop.gen_pmax
)
)
ob_space = ob_space.reencode_space("load_p",
ScalerAttrConverter(substract=obs_gym["load_p"],
divide=0.5 * obs_gym["load_p"]
)
)
# for even more customization, you can use any functions you want !
shape_ = (env_glop.dim_topo, env_glop.dim_topo)
env_gym.observation_space.add_key("connectivity_matrix",
lambda obs: obs.connectivity_matrix(), # can be any function returning a gym space
Box(shape=shape_,
low=np.zeros(shape_),
high=np.ones(shape_),
) # this "Box" should represent the return type of the above function
)
env_gym.observation_space = ob_space
env_gym.observation_space
misc
This is just a minor problem in the tutorial documentation and does not affect the functionality of the package. I am also not sure if my way of solving it is correct, as I just get started here.
Hello,
I finally had some time to have a look at this. This notebook was indeed not correct after the upgrade from the (now deprecated) gym
package to the more recent gymnasium
package and the change of interface (env.reset()
returns a tuple and not just the observation)
I made the change in the notebook, it will be part of the next release.
In the mean time, the "correct" notebook can be found here: https://github.com/BDonnot/Grid2Op/blob/bd_dev/getting_started/11_IntegrationWithExistingRLFrameworks.ipynb
Done and live in release in 1.10.3