From 7e99f3bba7deecb4cc73568d9fcee9b3ad58950a Mon Sep 17 00:00:00 2001 From: Thomas Gilon Date: Fri, 22 Mar 2024 10:05:40 +0100 Subject: [PATCH 01/11] Fix error with symbol of buses in simplify_network --- doc/release_notes.rst | 2 ++ scripts/simplify_network.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index b868e5e9..1aaaaebd 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -164,6 +164,8 @@ Upcoming Release * Fix duplicated years in `add_land_use_constraint_m`. +* Fix error with `symbol` of `buses` in `simplify_network`. + PyPSA-Eur 0.10.0 (19th February 2024) ===================================== diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index eac026a4..24df7312 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -594,18 +594,6 @@ if __name__ == "__main__": ) busmaps.append(busmap_hac) - if snakemake.wildcards.simpl: - n, cluster_map = cluster( - n, - int(snakemake.wildcards.simpl), - params.focus_weights, - solver_name, - params.simplify_network["algorithm"], - params.simplify_network["feature"], - params.aggregation_strategies, - ) - busmaps.append(cluster_map) - # some entries in n.buses are not updated in previous functions, therefore can be wrong. as they are not needed # and are lost when clustering (for example with the simpl wildcard), we remove them for consistency: remove = [ @@ -621,6 +609,18 @@ if __name__ == "__main__": n.buses.drop(remove, axis=1, inplace=True, errors="ignore") n.lines.drop(remove, axis=1, errors="ignore", inplace=True) + if snakemake.wildcards.simpl: + n, cluster_map = cluster( + n, + int(snakemake.wildcards.simpl), + params.focus_weights, + solver_name, + params.simplify_network["algorithm"], + params.simplify_network["feature"], + params.aggregation_strategies, + ) + busmaps.append(cluster_map) + update_p_nom_max(n) n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards))) From fd01cb0a756d769c1d638b38c372ae517814d097 Mon Sep 17 00:00:00 2001 From: Thomas Gilon Date: Fri, 22 Mar 2024 15:57:37 +0100 Subject: [PATCH 02/11] Fix type error in cluster_network with "m" configuration --- doc/release_notes.rst | 2 ++ scripts/cluster_network.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index b868e5e9..e561cbe0 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -164,6 +164,8 @@ Upcoming Release * Fix duplicated years in `add_land_use_constraint_m`. +* Fix type error with `m` option in `cluster_network`. + PyPSA-Eur 0.10.0 (19th February 2024) ===================================== diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 3f6c9ea2..22fb4176 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -471,7 +471,7 @@ if __name__ == "__main__": conventional_carriers = set(params.conventional_carriers) if snakemake.wildcards.clusters.endswith("m"): n_clusters = int(snakemake.wildcards.clusters[:-1]) - aggregate_carriers = params.conventional_carriers & aggregate_carriers + aggregate_carriers = conventional_carriers & aggregate_carriers elif snakemake.wildcards.clusters.endswith("c"): n_clusters = int(snakemake.wildcards.clusters[:-1]) aggregate_carriers = aggregate_carriers - conventional_carriers From 585f9a32a7a18d47d3b35c39169d10019f129f4d Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 25 Mar 2024 14:07:02 +0100 Subject: [PATCH 03/11] cluster_network: ensure correct indexing of weights --- scripts/cluster_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 22fb4176..903cbe9b 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -231,7 +231,7 @@ def distribute_clusters(n, n_clusters, focus_weights=None, solver_name="scip"): .pipe(normed) ) - N = n.buses.groupby(["country", "sub_network"]).size() + N = n.buses.groupby(["country", "sub_network"]).size()[L.index] assert ( n_clusters >= len(N) and n_clusters <= N.sum() @@ -454,7 +454,7 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("cluster_network", simpl="", clusters="5") + snakemake = mock_snakemake("cluster_network", simpl="", clusters="40") configure_logging(snakemake) set_scenario_config(snakemake) From 34f02942640504dbbfc2befead9d5820a783cca2 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 25 Mar 2024 14:08:38 +0100 Subject: [PATCH 04/11] scenario management: fix shared resources --- scripts/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 0fd5ab2b..8e8d67c8 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -106,7 +106,7 @@ def get_run_path(fn, dir, rdir, shared_resources): elif isinstance(shared_resources, str): rdir = shared_resources + "/" elif isinstance(shared_resources, bool): - rdir = "" + rdir = "" if shared_resources else rdir else: raise ValueError( "shared_resources must be a boolean, str, or 'base' for special handling." From 50466d959398b9d42e489cc7eac8daab9764f293 Mon Sep 17 00:00:00 2001 From: Thomas Gilon Date: Mon, 25 Mar 2024 15:44:05 +0100 Subject: [PATCH 05/11] Fix grouping year reference in add_land_use_constraint_m --- doc/release_notes.rst | 2 +- scripts/solve_network.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index b868e5e9..ca8dce2a 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -162,7 +162,7 @@ Upcoming Release * Adapt the disabling of transmission expansion in myopic foresight optimisations when limit is already reached to also handle cost limits. -* Fix duplicated years in `add_land_use_constraint_m`. +* Fix duplicated years and grouping years reference in `add_land_use_constraint_m`. PyPSA-Eur 0.10.0 (19th February 2024) ===================================== diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 10bc84e6..0f6725c7 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -155,7 +155,7 @@ def _add_land_use_constraint(n): def _add_land_use_constraint_m(n, planning_horizons, config): # if generators clustering is lower than network clustering, land_use accounting is at generators clusters - grouping_years = config["existing_capacities"]["grouping_years"] + grouping_years = config["existing_capacities"]["grouping_years_power"] current_horizon = snakemake.wildcards.planning_horizons for carrier in ["solar", "onwind", "offwind-ac", "offwind-dc"]: From 8b2a068b3a4c4411c8fde1ff0e46a498cae7f1f8 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Tue, 26 Mar 2024 11:57:21 +0100 Subject: [PATCH 06/11] Check if scenario file exists before attempting to load Useful when running the `create_scenarios` rule the first time. --- scripts/_helpers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 8e8d67c8..f063877e 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -43,10 +43,11 @@ def get_scenarios(run): scenario_config = run.get("scenarios", {}) if run["name"] and scenario_config.get("enable"): fn = Path(scenario_config["file"]) - scenarios = yaml.safe_load(fn.read_text()) - if run["name"] == "all": - run["name"] = list(scenarios.keys()) - return scenarios + if fn.exists(): + scenarios = yaml.safe_load(fn.read_text()) + if run["name"] == "all": + run["name"] = list(scenarios.keys()) + return scenarios return {} From be7dc0d0bbf7047002d87828f823d81022d6e474 Mon Sep 17 00:00:00 2001 From: Fabian Hofmann Date: Tue, 26 Mar 2024 13:28:06 +0100 Subject: [PATCH 07/11] postprocess: fix typo in benchmark folder --- rules/postprocess.smk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/postprocess.smk b/rules/postprocess.smk index 2b298610..e7df2e66 100644 --- a/rules/postprocess.smk +++ b/rules/postprocess.smk @@ -44,7 +44,7 @@ if config["foresight"] != "perfect": benchmark: ( RESULTS - + "benchmarksplot_power_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" + + "benchmarks/plot_power_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" ) conda: "../envs/environment.yaml" From 89dbd53805680427231c96904655526548ee0021 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Tue, 26 Mar 2024 17:20:10 +0100 Subject: [PATCH 08/11] provide Path object as input to ConfigSettings --- doc/release_notes.rst | 2 ++ scripts/_helpers.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index e561cbe0..e08981d3 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -10,6 +10,8 @@ Release Notes Upcoming Release ================ +* bugfix: convert Strings to pathlib.Path objects as input to ConfigSettings + * Allow the use of more solvers in clustering (Xpress, COPT, Gurobi, CPLEX, SCIP, MOSEK). * Enhanced support for choosing different weather years diff --git a/scripts/_helpers.py b/scripts/_helpers.py index f063877e..64ccab87 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -427,7 +427,7 @@ def mock_snakemake( configfiles = [configfiles] resource_settings = ResourceSettings() - config_settings = ConfigSettings(configfiles=configfiles) + config_settings = ConfigSettings(configfiles=map(Path, configfiles)) workflow_settings = WorkflowSettings() storage_settings = StorageSettings() dag_settings = DAGSettings(rerun_triggers=[]) From b34ce8d6f2221c1a9ec9cbe0dc1df74c14bdd7cb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 19:41:00 +0000 Subject: [PATCH 09/11] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/macisamuele/language-formatters-pre-commit-hooks: v2.12.0 → v2.13.0](https://github.com/macisamuele/language-formatters-pre-commit-hooks/compare/v2.12.0...v2.13.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2fb51c54..cb053d47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,7 +67,7 @@ repos: # Do YAML formatting (before the linter checks it for misses) - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.12.0 + rev: v2.13.0 hooks: - id: pretty-format-yaml args: [--autofix, --indent, "2", --preserve-quotes] From f7152856827705bd94cd7be9812495a82f22b834 Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:48:37 +0200 Subject: [PATCH 10/11] adjust resources perfect foresight --- rules/solve_perfect.smk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index d4cbd6f3..70acc830 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -35,7 +35,8 @@ rule add_existing_baseyear: planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear threads: 1 resources: - mem_mb=2000, + mem_mb=config_provider("solving", "mem_mb"), + runtime=config_provider("solving", "runtime", default="24h"), log: logs( "add_existing_baseyear_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log" From 3819e643774b028f5b16140d867222a2e41e8b12 Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:50:09 +0200 Subject: [PATCH 11/11] remove solver name --- config/config.default.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index a8cd195c..235c238d 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -786,7 +786,6 @@ solving: PreDual: 0 GURO_PAR_BARDENSETHRESH: 200 gurobi-numeric-focus: - name: gurobi NumericFocus: 3 # Favour numeric stability over speed method: 2 # barrier crossover: 0 # do not use crossover @@ -798,7 +797,6 @@ solving: threads: 8 Seed: 123 gurobi-fallback: # Use gurobi defaults - name: gurobi crossover: 0 method: 2 # barrier BarHomogeneous: 1 # Use homogeneous barrier if standard does not converge