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

feat: allow the user to remove lines, buses, plants, and DC lines #554

Merged
merged 3 commits into from
Oct 29, 2021

Conversation

danielolsen
Copy link
Contributor

@danielolsen danielolsen commented Sep 28, 2021

Pull Request doc

Purpose

Partial fulfilment of Closes #423. Plants and DC lines can already be effectively removed by scaling them down to zero, this allows branches and buses to be removed as well. If we like the structure of the branch and bus removal, and want to enable full removal of plants, DC lines, storage, etc., then I can amend this PR to include those analogous methods as well.

What the code is doing

Within the ChangeTable class:

  • We add new methods remove_bus and remove_branch, which check that the elements to be removed are actually in the grid before adding to the change table dictionary. remove_bus has a check to ensure that a bus cannot be removed if there's at least one plant with non-zero capacity at it, and to implement this we modify _get_df_with_new_elements so that if we request the plant table, we apply any plant scaling.
  • We add a user notification method, to ensure that the user is aware if they've accidentally islanded some load buses. This will not break the simulation, but load shedding will be enabled which could slow simulation.

Within the TransformGrid class:

  • We interpret the "remove_bus" and "remove_branch" change table keys.

Testing

New unit tests added.

Time estimate

15-30 minutes.

for subkey, subdict in self.ct.get(k, {}).items()
]
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you lost me here. What if modification is a single element, i.e., table is not plant? Won't modification_keys[1:] raise an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we'll just get an empty list:

>>> foo = ["a"]
>>> foo[1:]
[]

The current implementation is clunky for sure. If table == "plant", then we want to reliably create a tuple that includes all plant additions and plant scaling information. If table != "plant", we should be creating a tuple as before, just with one new top-level string entry for "new_bus" or "new_branch" or whatever.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should not, for readability, purpose have a modified_elements_tuple for plants (within if table == "plants" statement) and another one for the other (bus, branch, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored this a bit to try to make it a little clearer what's going on.

@rouille
Copy link
Collaborator

rouille commented Oct 11, 2021

I guess at some point we should use the generators' type in the grid model (defined in powersimdata.network.[grid_model].constants.plants) and not redefined those in the change_table module:

_resources = (
    "coal",
    "dfo",
    "geothermal",
    "ng",
    "nuclear",
    "hydro",
    "solar",
    "wind",
    "wind_offshore",
    "biomass",
    "other",
)
_renewable_resource = {"hydro", "solar", "wind", "wind_offshore"}

Same in the TransformGrid class.

I wil take care of it in a follow up PR

@rouille
Copy link
Collaborator

rouille commented Oct 11, 2021

Should we update the clear method to be able to remove the two keys introduced in this PR?

@danielolsen
Copy link
Contributor Author

Should we update the clear method to be able to remove the two keys introduced in this PR?

Done.

@rouille
Copy link
Collaborator

rouille commented Oct 26, 2021

Do you plan to remove the other objects (DC lines, plants, etc) in this PR?

@danielolsen
Copy link
Contributor Author

Do you plan to remove the other objects (DC lines, plants, etc) in this PR?

Done.

Copy link
Collaborator

@rouille rouille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think it will be nice to develop some checks to ensure that demand does not exceed generation and so forth.

Comment on lines +923 to +958
def _check_for_islanded_load_buses(self):
"""Identifies buses with non-zero demand, with no connected lines, and warns."""
bus = self._get_transformed_df("bus")
connected_buses = set().union(
*[
set(self.grid.branch["from_bus_id"]),
set(self.grid.branch["to_bus_id"]),
set(self.grid.dcline["from_bus_id"]),
set(self.grid.dcline["to_bus_id"]),
]
)
load_buses = set(bus.query("Pd > 0").index)
diff = load_buses - connected_buses
if len(diff) > 0:
print(f"Warning: load buses connected to no lines exist: {sorted(diff)}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a neat check. Following the same logic, do we want to _check_for_islanded_generation_buses, or a comprehensive check that covers all the potential disconnected issues when removing entries from the grid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are two levels of potential issues: branches or DC lines or plants that connect to non-existent buses will crash the simulation engine, but islanded load buses should be okay since the simulation engine will just shed the load and continue. That's why I had one check raise an exception, but the other just printed a warning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Thinking a little further, here is my list of potential issues:

  • branches, DC lines, plants or storage that result in connecting to non-existent buses (error)
  • removing entries makes the resultant grid multiple connected components (isolated load/generation buses are special cases in this situation)
    • on each island, if load (we only know Pd instead of actual load anyways) > generation, it is okay since load shedding will take care of it (warning)
    • on each island, if sum(Pmin) > load, it will crash the engine, however, I'm not sure how to check this though (maybe also warning instead of error?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pmin issues are also tricky since we're re-setting some Pmins within REISE.jl, which PowerSimData doesn't know about. If we add generation spillage to REISE.jl that should take care of things I think, and make the big problem into a smaller once (since we'll eventually get to a feasible solution).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will leave this thread open for future PRs.

@danielolsen danielolsen changed the title feat: allow the user to remove lines and buses feat: allow the user to remove lines, buses, plants, and DC lines Oct 26, 2021
Copy link
Collaborator

@BainanXia BainanXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@danielolsen danielolsen merged commit f9ef411 into develop Oct 29, 2021
@danielolsen danielolsen deleted the daniel/remove_line branch October 29, 2021 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to remove grid elements from change table
4 participants