-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: add Grid validation function #495
Conversation
Should we add networkx to the setup.py as well? |
Should we move the grid modification to a separate PR so that it is more trackable in the future, although these changes on bus voltages are very unlikely to cause any trouble given we created them. |
Good catch, yes
If you think it is cleaner. It's already a distinct commit, and if we move it to a separate PR then we will need to merge that PR before this one, otherwise the tests in this one will fail. |
""" | ||
g = nx.from_pandas_edgelist(grid.branch, "from_bus_id", "to_bus_id") | ||
num_connected_components = len([c for c in nx.connected_components(g)]) | ||
if len(grid.interconnect) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I need to refresh my brain here, the only situation we have len(grid.interconnect)
> 1 is TexasWestern, right? If TexasWestern is handled in else
block, what does Texas_Western
entry do in interconnect_combinations
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I don't know if/when/how interconnect_combinations
was used prior to this PR. We can init a Grid(["Western", "Eastern"])
and then grid.interconnect == ["Western", "Eastern"]
.
Either way. I don't have strong preference. What do you think @rouille |
Given this feature could be useful in many situations especially when we are adopting a new model, do you think it is worthwhile to make all the check run regardless of whether the previous one fails or not, so that the user will be aware of all the problems in one shot? |
4515013
to
a87fedd
Compare
In this case, would we need to refactor |
a87fedd
to
0e812eb
Compare
That's what I could think of. Maybe there are better solutions @jon-hagg @rouille ? |
c2251df
to
cbd493a
Compare
What I'd do is have each function return a list of error messages and collect those, then raise an exception from the top level |
cbd493a
to
b202638
Compare
Good call, we don't need to raise exceptions in the lower-level functions, they can return either a string or None and then we can combine any returned strings as necessary for generating the final exception. I think the high-level function should interrupt control flow here if there is a problem: grid integrity is important. |
Mega-Exception logic is added. We get:
or
etc when we muck with the usa_tamu data, otherwise all tests pass. |
edc3c3e
to
cee4f92
Compare
9a608a8
to
2b41df1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. This could be very useful. Thanks for the patience and being responsive.
7768262
to
0b9ad99
Compare
0b9ad99
to
60a022e
Compare
60a022e
to
bb8733c
Compare
One thing that was not done here, that probably should be: checking for null values in all of the data frames. |
Pull Request doc
Purpose
Since we are increasingly looking to constructing Grid objects from datasets besides the
usa_tamu
CSVs, we are increasingly in need of a check that the Grid objects that we are constructing are internally consistent. This PR adds that check (closes #481), and also makes a couple of changes to some of the Western offshore wind buses we added, so that their voltages are consistent with their connected onshore voltages (found by running the tests).What the code is doing
There is one main user-facing
check_grid
function, which activates nine lower-level functions which check the bullet points from #481. Each of these is pretty self-explanatory, with the exception of the connected components check, for which we need to make a slight modification in the model immutables so that we know that the"USA"
interconnect should really have three connected components. I don't see theinterconnect_combinations
parameter being used anywhere, so I think this will be okay, but maybe @rouille knows more.Testing
Tests pass on all of our Grids.
Time estimate
15-30 minutes if you want to dig into all of the lower-level tests.