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

[bug] index error when running power flow calculation with added lines and switches #2166

Open
6 tasks done
ced2205 opened this issue Nov 8, 2023 · 2 comments
Open
6 tasks done
Labels

Comments

@ced2205
Copy link

ced2205 commented Nov 8, 2023

Bug report checklis

  • Searched the issues page for similar reports

  • Read the relevant sections of the documentation

  • Browse the tutorials and tests for usefull code snippets and examples of use

  • Reproduced the issue after updating with pip install --upgrade pandapower (or git pull)

  • Tried basic troubleshooting (if a bug/error) like restarting the interpreter and checking the pythonpath

Reproducible Example

net = pp.from_json('mv_net_2040.json')

line1 = pp.create_line(net, from_bus=1, to_bus=3,  length_km=1, std_type="NA2XS2Y 1x240 RM/25 6/10 kV",  name=f"b{1} to b{3}",  in_service=True, max_loading_percent=80)
line2 = pp.create_line(net, from_bus=4, to_bus=1,  length_km=0.8, std_type="NA2XS2Y 1x240 RM/25 6/10 kV",  name=f"b{4} to b{1}",  in_service=True, max_loading_percent=80)
line3 = pp.create_line(net, from_bus=2, to_bus=5,  length_km=0.633, std_type="NA2XS2Y 1x240 RM/25 6/10 kV",  name=f"b{2} to b{5}",  in_service=True, max_loading_percent=80)

pp.create_switch(net, bus=1, element=line1, et='l', closed=True, type="CB",
                             name=f"switch{10}", in_service=True)
pp.create_switch(net, bus=4, element=line2, et='l', closed=True, type="CB",
                             name=f"switch{11}", in_service=True)
pp.create_switch(net, bus=2, element=line3, et='l', closed=True, type="CB",
                             name=f"switch{12}", in_service=True)

ow_pf = create_output_writer(net,time_steps=96, year=2040,storage=False)
run_timeseries(net, time_steps=range(96),run=pp.runpp, continue_on_divergence=False, verbose=True, check_controllers=True, numba=False, run_control=True, calculate_voltage_angles=False)

Issue Description and Traceback

0%|          | 0/96 [00:00<?, ?it/s]Traceback (most recent call last):
 File "<ipython-input-18-0886297f146e>", line 3, in <module>
   run_timeseries(net_0, time_steps=range(timesteps),run=pp.runpp, continue_on_divergence=False, verbose=True, check_controllers=True, numba=False, run_control=True, calculate_voltage_angles=False)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\timeseries\run_time_series.py", line 361, in run_timeseries
   run_loop(net, ts_variables, **kwargs)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\timeseries\run_time_series.py", line 329, in run_loop
   run_time_step(net, time_step, ts_variables, run_control_fct, output_writer_fct, **kwargs)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\timeseries\run_time_series.py", line 129, in run_time_step
   run_control_fct(net, ctrl_variables=ts_variables, **kwargs)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\control\run_control.py", line 300, in run_control
   ctrl_variables = net_initialization(net, ctrl_variables, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\control\run_control.py", line 162, in net_initialization
   run_funct(net, **kwargs)  # run can be runpp, runopf or whatever
   ^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\run.py", line 241, in runpp
   _powerflow(net, **kwargs)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\powerflow.py", line 86, in _powerflow
   _ppci_to_net(result, net)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\powerflow.py", line 196, in _ppci_to_net
   _extract_results(net, result)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\results.py", line 34, in _extract_results
   _get_branch_results(net, ppc, bus_lookup_aranged, bus_pq)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\results_branch.py", line 44, in _get_branch_results
   _get_switch_results(net, i_ft, suffix=suffix)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\results_branch.py", line 683, in _get_switch_results
   _copy_switch_results_from_branches(net, suffix)
 File "D:\pythonProject\venv\Lib\site-packages\pandapower\results_branch.py", line 709, in _copy_switch_results_from_branches
   net[res_switch_df].loc[open_switches, current_parameter] = 0
   ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 845, in __setitem__
   indexer = self._get_setitem_indexer(key)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 710, in _get_setitem_indexer
   return self._convert_tuple(key)
          ^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 927, in _convert_tuple
   keyidx = [self._convert_to_indexer(k, axis=i) for i, k in enumerate(key)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 927, in <listcomp>
   keyidx = [self._convert_to_indexer(k, axis=i) for i, k in enumerate(key)]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 1426, in _convert_to_indexer
   return self._get_listlike_indexer(key, axis)[1]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexing.py", line 1462, in _get_listlike_indexer
   keyarr, indexer = ax._get_indexer_strict(key, axis_name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexes\base.py", line 5876, in _get_indexer_strict
   self._raise_if_missing(keyarr, indexer, axis_name)
 File "D:\pythonProject\venv\Lib\site-packages\pandas\core\indexes\base.py", line 5935, in _raise_if_missing
   raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index([-2, -2, -1, -2, -1, -1, -2, -2, -1, -2, -2, -2], dtype='object')] are in the [index]"

Expected Behavior

When I add new switches and lines to my network, this traceback appears. Before I added new lines and switches the timeseries powerflow calculation works. The initial Network where is no traceback in the timeseries powerflow is attached.
mv_net_2040.json

Installed Versions

  • python version:3.11
  • pandas version:2.0.0
  • networkx version:3.1
  • scipy version: 1.10.1
  • numpy version: 1.24.2
  • packaging version: 23.1
  • tqdm version:4.65.0
  • deepdiff version:6.3.0
  • Operating System name/version: Windows 11

Label

  • Relevant labels are selected
@ced2205 ced2205 added the bug label Nov 8, 2023
@rbolgaryn
Copy link
Member

Hi @ced2205 ,

can you please run the function pp.diagnostic(net) and see if it outputs anything helpful?

@ced2205
Copy link
Author

ced2205 commented Nov 23, 2023

Hi @rbolgaryn ,

i found the issue in results_branch.py in function _copy_switch_results_from_branches where open_switches=~net.switch.closed.values defined. this mask returns the index shown in the Error Log. I changed it to a list containing the indices of switches that are open/not closed and that worked for me.

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

No branches or pull requests

2 participants