snakefmt to Snakefile

This commit is contained in:
Fabian Neumann 2023-03-08 19:22:29 +01:00
parent bf895de7cc
commit 7405377fd7
6 changed files with 34 additions and 19 deletions

View File

@ -33,7 +33,10 @@ BENCHMARKS = "benchmarks/" + RDIR
RESOURCES = "resources/" + RDIR if not run.get("shared_resources") else "resources/" RESOURCES = "resources/" + RDIR if not run.get("shared_resources") else "resources/"
RESULTS = "results/" + RDIR RESULTS = "results/" + RDIR
localrules: purge
localrules:
purge,
wildcard_constraints: wildcard_constraints:
simpl="[a-zA-Z0-9]*", simpl="[a-zA-Z0-9]*",
@ -42,6 +45,7 @@ wildcard_constraints:
opts="[-+a-zA-Z0-9\.]*", opts="[-+a-zA-Z0-9\.]*",
sector_opts="[-+a-zA-Z0-9\.\s]*", sector_opts="[-+a-zA-Z0-9\.\s]*",
include: "rules/common.smk" include: "rules/common.smk"
include: "rules/collect.smk" include: "rules/collect.smk"
include: "rules/retrieve.smk" include: "rules/retrieve.smk"
@ -62,22 +66,25 @@ if config["foresight"] == "myopic":
rule purge: rule purge:
message: "Purging generated resources and results. Downloads are kept." message:
"Purging generated resources and results. Downloads are kept."
run: run:
rmtree("resources/") rmtree("resources/")
rmtree("results/") rmtree("results/")
rule dag: rule dag:
message: "Creating DAG of workflow." message:
"Creating DAG of workflow."
output: output:
dot=RESOURCES + "dag.dot", dot=RESOURCES + "dag.dot",
pdf=RESOURCES + "dag.pdf", pdf=RESOURCES + "dag.pdf",
png=RESOURCES + "dag.png" png=RESOURCES + "dag.png",
conda: "envs/environment.yaml" conda:
"envs/environment.yaml"
shell: shell:
""" """
snakemake --rulegraph all | sed -n "/digraph/,\$p" > {output.dot} snakemake --rulegraph all | sed -n "/digraph/,\$p" > {output.dot}
dot -Tpdf -o {output.pdf} {output.dot} dot -Tpdf -o {output.pdf} {output.dot}
dot -Tpng -o {output.png} {output.dot} dot -Tpng -o {output.png} {output.dot}
""" """

View File

@ -2,6 +2,7 @@
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
def memory(w): def memory(w):
factor = 3.0 factor = 3.0
for o in w.opts.split("-"): for o in w.opts.split("-"):
@ -37,4 +38,4 @@ def solved_previous_horizon(wildcards):
+ "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_" + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_"
+ planning_horizon_p + planning_horizon_p
+ ".nc" + ".nc"
) )

View File

@ -24,7 +24,8 @@ rule plot_network:
mem_mb=10000, mem_mb=10000,
benchmark: benchmark:
( (
BENCHMARKS + "plot_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" BENCHMARKS
+ "plot_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}"
) )
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"
@ -55,7 +56,7 @@ rule copy_conda_env:
resources: resources:
mem_mb=500, mem_mb=500,
log: log:
LOGS + "copy_conda_env.log" LOGS + "copy_conda_env.log",
benchmark: benchmark:
BENCHMARKS + "copy_conda_env" BENCHMARKS + "copy_conda_env"
conda: conda:
@ -102,7 +103,7 @@ rule make_summary:
resources: resources:
mem_mb=10000, mem_mb=10000,
log: log:
LOGS + "make_summary.log" LOGS + "make_summary.log",
benchmark: benchmark:
BENCHMARKS + "make_summary" BENCHMARKS + "make_summary"
conda: conda:
@ -128,7 +129,7 @@ rule plot_summary:
resources: resources:
mem_mb=10000, mem_mb=10000,
log: log:
LOGS + "plot_summary.log" LOGS + "plot_summary.log",
benchmark: benchmark:
BENCHMARKS + "plot_summary" BENCHMARKS + "plot_summary"
conda: conda:

View File

@ -85,7 +85,7 @@ if config["enable"].get("retrieve_natura_raster", True):
output: output:
RESOURCES + "natura.tiff", RESOURCES + "natura.tiff",
log: log:
LOGS + "retrieve_natura_raster.log" LOGS + "retrieve_natura_raster.log",
resources: resources:
mem_mb=5000, mem_mb=5000,
retries: 2 retries: 2
@ -168,7 +168,7 @@ rule retrieve_ship_raster:
output: output:
"data/shipdensity_global.zip", "data/shipdensity_global.zip",
log: log:
LOGS + "retrieve_ship_raster.log" LOGS + "retrieve_ship_raster.log",
resources: resources:
mem_mb=5000, mem_mb=5000,
retries: 2 retries: 2

View File

@ -29,10 +29,12 @@ rule add_existing_baseyear:
resources: resources:
mem_mb=2000, mem_mb=2000,
log: log:
LOGS + "add_existing_baseyear_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log" LOGS
+ "add_existing_baseyear_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log",
benchmark: benchmark:
( (
BENCHMARKS + "add_existing_baseyear/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" BENCHMARKS
+ "add_existing_baseyear/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}"
) )
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"
@ -56,10 +58,12 @@ rule add_brownfield:
resources: resources:
mem_mb=10000, mem_mb=10000,
log: log:
LOGS + "add_brownfield_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log" LOGS
+ "add_brownfield_elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.log",
benchmark: benchmark:
( (
BENCHMARKS + "add_brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" BENCHMARKS
+ "add_brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}"
) )
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"
@ -94,7 +98,8 @@ rule solve_sector_network_myopic:
mem_mb=config["solving"]["mem"], mem_mb=config["solving"]["mem"],
benchmark: benchmark:
( (
BENCHMARKS + "solve_sector_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" BENCHMARKS
+ "solve_sector_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}"
) )
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"

View File

@ -29,7 +29,8 @@ rule solve_sector_network:
benchmark: benchmark:
( (
RESULTS RESULTS
+ BENCHMARKS + "solve_sector_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}" + BENCHMARKS
+ "solve_sector_network/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}"
) )
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"