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

Detachment in LightSim2Grid #101

Open
DEUCE1957 opened this issue Jan 17, 2025 · 2 comments
Open

Detachment in LightSim2Grid #101

DEUCE1957 opened this issue Jan 17, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@DEUCE1957
Copy link

Environment

  • Grid2op version: 1.11.0.dev3 (Note: This is a development branch)
  • lightsim version: 0.10.0
  • System: linux

Bug description

When using the up-and-coming detachment feature in Grid2Op, it works well with the PandaPowerBackend, but causes an error to be thrown in LightSim2Grid.

How to reproduce

import grid2op
import matplotlib.pyplot as plt
from grid2op.PlotGrid import PlotMatplot
from lightsim2grid import LightSimBackend
env = grid2op.make("l2rpn_case14_sandbox", allow_detachment=True,
                   backend=LightSimBackend(detailed_infos_for_cascading_failures=True,
                                           max_iter=100))
obs = env.reset(options={"time serie id": "0000"})
plotter = PlotMatplot(env.observation_space, load_name=True, gen_name=True)
plotter.plot_obs(obs);
plt.show()

# Action: Disable generator at substation 1
obs, reward, done, info = env.step(env.action_space(
    {
        "set_bus": [(obs.gen_pos_topo_vect[obs.name_gen == "gen_1_0"].item(), -1)]
    }
))
plotter.plot_obs(obs);
plt.show()

# Run episode until completion
while not done:
    # NOTE: Error thrown here!
    _, _, done, info = env.step(env.action_space({}))
    print(f"{env.nb_time_step}/{env.max_episode_duration()}")

Current output

Currently it seems Lightsim2grid will still internally try to change the active power setpoint of disconnected generators (probably as part of the backend changing the setpoints of loads/generators to balance supply & demand). I imagine these will need to be masked so that the backend does not try to use disconnected elements.

Grid2OpException BackendError "GeneratorContainer::change_p: Impossible to change the active value of a disconnected generator (check gen. id 0)"

The error appears to occur in GeneratorContainer.cpp line 268.

Expected output

Expect no error to be thrown.

@DEUCE1957 DEUCE1957 added the bug Something isn't working label Jan 17, 2025
@BDonnot
Copy link
Collaborator

BDonnot commented Jan 21, 2025

Hello,

Thanks for reporting this issue. This is on my todo list but requires a bit of work on the cpp side of lightsim2grid (refactoring because it currently is a bit messy...)
As a quick and dirty fix, You can inherit the lightsim2grid backend and override the "apply_action" method to "mask out" the loads and generators disconnected in the "change_p", "change_q" or "change_v" functions.
Let me know if this is enough for you or if you want a code snippet 😊

@BDonnot
Copy link
Collaborator

BDonnot commented Feb 17, 2025

Sorry again for my super late reply on this topic... I am working on it right now (while refactoring the c++ side of lightsim2grid).

Just a quick note in case you don't know, you have more concise way to do what you want (disconnect gen 0), for example you can do:

env.action_space(
            {
                "set_bus": {"generators_id": [(0, -1)]}
            })

Or you can also do, if you prefer to work directly with name:

env.action_space(
            {
                "set_bus": {"generators_id": [("gen_1_0", -1)]}
            })

BDonnot added a commit that referenced this issue Feb 17, 2025
BDonnot added a commit that referenced this issue Mar 7, 2025
Signed-off-by: DONNOT Benjamin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants