rwl / PYPOWER

Port of MATPOWER to Python
http://rwl.github.io/PYPOWER/api/
Other
329 stars 110 forks source link

makeYbus uses one-indexing #53

Closed priyald17 closed 5 years ago

priyald17 commented 5 years ago

makeYbus fails when using pypower test cases due to one-indexing issues. For instance, for:

import pypower.api as pp ppc = pp.case14() baseMVA, bus, branch = ppc['baseMVA'], ppc['bus'], ppc['branch'] pp.makeYbus(baseMVA, bus, branch)

The output is buses must appear in order by bus number Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/priyadonti/anaconda2/envs/acopf/lib/python3.7/site-packages/pypower/makeYbus.py", line 71, in makeYbus Ct = csr_matrix((ones(nl), (range(nl), t)), (nl, nb)) File "/Users/priyadonti/anaconda2/envs/acopf/lib/python3.7/site-packages/scipy/sparse/compressed.py", line 51, in __init__ other = self.__class__(coo_matrix(arg1, shape=shape)) File "/Users/priyadonti/anaconda2/envs/acopf/lib/python3.7/site-packages/scipy/sparse/coo.py", line 192, in __init__ self._check() File "/Users/priyadonti/anaconda2/envs/acopf/lib/python3.7/site-packages/scipy/sparse/coo.py", line 274, in _check raise ValueError('column index exceeds matrix dimensions') ValueError: column index exceeds matrix dimensions

FIXES:

Line 66 should be f = branch[:, F_BUS] - 1 and line 67 should be t = branch[:, T_BUS] - 1

Additionally, the check in line 35 should be if any(bus[:, BUS_I] != list(range(1, nb+1))):

rwl commented 5 years ago

The column bus[:, BUS_I] isn't necessarily a one-based index. It is a positive integer to identify the bus:

https://github.com/rwl/PYPOWER/blob/master/pypower/caseformat.py#L47

The ext2int function will convert to zero-based, consecutive indexing and int2ext will convert back again.

WoodpeckerBaby commented 1 year ago

@rwl

Bus 1 to bus 6 is not in the range of 0 to 5 man! That throws an error.

For running

Ybus, _, _ = makeYbus.makeYbus(thisCase["baseMVA"], thisCase["bus"], thisCase["branch"])

buses must appear in order by bus number Traceback (most recent call last): File "...main.py", line 27, in Ybus, , = makeYbus.makeYbus( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pypower/makeYbus.py", line 71, in makeYbus Ct = csr_matrix((ones(nl), (range(nl), t)), (nl, nb)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/scipy/sparse/_compressed.py", line 53, in init self._coo_container(arg1, shape=shape, dtype=dtype) File "/usr/local/lib/python3.11/site-packages/scipy/sparse/_coo.py", line 197, in init self._check() File "/usr/local/lib/python3.11/site-packages/scipy/sparse/_coo.py", line 286, in _check raise ValueError('column index exceeds matrix dimensions') ValueError: column index exceeds matrix dimensions

This is the bus print out [[ 1. 2. 0. 0. 0. 0. 1. 1.05 0. 400.

  1. 1.05 0.95 0. 0. 0. 0. ] [ 2. 3. 0. 0. 0. 0. 1. 1.05 0. 400.
  2. 1.05 0.95 0. 0. 0. 0. ] [ 3. 2. 0. 0. 0. 0. 1. 1.05 0. 400.
  3. 1.05 0.95 0. 0. 0. 0. ] [ 4. 1. 90. 60. 0. 0. 1. 1. 0. 400.
  4. 1.05 0.95 0. 0. 0. 0. ] [ 5. 1. 100. 70. 0. 0. 1. 1. 0. 400.
  5. 1.05 0.95 0. 0. 0. 0. ] [ 6. 1. 90. 60. 0. 0. 1. 1. 0. 400.
  6. 1.05 0.95 0. 0. 0. 0. ]]

DC and AC power flows are working.

Why the FDPF can't take the regular case object ppc like the others?

rwl commented 1 year ago

ext2int

WoodpeckerBaby commented 1 year ago

ext2int

It's not very well documented.

Could you please update the fdpf() function to take a regular ppc object like opf() and dcpf()?

I believe the matpower version can.