diff --git a/doc/release_notes.rst b/doc/release_notes.rst index ad1bbf4f..7edc7ac6 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -10,6 +10,9 @@ Release Notes Upcoming Release ================ +* Removed rule ``copy_config``. Instead, a config file is created for each + network output of the ``solve_*`` rules, with the same content as ``n.meta``. + * Upgrade to Snakemake v8.5+. This version is the new minimum version required. To upgrade an existing environment, run ``conda install -c bioconda snakemake-minimal">=8.5"`` and ``pip install snakemake-storage-plugin-http`` diff --git a/doc/sector.rst b/doc/sector.rst index 84a5fdc9..71a2acb8 100644 --- a/doc/sector.rst +++ b/doc/sector.rst @@ -171,11 +171,6 @@ Rule ``cluster_gas_network`` .. automodule:: cluster_gas_network -Rule ``copy_config`` -============================================================================== - -.. automodule:: copy_config - Rule ``prepare_sector_network`` ============================================================================== diff --git a/rules/postprocess.smk b/rules/postprocess.smk index 1b188829..30de78bb 100644 --- a/rules/postprocess.smk +++ b/rules/postprocess.smk @@ -3,10 +3,6 @@ # SPDX-License-Identifier: MIT -localrules: - copy_config, - - if config["foresight"] != "perfect": rule plot_power_network_clustered: @@ -137,20 +133,6 @@ if config["foresight"] == "perfect": "../scripts/plot_power_network_perfect.py" -rule copy_config: - params: - RDIR=RDIR, - output: - RESULTS + "config.yaml", - threads: 1 - resources: - mem_mb=1000, - conda: - "../envs/environment.yaml" - script: - "../scripts/copy_config.py" - - rule make_summary: params: foresight=config_provider("foresight"), diff --git a/rules/solve_electricity.smk b/rules/solve_electricity.smk index 8481c75b..06d2f4aa 100644 --- a/rules/solve_electricity.smk +++ b/rules/solve_electricity.smk @@ -14,9 +14,9 @@ rule solve_network: custom_extra_functionality=input_custom_extra_functionality, input: network=resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"), - config=RESULTS + "config.yaml", output: network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", + config=RESULTS + "configs/config.elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.yaml", log: solver=normpath( RESULTS diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 57b8a9d3..28c0313f 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -117,10 +117,11 @@ rule solve_sector_network_myopic: network=RESULTS + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", costs=resources("costs_{planning_horizons}.csv"), - config=RESULTS + "config.yaml", output: - RESULTS + network=RESULTS + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + config=RESULTS + + "configs/config.elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.yaml", shadow: "shallow" log: diff --git a/rules/solve_overnight.smk b/rules/solve_overnight.smk index 26e6e220..26dee7a6 100644 --- a/rules/solve_overnight.smk +++ b/rules/solve_overnight.smk @@ -15,10 +15,11 @@ rule solve_sector_network: input: network=RESULTS + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", - config=RESULTS + "config.yaml", output: - RESULTS + network=RESULTS + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + config=RESULTS + + "configs/config.elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.yaml", shadow: "shallow" log: diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index a565d978..215757fe 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -107,10 +107,10 @@ rule solve_sector_network_perfect: network=RESULTS + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_brownfield_all_years.nc", costs=resources("costs_2030.csv"), - config=RESULTS + "config.yaml", output: - RESULTS + network=RESULTS + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_brownfield_all_years.nc", + config="configs/config.elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_brownfield_all_years.yaml", threads: solver_threads resources: mem_mb=config_provider("solving", "mem"), diff --git a/scripts/copy_config.py b/scripts/copy_config.py deleted file mode 100644 index 0a5fe10b..00000000 --- a/scripts/copy_config.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors -# -# SPDX-License-Identifier: MIT -""" -Copy used configuration files and important scripts for archiving. -""" - - -import yaml -from _helpers import set_scenario_config - -if __name__ == "__main__": - if "snakemake" not in globals(): - from _helpers import mock_snakemake - - snakemake = mock_snakemake("copy_config") - - set_scenario_config(snakemake) - - with open(snakemake.output[0], "w") as yaml_file: - yaml.dump( - snakemake.config, - yaml_file, - default_flow_style=False, - allow_unicode=True, - sort_keys=False, - ) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 7e53e606..6cb9a054 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -36,6 +36,7 @@ import numpy as np import pandas as pd import pypsa import xarray as xr +import yaml from _benchmark import memory_logger from _helpers import ( configure_logging, @@ -968,4 +969,13 @@ if __name__ == "__main__": logger.info(f"Maximum memory usage: {mem.mem_usage}") n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards))) - n.export_to_netcdf(snakemake.output[0]) + n.export_to_netcdf(snakemake.output.network) + + with open(snakemake.output.config, "w") as file: + yaml.dump( + n.meta, + file, + default_flow_style=False, + allow_unicode=True, + sort_keys=False, + )