Grid2Op icon indicating copy to clipboard operation
Grid2Op copied to clipboard

Lightsim2grid backend is not properly copied by env's copy method

Open Farid-Najar opened this issue 2 years ago • 0 comments

Environment

  • Grid2op version: dev_multiagent
  • System: ubuntu20.04.3 LTS

Bug description

When we copy the env with env.copy(), the backend loses, at least, _my_kwargs attribute. Here, I used the lightsim2grid backend.

How to reproduce

Try the following code on a notebook or python terminal

Code snippet

from grid2op import make
try:
    from lightsim2grid import LightSimBackend
    bk_cls = LightSimBackend
    print("Using lightsim2grid!")
except ImportError as exc:
    print(f"Error: {exc} when importing faster LightSimBackend")
    from grid2op.Backend import PandaPowerBackend
    bk_cls = PandaPowerBackend

print(bk_cls()._my_kwargs)
env = make("l2rpn_case14_sandbox", test = True, backend = bk_cls()).copy()
print(env.backend._my_kwargs)

Current output

{'detailed_infos_for_cascading_failures': False, 'can_be_copied': True, 'solver_type': None, 'max_iter': 10, 'tol': 1e-08}
~/Grid2Op/grid2op/MakeEnv/Make.py:394: 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)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/Grid2Op/grid2op/multi_agent/test.ipynb Cell 29' in <cell line: 3>()
      [1](~/Grid2Op/grid2op/multi_agent/test.ipynb#ch0000049?line=0) print(bk_cls()._my_kwargs)
      [2](~/Grid2Op/grid2op/multi_agent/test.ipynb#ch0000049?line=1) env = make("l2rpn_case14_sandbox", test = True, backend = bk_cls()).copy()
----> [3](~/Grid2Op/grid2op/multi_agent/test.ipynb#ch0000049?line=2) print(env.backend._my_kwargs)

AttributeError: 'LightSimBackend_l2rpn_case14_sandbox' object has no attribute '_my_kwargs'

Expected output

{'detailed_infos_for_cascading_failures': False, 'can_be_copied': True, 'solver_type': None, 'max_iter': 10, 'tol': 1e-08}
~/Grid2Op/grid2op/MakeEnv/Make.py:394: 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)
{'detailed_infos_for_cascading_failures': False, 'can_be_copied': True, 'solver_type': None, 'max_iter': 10, 'tol': 1e-08}

Farid-Najar avatar Jul 12 '22 09:07 Farid-Najar