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

Error using PlotMatplot(env.observation_space) in case of 'unmodelled' power network elements #223

Closed
janviebahn opened this issue Jun 7, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@janviebahn
Copy link

janviebahn commented Jun 7, 2021

Environment

  • Grid2op version: 1.5.0

Bug description

Using a slightly modified grid.json and grid_layout.json (both are attached and see 'How to reproduce' for code)
grid_files.zip

I get the following problem

import grid2op
from grid2op.PlotGrid import PlotMatplot

env = grid2op.make("/home/cdsw/.local/lib/python3.6/site-packages/grid2op/data/rte_case5_example")

plot_helper = PlotMatplot(env.observation_space)

KeyError: 5
KeyError Traceback (most recent call last)
in engine
----> 1 plot_helper = PlotMatplot(env.observation_space)

/home/cdsw/.local/lib/python3.6/site-packages/grid2op/PlotGrid/PlotMatplot.py in init(self, observation_space, width, height, grid_layout, dpi, scale, bus_radius, sub_radius, load_radius, load_name, load_id, load_resolution, gen_radius, gen_name, gen_id, gen_resolution, storage_resolution, line_name, line_id)
169 line_id=False):
170 self.dpi = dpi
--> 171 super().init(observation_space, width, height, scale, grid_layout)
172
173 self._sub_radius = sub_radius

/home/cdsw/.local/lib/python3.6/site-packages/grid2op/PlotGrid/BasePlot.py in init(self, observation_space, width, height, scale, grid_layout, parallel_spacing)
67 self._gens_info = ["p", "v", None]
68
---> 69 self._grid_layout = self.compute_grid_layout(observation_space, grid_layout)
70
71 # Augment observation_space with dummy observation data

/home/cdsw/.local/lib/python3.6/site-packages/grid2op/PlotGrid/BasePlot.py in compute_grid_layout(self, observation_space, grid_layout)
149 # Compute loads and gens positions using a default implementation
150 observation_space.grid_layout = use_grid_layout
--> 151 return layout_obs_sub_load_and_gen(observation_space, scale=self.scale, use_initial=True)
152
153 @AbstractMethod

/home/cdsw/.local/lib/python3.6/site-packages/grid2op/PlotGrid/LayoutUtil.py in layout_obs_sub_load_and_gen(obs, scale, use_initial)
148 kkl = nx.spring_layout(G, scale=scale, fixed=fix,
149 pos=initial_layout, seed=seed,
--> 150 iterations=1000)
151 else:
152 # Use kamada_kawai algorithm

in fruchterman_reingold_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed)

/home/cdsw/.local/lib/python3.6/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs)
403 new_args = list(args)
404 new_args[random_state_index] = random_state
--> 405 return func(*new_args, **kwargs)
406 return _random_state
407

/home/cdsw/.local/lib/python3.6/site-packages/networkx/drawing/layout.py in fruchterman_reingold_layout(G, k, pos, fixed, iterations, threshold, weight, scale, center, dim, seed)
454 raise ValueError('nodes are fixed without positions given')
455 nfixed = {node: i for i, node in enumerate(G)}
--> 456 fixed = np.asarray([nfixed[node] for node in fixed])
457
458 if pos is not None:

/home/cdsw/.local/lib/python3.6/site-packages/networkx/drawing/layout.py in (.0)
454 raise ValueError('nodes are fixed without positions given')
455 nfixed = {node: i for i, node in enumerate(G)}
--> 456 fixed = np.asarray([nfixed[node] for node in fixed])
457
458 if pos is not None:

KeyError: 5

How to reproduce

I use the exact same modifications as in issue #217
That is, I modify rte_case5_example slightly

import pandapower as pp

net = pp.from_json("grid.json")

pp.create_bus(net, name = "substation_6", vn_kv = 20)
pp.create_bus(net, name = "substation_7", vn_kv = 10)
pp.create_transformer3w(net, hv_bus = 4, mv_bus = 5, lv_bus = 6, name = "trafo3w", std_type = "63/25/38 MVA 110/20/10 kV")
pp.create_sgen(net, 6, p_mw = -10)
pp.create_shunt(net, 5, 10)

pp.to_json(net, "grid_modified.json")

In the grid_layout.json I just manually added locations for the two new substations.

@janviebahn janviebahn added the bug Something isn't working label Jun 7, 2021
@BDonnot
Copy link
Collaborator

BDonnot commented Jun 8, 2021

Hello,

It appears you added some substations in your grid, but did not modify the grid layout (or has forgotten to provide it).

If you did not update the layout, this is why this error is happening: you need to provide coordinates for each substations at the moment.

@janviebahn
Copy link
Author

janviebahn commented Jun 8, 2021

Both grid.json and grid_layout.json are provided in grid_files.zip (see beginning of "Bug description"). I attach it here again.
grid_files.zip

The way it is produced is described in "How to reproduce".

@BDonnot
Copy link
Collaborator

BDonnot commented Jun 8, 2021

Oh sorry i must have missed it

BDonnot referenced this issue in BDonnot/Grid2Op Jun 8, 2021
@BDonnot
Copy link
Collaborator

BDonnot commented Jun 8, 2021

I could reproduce the issue and fixed it (hopefully the tests pass). The fix will be included in the next grid2op release (probably in the next few days / weeks).

In the mean time, you can install the (development) version with:
pip install git+git://github.com/bdonnot/grid2op.git@bd_dev

(it will be grid2op version 1.6.0.rc1 however)

@BDonnot
Copy link
Collaborator

BDonnot commented Jun 9, 2021

The fix is now part of the development version of grid2op and can also be installed with:
pip install git+git://github.com/rte-france/grid2op.git@dev_1.6.0

@janviebahn
Copy link
Author

Nice. Thanks.

It indeed works for rte_case5_example. I will now test it on larger networks.

@BDonnot
Copy link
Collaborator

BDonnot commented Jun 22, 2021

Fixed and merged in version 1.6.0, now available on pypi

@BDonnot BDonnot closed this as completed Jun 22, 2021
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