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

Indexing matrices by bus throws BoundsError #44

Closed
degleris1 opened this issue Jul 12, 2023 · 2 comments
Closed

Indexing matrices by bus throws BoundsError #44

degleris1 opened this issue Jul 12, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@degleris1
Copy link

The following code seems to generate an error for v0.7.1:

B = ABA_Matrix(sys)
buses = collect(get_components(Bus, sys))
for b in buses
	@show B[b, b]
end

In general, it seems B.lookup[1] has length length(buses), whereas B.data has dimensions (n, n) where n = length(buses) - length(B.ref_bus_positions).

The full code to reproduce the error is in the Pluto notebook here:

https://gist.github.com/degleris1/ea6830f33a0e8ba125286a1c55feaa13

@amirmm11 @jd-lara

@jd-lara jd-lara added the question Further information is requested label Jul 13, 2023
@alefcastelli
Copy link
Contributor

Hi!

I had the chance to look at the issue you reported.

The ABA_matrix stores the ABA matrix without the column and row of the reference bus. For the system you loaded there are 14 buses, one of them is the reference. This explains why the matrix is a 13x13.

The "lookup" field contains the dictionaries that link the number of the buses of the systems with the number of the rows/columns. In these dictionaries the reference bus is considered in case the full matrix is wanted to be recreated (together by using the information in the field "ref_bus_positions").

To use the "lookup" field in a for loop you just need to get rid of the key related to the reference bus.

@degleris1
Copy link
Author

@alefcastelli I understand why the ABA matrix has the reference bus row/column removed, but the point is that indexing with a Bus object or a bus ID (not index) will produce incorrect results or throw an error.

For example, in the example provided, ref_bus = 1. Indeed, if you index the reference bus B[ref_bus, ref_bus], you actually get a value, which is the entry in the first row/column of B.data, which is not the correct bus susceptance for the reference bus. Alternatively, bus number 14 is not a reference bus, but produces an error. Other buses will consistently produce

At the very least, the getindex methods should be removed to prevent the incorrect behavior.

Screenshot 2023-07-13 at 4 26 12 PM

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

No branches or pull requests

3 participants