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

remove copy_config rule and write config for each solved network #965

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
5 changes: 0 additions & 5 deletions doc/sector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ Rule ``cluster_gas_network``

.. automodule:: cluster_gas_network

Rule ``copy_config``
==============================================================================

.. automodule:: copy_config

Rule ``prepare_sector_network``
==============================================================================

Expand Down
18 changes: 0 additions & 18 deletions rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# SPDX-License-Identifier: MIT


localrules:
copy_config,


if config["foresight"] != "perfect":

rule plot_power_network_clustered:
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion rules/solve_electricity.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions rules/solve_myopic.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions rules/solve_overnight.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions rules/solve_perfect.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
28 changes: 0 additions & 28 deletions scripts/copy_config.py

This file was deleted.

12 changes: 11 additions & 1 deletion scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import pandas as pd
import pypsa
import xarray as xr
import yaml
from _benchmark import memory_logger
from _helpers import (
configure_logging,
Expand Down Expand Up @@ -968,4 +969,13 @@ def solve_network(n, config, solving, **kwargs):
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,
)
Loading