Skip to content

Commit

Permalink
Merge branch 'dev' into wp_flex_changed_reinforcement_2
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Apr 24, 2024
2 parents 5288c7d + 0f603cc commit b5d976f
Show file tree
Hide file tree
Showing 15 changed files with 567 additions and 270 deletions.
7 changes: 6 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def setup(sphinx):
"networkx.%s",
),
"sqlalchemy": (
"http://docs.sqlalchemy.org/en/latest/core/connections.html#%s",
"https://docs.sqlalchemy.org/en/latest/core/connections.html#%s",
"sqlalchemy.%s",
),
"numpy": (
Expand All @@ -134,6 +134,11 @@ def setup(sphinx):
"plotly.%s",
),
}
# ignore the following external links when checking the links
# stackoverflow is listed here because for some reason the link check fails for these
# in the github action, even though the link is correct
linkcheck_ignore = [r"https://stackoverflow.com*"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
4 changes: 2 additions & 2 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The steps required to set up HSL are also described in the
Here is a short version for reference:

First, you need to obtain an academic license for HSL Solvers.
Under https://www.hsl.rl.ac.uk/ipopt/ download the sources for Coin-HSL Full (Stable).
Under https://licences.stfc.ac.uk/product/coin-hsl download the sources for Coin-HSL Full (Stable).
You will need to provide an institutional e-mail to gain access.

Unpack the tar.gz:
Expand Down Expand Up @@ -163,7 +163,7 @@ Beyond a running and up-to-date installation of eDisGo you need **grid topology
data**. Currently synthetic grid data generated with the python project
`Ding0 <https://github.com/openego/ding0>`_
is the only supported data source. You can retrieve data from
`Zenodo <https://zenodo.org/record/890479>`_
`Zenodo <https://zenodo.org/records/890479>`_
(make sure you choose latest data) or check out the
`Ding0 documentation <https://dingo.readthedocs.io/en/dev/usage_details.html#ding0-examples>`_
on how to generate grids yourself.
Expand Down
1 change: 1 addition & 0 deletions doc/whatsnew/v0-3-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Changes
* Added method to aggregate LV grid buses to station bus secondary side `#353 <https://github.com/openego/eDisGo/pull/353>`_
* Adapted codebase to work with pandas 2.0 `#373 <https://github.com/openego/eDisGo/pull/373>`_
* Added option to run reinforcement with reduced number of time steps `#379 <https://github.com/openego/eDisGo/pull/379>`_
(adapted in `#395 <https://github.com/openego/eDisGo/pull/395>`_)
* Added optimization method to determine dispatch of flexibilities that lead to minimal network expansion costs `#376 <https://github.com/openego/eDisGo/pull/376>`_
* Added a new reinforcement method that separate lv grids when the overloading is very high `#380 <https://github.com/openego/eDisGo/pull/380>`_
* Move function to assign feeder to Topology class and add methods to the Grid class to get information on the feeders `#360 <https://github.com/openego/eDisGo/pull/360>`_
Expand Down
2 changes: 1 addition & 1 deletion eDisGo_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python >= 3.8, < 3.10
- pip
- pandas >= 1.4
- pandas >= 1.4, < 2.2.0
- conda-forge::fiona
- conda-forge::geopy
- conda-forge::geopandas
Expand Down
2 changes: 1 addition & 1 deletion eDisGo_env_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python >= 3.8, < 3.10
- pip
- pandas >= 1.4
- pandas >= 1.4, < 2.2.0
- conda-forge::fiona
- conda-forge::geopy
- conda-forge::geopandas
Expand Down
20 changes: 16 additions & 4 deletions edisgo/edisgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,18 +1316,30 @@ def reinforce(
default is 1.0, in which case all most critical time steps are selected.
Default: 1.0.
use_troubleshooting_mode : bool
In case `reduced_analysis` is set to True, this parameter can be
used to specify how to handle non-convergence issues in the power flow
analysis. If set to True, non-convergence issues are tried to be
In case `reduced_analysis` is set to True, this parameter can be used to
specify how to handle non-convergence issues when determining the most
critical time steps. If set to True, non-convergence issues are tried to be
circumvented by reducing load and feed-in until the power flow converges.
The most critical time steps are then determined based on the power flow
results with the reduced load and feed-in. If False, an error will be
raised in case time steps do not converge. Default: True.
raised in case time steps do not converge.
Setting this to True doesn't make sense for the grid reinforcement as the
troubleshooting mode is only used when determining the most critical time
steps not when running a power flow analysis to determine grid reinforcement
needs. To handle non-convergence in the grid reinforcement set parameter
`catch_convergence_problems` to True.
Default: False.
run_initial_analyze : bool
In case `reduced_analysis` is set to True, this parameter can be
used to specify whether to run an initial analyze to determine most
critical time steps or to use existing results. If set to False,
`use_troubleshooting_mode` is ignored. Default: True.
weight_by_costs : bool
In case `reduced_analysis` is set to True, this parameter can be used
to specify whether to weight time steps by estimated grid expansion costs.
See parameter `weight_by_costs` in
:func:`~.tools.temporal_complexity_reduction.get_most_critical_time_steps`
for more information. Default: False.
Returns
--------
Expand Down
107 changes: 34 additions & 73 deletions edisgo/flex_opt/reinforce_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,18 @@ def reinforce_grid(
In case `reduced_analysis` is set to True, this parameter can be used
to specify how to handle non-convergence issues in the power flow analysis.
See parameter `use_troubleshooting_mode` in function :attr:`~.EDisGo.reinforce`
for more information. Default: True.
for more information. Default: False.
run_initial_analyze : bool
In case `reduced_analysis` is set to True, this parameter can be
used to specify whether to run an initial analyze to determine most
critical time steps or to use existing results. If set to False,
`use_troubleshooting_mode` is ignored. Default: True.
weight_by_costs : bool
In case `reduced_analysis` is set to True, this parameter can be
used to specify whether to weight time steps by estimated grid expansion costs.
See parameter `weight_by_costs` in
:func:`~.tools.temporal_complexity_reduction.get_most_critical_time_steps`
for more information. Default: False.
Returns
-------
Expand Down Expand Up @@ -182,8 +188,9 @@ def reinforce_grid(
num_steps_loading=kwargs.get("num_steps_loading", None),
num_steps_voltage=kwargs.get("num_steps_voltage", None),
percentage=kwargs.get("percentage", 1.0),
use_troubleshooting_mode=kwargs.get("use_troubleshooting_mode", True),
use_troubleshooting_mode=kwargs.get("use_troubleshooting_mode", False),
run_initial_analyze=kwargs.get("run_initial_analyze", True),
weight_by_costs=kwargs.get("weight_by_costs", False),
)
if timesteps_pfa is not None and len(timesteps_pfa) == 0:
logger.debug("Zero time steps for grid reinforcement.")
Expand Down Expand Up @@ -678,7 +685,7 @@ def catch_convergence_reinforce_grid(
Reinforcement strategy to reinforce grids with non-converging time steps.
First, conducts a grid reinforcement with only converging time steps.
Afterwards, tries to run reinforcement with all time steps that did not converge
Afterward, tries to run reinforcement with all time steps that did not converge
in the beginning. At last, if there are still time steps that do not converge,
the feed-in and load time series are iteratively scaled and the grid reinforced,
starting with a low grid load and scaling-up the time series until the original
Expand All @@ -705,7 +712,6 @@ def reinforce():
edisgo,
timesteps_pfa=selected_timesteps,
scale_timeseries=set_scaling_factor,
use_troubleshooting_mode=troubleshooting_mode,
**kwargs,
)
converged = True
Expand All @@ -721,13 +727,11 @@ def reinforce():
# Get the timesteps from kwargs and then remove it to set it later manually
timesteps_pfa = kwargs.pop("timesteps_pfa", None)
selected_timesteps = timesteps_pfa
troubleshooting_mode_set = kwargs.pop("troubleshooting_mode", True)

# Initial try
logger.info("Run initial reinforcement.")
set_scaling_factor = 1.0
iteration = 0
troubleshooting_mode = False
converged = reinforce()
if converged is False:
logger.info("Initial reinforcement did not succeed.")
Expand Down Expand Up @@ -759,18 +763,18 @@ def reinforce():
"reinforcement."
)
selected_timesteps = converging_timesteps
troubleshooting_mode = troubleshooting_mode_set
reinforce()

# Run reinforcement for time steps that did not converge after initial reinforcement
if not non_converging_timesteps.empty:
logger.info(
"Run reinforcement for time steps that did not converge after initial "
"reinforcement."
)
selected_timesteps = non_converging_timesteps
troubleshooting_mode = False
converged = reinforce()
# Run reinforcement for time steps that did not converge after initial
# reinforcement (only needs to done, when grid was previously reinforced using
# converged time steps, wherefore it is within that if-statement)
if not non_converging_timesteps.empty:
logger.info(
"Run reinforcement for time steps that did not converge after initial "
"reinforcement."
)
selected_timesteps = non_converging_timesteps
converged = reinforce()

if converged:
return edisgo.results
Expand Down Expand Up @@ -803,7 +807,6 @@ def reinforce():
) + highest_converged_scaling_factor

logger.info(f"Try reinforcement with {set_scaling_factor=} at {iteration=}")
troubleshooting_mode = False
converged = reinforce()
if converged:
logger.info(
Expand All @@ -824,7 +827,6 @@ def reinforce():
if set_scaling_factor != 1:
logger.info("Run final reinforcement.")
selected_timesteps = timesteps_pfa
troubleshooting_mode = False
reinforce()

return edisgo.results
Expand Down Expand Up @@ -914,7 +916,7 @@ def enhanced_reinforce_grid(
logger.info("Run initial grid reinforcement for single LV grids.")
for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids):
logger.info(f"Check initial convergence for {lv_grid=}.")
ts_converged, ts_not_converged = edisgo_object.analyze(
_, ts_not_converged = edisgo_object.analyze(
mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id
)
if len(ts_not_converged) > 0:
Expand All @@ -933,32 +935,12 @@ def enhanced_reinforce_grid(
)
try:
logger.info(f"Try initial mode 'lv' reinforcement for {lv_grid=}.")
if len(ts_not_converged) > 0:
# if there are time steps that did not converge, run reinforcement
# first on converged time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
timesteps_pfa=ts_converged,
**kwargs,
)
# run reinforcement again in catch-convergence mode with all time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
else:
# if all time steps converged, run normal reinforcement
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
run_initial_analyze=False,
**kwargs,
)
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
logger.info(f"Initial mode 'lv' reinforcement for {lv_grid} successful.")
except (ValueError, RuntimeError, exceptions.MaximumIterationError):
logger.warning(f"Initial mode 'lv' reinforcement for {lv_grid} failed.")
Expand Down Expand Up @@ -991,7 +973,7 @@ def enhanced_reinforce_grid(

for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids):
logger.info(f"Check convergence for {lv_grid=}.")
ts_converged, ts_not_converged = edisgo_object.analyze(
_, ts_not_converged = edisgo_object.analyze(
mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id
)
if len(ts_not_converged) > 0:
Expand All @@ -1012,33 +994,12 @@ def enhanced_reinforce_grid(
)
try:
logger.info(f"Try mode 'lv' reinforcement for {lv_grid=}.")
if len(ts_not_converged) > 0:
# if there are time steps that did not converge, run reinforcement
# first on converged time steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
timesteps_pfa=ts_converged,
**kwargs,
)
# run reinforcement again in catch-convergence mode with all time
# steps
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
else:
# if all time steps converged, run normal reinforcement
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=False,
run_initial_analyze=False,
**kwargs,
)
edisgo_object.reinforce(
mode="lv",
lv_grid_id=lv_grid.id,
catch_convergence_problems=True,
**kwargs,
)
logger.info(f"Mode 'lv' reinforcement for {lv_grid} successful.")
except (ValueError, RuntimeError, exceptions.MaximumIterationError):
logger.info(f"Mode 'lv' reinforcement for {lv_grid} failed.")
Expand Down
2 changes: 1 addition & 1 deletion edisgo/io/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def engine(path: Path | str, ssh: bool = False) -> Engine:
Returns
-------
sqlalchemy.engine.base.Engine
:sqlalchemy:`sqlalchemy.Engine<sqlalchemy.engine.Engine>`
Database engine
"""
Expand Down
Loading

0 comments on commit b5d976f

Please sign in to comment.