From 26184e370bd3ec34ecfc8209c7c27909eb5625e7 Mon Sep 17 00:00:00 2001 From: JulianGeis Date: Wed, 17 Apr 2024 15:02:13 +0200 Subject: [PATCH 1/5] add functionality for post discretization of lines and transmission infrastructure links --- scripts/solve_network.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 9a6384b5..2a64a0f8 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -45,6 +45,7 @@ from _helpers import ( ) from pypsa.descriptors import get_activity_mask from pypsa.descriptors import get_switchable_as_dense as get_as_dense +from pypsa.optimization.abstract import optimize_transmission_expansion_iteratively logger = logging.getLogger(__name__) pypsa.pf.logger.setLevel(logging.WARNING) @@ -919,11 +920,13 @@ def solve_network(n, config, solving, **kwargs): elif skip_iterations: status, condition = n.optimize(**kwargs) else: - kwargs["track_iterations"] = (cf_solving.get("track_iterations", False),) - kwargs["min_iterations"] = (cf_solving.get("min_iterations", 4),) - kwargs["max_iterations"] = (cf_solving.get("max_iterations", 6),) - status, condition = n.optimize.optimize_transmission_expansion_iteratively( - **kwargs + kwargs["track_iterations"] = cf_solving["track_iterations"] + kwargs["min_iterations"] = cf_solving["min_iterations"] + kwargs["max_iterations"] = cf_solving["max_iterations"] + kwargs["lines_disc"] = config["post-discretization"]["lines"] + kwargs["links_disc"] = config["post-discretization"]["links"] + status, condition = optimize_transmission_expansion_iteratively( + n, **kwargs ) if status != "ok" and not rolling_horizon: From 5dc2e6862b657266cef411824a46f5e0d7b6dfa2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:03:17 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/solve_network.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 2a64a0f8..0ca490f0 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -925,9 +925,7 @@ def solve_network(n, config, solving, **kwargs): kwargs["max_iterations"] = cf_solving["max_iterations"] kwargs["lines_disc"] = config["post-discretization"]["lines"] kwargs["links_disc"] = config["post-discretization"]["links"] - status, condition = optimize_transmission_expansion_iteratively( - n, **kwargs - ) + status, condition = optimize_transmission_expansion_iteratively(n, **kwargs) if status != "ok" and not rolling_horizon: logger.warning( From 84689e9257e575ff297df8cf17015258a29ad6f1 Mon Sep 17 00:00:00 2001 From: JulianGeis Date: Mon, 6 May 2024 13:43:55 +0200 Subject: [PATCH 3/5] add docu --- doc/configtables/post_discretization.csv | 10 ++++++++++ doc/release_notes.rst | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 doc/configtables/post_discretization.csv diff --git a/doc/configtables/post_discretization.csv b/doc/configtables/post_discretization.csv new file mode 100644 index 00000000..77740076 --- /dev/null +++ b/doc/configtables/post_discretization.csv @@ -0,0 +1,10 @@ +,Unit,Values,Description +post-discretization,,, +-- AC,int,1700,Minimum capacity of discrete "AC" line expansion steps. +links,,, +-- DC,int,2000,Check +-- gas pipeline,int,1500,Minimum capacity of discrete "gas pipeline". +-- gas pipeline new,int,1500,Minimum capacity of discrete "new gas pipeline". +-- H2 pipeline,int,1200,Minimum capacity of discrete "H2 pipeline". +-- H2 pipeline (Kernnetz),int,1200,Minimum capacity of discrete "H2 pipeline (Kernnetz)". +-- H2 pipeline retrofitted,int,1200,Minimum capacity of discrete "retrofitted H2 pipeline". diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 6605f9a4..c2216d03 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -43,6 +43,8 @@ Upcoming Release * Allow dictionary for the config aviation_demand_factor. +* Post discretize network infrastructure like lines and links. + * Group existing capacities to the earlier grouping_year for consistency with optimized capacities. * Update data bundle: From 9b50c846a09254588d7e96cc8c1e36618482606c Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 15 May 2024 14:56:50 +0200 Subject: [PATCH 4/5] solve: add option for post-discretization of lines and links --- config/config.default.yaml | 13 +++++++++++-- doc/configtables/post_discretization.csv | 10 ---------- doc/configtables/solving.csv | 7 +++++++ doc/release_notes.rst | 5 ++++- envs/environment.yaml | 2 +- scripts/solve_network.py | 9 +++++---- 6 files changed, 28 insertions(+), 18 deletions(-) delete mode 100644 doc/configtables/post_discretization.csv diff --git a/config/config.default.yaml b/config/config.default.yaml index 1e7af9ea..e04ac2a3 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -770,11 +770,20 @@ solving: # io_api: "direct" # Increases performance but only supported for the highs and gurobi solvers # options that go into the optimize function track_iterations: false - min_iterations: 4 - max_iterations: 6 + min_iterations: 2 + max_iterations: 3 transmission_losses: 2 linearized_unit_commitment: true horizon: 365 + post_discretization: + enable: false + line_unit_size: 1700 + link_unit_size: + DC: 2000 + H2 pipeline: 1200 + gas pipeline: 1500 + line_threshold: 0.3 + link_threshold: 0.3 constraints: CCL: false diff --git a/doc/configtables/post_discretization.csv b/doc/configtables/post_discretization.csv deleted file mode 100644 index 77740076..00000000 --- a/doc/configtables/post_discretization.csv +++ /dev/null @@ -1,10 +0,0 @@ -,Unit,Values,Description -post-discretization,,, --- AC,int,1700,Minimum capacity of discrete "AC" line expansion steps. -links,,, --- DC,int,2000,Check --- gas pipeline,int,1500,Minimum capacity of discrete "gas pipeline". --- gas pipeline new,int,1500,Minimum capacity of discrete "new gas pipeline". --- H2 pipeline,int,1200,Minimum capacity of discrete "H2 pipeline". --- H2 pipeline (Kernnetz),int,1200,Minimum capacity of discrete "H2 pipeline (Kernnetz)". --- H2 pipeline retrofitted,int,1200,Minimum capacity of discrete "retrofitted H2 pipeline". diff --git a/doc/configtables/solving.csv b/doc/configtables/solving.csv index 4d245195..1fb2c692 100644 --- a/doc/configtables/solving.csv +++ b/doc/configtables/solving.csv @@ -14,6 +14,13 @@ options,,, -- transmission_losses,int,[0-9],"Add piecewise linear approximation of transmission losses based on n tangents. Defaults to 0, which means losses are ignored." -- linearized_unit_commitment,bool,"{'true','false'}",Whether to optimise using the linearized unit commitment formulation. -- horizon,--,int,Number of snapshots to consider in each iteration. Defaults to 100. +-- post_discretization,,, +-- -- enable,bool,"{'true','false'}",Switch to enable post-discretization of the network. Disabled by default. +-- -- line_unit_size,MW,float,Discrete unit size of lines in MW. +-- -- link_unit_size,MW,float,Discrete unit size of links in MW by carrier (given in dictionary style. +-- -- -- {carrier},,, +-- -- line_threshold,,float,The threshold relative to the discrete line unit size beyond which to round up to the next unit. Defaults to 0.3. +-- -- link_threshold,,float,The threshold relative to the discrete link unit size beyond which to round up to the next unit. Defaults to 0.3. constraints ,,, -- CCL,bool,"{'true','false'}",Add minimum and maximum levels of generator nominal capacity per carrier for individual countries. These can be specified in the file linked at ``electricity: agg_p_nom_limits`` in the configuration. File defaults to ``data/agg_p_nom_minmax.csv``. -- EQ,bool/string,"{'false',`n(c| )``; i.e. ``0.5``-``0.7c``}",Require each country or node to on average produce a minimal share of its total consumption itself. Example: ``EQ0.5c`` demands each country to produce on average at least 50% of its consumption; ``EQ0.5`` demands each node to produce on average at least 50% of its consumption. diff --git a/doc/release_notes.rst b/doc/release_notes.rst index c2216d03..f7e816ee 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -43,7 +43,10 @@ Upcoming Release * Allow dictionary for the config aviation_demand_factor. -* Post discretize network infrastructure like lines and links. +* Add option to post-discretize line and link capacities based on unit sizes and + rounding thresholds specified in the configuration under ``solving: options: + post_discretization:`` when iterative solving is enables (``solving: optiosn: + skip_iterations: false``). This option is disabled by default. * Group existing capacities to the earlier grouping_year for consistency with optimized capacities. diff --git a/envs/environment.yaml b/envs/environment.yaml index 58835603..dc5fad2b 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -11,7 +11,7 @@ dependencies: - pip - atlite>=0.2.9 -- pypsa>=0.26.1 +- pypsa>=0.28 - linopy - dask diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 0ca490f0..67c5e805 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -45,7 +45,6 @@ from _helpers import ( ) from pypsa.descriptors import get_activity_mask from pypsa.descriptors import get_switchable_as_dense as get_as_dense -from pypsa.optimization.abstract import optimize_transmission_expansion_iteratively logger = logging.getLogger(__name__) pypsa.pf.logger.setLevel(logging.WARNING) @@ -923,9 +922,11 @@ def solve_network(n, config, solving, **kwargs): kwargs["track_iterations"] = cf_solving["track_iterations"] kwargs["min_iterations"] = cf_solving["min_iterations"] kwargs["max_iterations"] = cf_solving["max_iterations"] - kwargs["lines_disc"] = config["post-discretization"]["lines"] - kwargs["links_disc"] = config["post-discretization"]["links"] - status, condition = optimize_transmission_expansion_iteratively(n, **kwargs) + if cf_solving["post_discretization"].pop("enable"): + kwargs.update(cf_solving["post_discretization"]) + status, condition = n.optimize.optimize_transmission_expansion_iteratively( + **kwargs + ) if status != "ok" and not rolling_horizon: logger.warning( From ea8fc31a30fd158dede9255c8a542d707acc25d9 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 15 May 2024 15:15:09 +0200 Subject: [PATCH 5/5] link_thresholds as dictionary, not float, more logging messages --- config/config.default.yaml | 7 +++++-- doc/configtables/solving.csv | 7 ++++--- scripts/solve_network.py | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index e04ac2a3..b26e73ce 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -778,12 +778,15 @@ solving: post_discretization: enable: false line_unit_size: 1700 + line_threshold: 0.3 link_unit_size: DC: 2000 H2 pipeline: 1200 gas pipeline: 1500 - line_threshold: 0.3 - link_threshold: 0.3 + link_threshold: + DC: 0.3 + H2 pipeline: 0.3 + gas pipeline: 0.3 constraints: CCL: false diff --git a/doc/configtables/solving.csv b/doc/configtables/solving.csv index 1fb2c692..ad8778a3 100644 --- a/doc/configtables/solving.csv +++ b/doc/configtables/solving.csv @@ -17,10 +17,11 @@ options,,, -- post_discretization,,, -- -- enable,bool,"{'true','false'}",Switch to enable post-discretization of the network. Disabled by default. -- -- line_unit_size,MW,float,Discrete unit size of lines in MW. --- -- link_unit_size,MW,float,Discrete unit size of links in MW by carrier (given in dictionary style. +-- -- line_threshold,,float,The threshold relative to the discrete line unit size beyond which to round up to the next unit. +-- -- link_unit_size,MW,float,Discrete unit size of links in MW by carrier (given in dictionary style). +-- -- -- {carrier},,, +-- -- link_threshold,,float,The threshold relative to the discrete link unit size beyond which to round up to the next unit by carrier (given in dictionary style). -- -- -- {carrier},,, --- -- line_threshold,,float,The threshold relative to the discrete line unit size beyond which to round up to the next unit. Defaults to 0.3. --- -- link_threshold,,float,The threshold relative to the discrete link unit size beyond which to round up to the next unit. Defaults to 0.3. constraints ,,, -- CCL,bool,"{'true','false'}",Add minimum and maximum levels of generator nominal capacity per carrier for individual countries. These can be specified in the file linked at ``electricity: agg_p_nom_limits`` in the configuration. File defaults to ``data/agg_p_nom_minmax.csv``. -- EQ,bool/string,"{'false',`n(c| )``; i.e. ``0.5``-``0.7c``}",Require each country or node to on average produce a minimal share of its total consumption itself. Example: ``EQ0.5c`` demands each country to produce on average at least 50% of its consumption; ``EQ0.5`` demands each node to produce on average at least 50% of its consumption. diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 67c5e805..6438d275 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -923,6 +923,7 @@ def solve_network(n, config, solving, **kwargs): kwargs["min_iterations"] = cf_solving["min_iterations"] kwargs["max_iterations"] = cf_solving["max_iterations"] if cf_solving["post_discretization"].pop("enable"): + logger.info("Add post-discretization parameters.") kwargs.update(cf_solving["post_discretization"]) status, condition = n.optimize.optimize_transmission_expansion_iteratively( **kwargs