BDonnot / lightsim2grid

LightSim2grid implements a c++ backend targeting the Grid2Op (https://github.com/rte-france/grid2op) platform.
https://lightsim2grid.readthedocs.io/en/latest/
Mozilla Public License 2.0
45 stars 9 forks source link

Problem when deep copying a grid2op environment with lightsim2grid backend #36

Open BDonnot opened 2 years ago

BDonnot commented 2 years ago

Environment

Bug description

The powerflow diverge when the environment is deep copied.

How to reproduce

It can be reproduced by executing:

import copy
from lightsim2grid import LightSimBackend
import grid2op
env = grid2op.make("l2rpn_case14_sandbox", test=True, backend=LightSimBackend())
obs = env.reset()
env_cpy = copy.deepcopy(env)
new_obs, reward, done, info = env.step(env.action_space())
assert not done
new_obs_2, reward_2, done_2, info_2 = env_cpy.step(env.action_space())
assert not done_2, f'powerflow diverge, error was: \n{info_2["exception"]}'

Current output

/home/benjamin/Documents/grid2op_dev/grid2op/MakeEnv/Make.py:317: UserWarning: You are using a development environment. This environment is not intended for training agents. It might not be up to date and its primary use if for tests (hence the "test=True" you passed as argument). Use at your own risk.
  warnings.warn(_MAKE_DEV_ENV_WARN)
Traceback (most recent call last):
  File "test_deepcopy_env.py", line 11, in <module>
    assert not done_2, f'powerflow diverge, error was: \n{info_2["exception"]}'
AssertionError: powerflow diverge, error was: 
[RuntimeError('The slack bus is disconnected.')]

Expected output

Nothing shoud be raised and the environment should work correctly

BDonnot commented 2 years ago

The complete implementation of "deepcopy" is not really implemented at the moment, in the mean time, please use env.copy() which is working as expected