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

Topo_vect is not properly updated when something is disconnected by the backend #12

Open
BDonnot opened this issue Feb 28, 2025 · 3 comments

Comments

@BDonnot
Copy link
Contributor

BDonnot commented Feb 28, 2025

Here is a reproducible example.

On the case 14 if I disconnect the line 6_7_18 it will also disconnect the generator gen_7_4 (only connected to the grid through this line).

If the backend does check_isolated_and_disconnected_injections then nothing surprising is happening: the episode is over because a generator is alone (one case of game over)

But if we deactivate the check_isolated_and_disconnected_injections then the backend will not throw a game over. And actually in this case it will not even tell grid2op it has disconnected an element (topo_vect is not updated correctly)

import os

import numpy as np
import grid2op 
from pypowsybl2grid import PyPowSyBlBackend
import pypowsybl as pp

env_no_auto_disco = grid2op.make("l2rpn_case14_sandbox", test=True, backend=PyPowSyBlBackend(check_isolated_and_disconnected_injections=True), allow_detachment=True)
env_auto_disco = grid2op.make("l2rpn_case14_sandbox", test=True, backend=PyPowSyBlBackend(check_isolated_and_disconnected_injections=False), allow_detachment=True)

obs_no_auto_disco = env_no_auto_disco.reset()
obs_auto_disco = env_auto_disco.reset()

line_name = "6_7_18"
gen_name = "gen_7_4"
l_id, *_ = type(env_no_auto_disco).get_line_info(line_name=line_name)
gen_id, *_ = type(env_no_auto_disco).get_gen_info(gen_name=gen_name)
act_isolate_gen = env_no_auto_disco.action_space({"set_line_status": [(line_name, -1)]})

obs1_no_auto_disco, reward_no_auto_disco, done_no_auto_disco, info_no_auto_disco = env_no_auto_disco.step(act_isolate_gen)
obs1_auto_disco, reward_auto_disco, done_auto_disco, info_auto_disco = env_auto_disco.step(act_isolate_gen)
assert done_no_auto_disco  # we prevent to disconnect load and generators, so it's normal
assert not done_auto_disco  # we allow to disconnect load and generators, so it's normal in this case

assert obs1_auto_disco.topo_vect[obs1_auto_disco.line_or_pos_topo_vect[l_id]] == -1  # line is correctly disconnected (or side)
assert obs1_auto_disco.topo_vect[obs1_auto_disco.line_ex_pos_topo_vect[l_id]] == -1  # line is correctly disconnected (ex side)
assert not obs1_auto_disco.line_status[l_id]  # line is correctly marked as disconnected

assert np.abs(obs1_auto_disco.gen_p[gen_id]) <= 1e-7   # gen p is 0 because gen has been deactivated
assert np.abs(obs1_auto_disco.gen_v[gen_id]) <= 1e-7   # gen v is 0 because gen has been deactivated
assert obs1_auto_disco.topo_vect[obs1_auto_disco.gen_pos_topo_vect[gen_id]] == -1  # gen should be to bus "-1" because it's disconnected
assert obs1_auto_disco.gen_detached[gen_id]  # gen should be marked as detached (grid2op does that based on topo_vect of generator)
@geofjamg
Copy link
Collaborator

geofjamg commented Mar 5, 2025

@BDonnot I wonder what is expected for bus num in the topo vect when an element is connected to a bus but not anymore a bus beloning to main connected component

  • is it expected to have a bus num to -1 just to mention that it is not connected to a bus of main connected component
  • or should we set a bus num even if this bus is not in main connected component ?

@BDonnot
Copy link
Contributor Author

BDonnot commented Mar 5, 2025

Hello,

That's a good question.

If a powerflow has run on all components then I think the bus number outside of this connected component.

If the powerflow is configured to run only on the main one, then it's as if elements are disconnected (no results) so in that case - 1 is better.

@geofjamg
Copy link
Collaborator

geofjamg commented Mar 6, 2025

Hello,

That's a good question.

If a powerflow has run on all components then I think the bus number outside of this connected component.

If the powerflow is configured to run only on the main one, then it's as if elements are disconnected (no results) so in that case - 1 is better.

I went for solution 1, so is it ok with how grid2op is working right now (only main cc is solved) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants