2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2020-05-29 07:50:55 +00:00
|
|
|
|
2019-11-28 15:33:33 +00:00
|
|
|
from os.path import normpath, exists
|
2023-03-08 17:43:52 +00:00
|
|
|
from shutil import copyfile, move, rmtree
|
2019-11-28 15:33:33 +00:00
|
|
|
|
2021-04-27 12:54:54 +00:00
|
|
|
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
|
2023-03-06 18:44:57 +00:00
|
|
|
|
2021-04-27 12:54:54 +00:00
|
|
|
HTTP = HTTPRemoteProvider()
|
|
|
|
|
2023-03-08 16:44:25 +00:00
|
|
|
from snakemake.utils import min_version
|
|
|
|
|
2023-03-08 18:28:00 +00:00
|
|
|
min_version("7.7")
|
2023-03-08 16:44:25 +00:00
|
|
|
|
|
|
|
|
2023-04-21 09:05:18 +00:00
|
|
|
if not exists("config/config.yaml"):
|
|
|
|
copyfile("config/config.default.yaml", "config/config.yaml")
|
2019-11-22 14:13:46 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2023-06-29 17:22:33 +00:00
|
|
|
configfile: "config/config.yaml"
|
2017-12-18 19:34:15 +00:00
|
|
|
|
2023-03-07 17:24:47 +00:00
|
|
|
|
2023-03-07 17:11:59 +00:00
|
|
|
COSTS = f"data/costs_{config['costs']['year']}.csv"
|
|
|
|
ATLITE_NPROCESSES = config["atlite"].get("nprocesses", 4)
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2022-09-08 07:52:00 +00:00
|
|
|
run = config.get("run", {})
|
2022-09-13 07:47:11 +00:00
|
|
|
RDIR = run["name"] + "/" if run.get("name") else ""
|
2022-09-13 12:51:36 +00:00
|
|
|
CDIR = RDIR if not run.get("shared_cutouts") else ""
|
2022-09-08 07:52:00 +00:00
|
|
|
|
2023-03-07 17:11:59 +00:00
|
|
|
LOGS = "logs/" + RDIR
|
|
|
|
BENCHMARKS = "benchmarks/" + RDIR
|
2023-03-07 19:37:47 +00:00
|
|
|
RESOURCES = "resources/" + RDIR if not run.get("shared_resources") else "resources/"
|
2023-03-07 17:11:59 +00:00
|
|
|
RESULTS = "results/" + RDIR
|
2018-10-25 14:43:24 +00:00
|
|
|
|
2023-03-08 18:22:29 +00:00
|
|
|
|
|
|
|
localrules:
|
|
|
|
purge,
|
|
|
|
|
2022-09-08 07:52:00 +00:00
|
|
|
|
2017-12-18 19:34:15 +00:00
|
|
|
wildcard_constraints:
|
2023-03-06 16:41:09 +00:00
|
|
|
simpl="[a-zA-Z0-9]*",
|
2023-04-27 08:10:30 +00:00
|
|
|
clusters="[0-9]+(m|c)?|all",
|
2023-03-06 16:41:09 +00:00
|
|
|
ll="(v|c)([0-9\.]+|opt)",
|
2019-06-18 09:50:54 +00:00
|
|
|
opts="[-+a-zA-Z0-9\.]*",
|
2023-03-06 18:44:57 +00:00
|
|
|
sector_opts="[-+a-zA-Z0-9\.\s]*",
|
2017-12-18 19:34:15 +00:00
|
|
|
|
2023-03-08 18:22:29 +00:00
|
|
|
|
2023-03-08 18:22:00 +00:00
|
|
|
include: "rules/common.smk"
|
2023-03-08 16:29:01 +00:00
|
|
|
include: "rules/collect.smk"
|
|
|
|
include: "rules/retrieve.smk"
|
|
|
|
include: "rules/build_electricity.smk"
|
|
|
|
include: "rules/build_sector.smk"
|
|
|
|
include: "rules/solve_electricity.smk"
|
|
|
|
include: "rules/postprocess.smk"
|
2023-07-03 15:14:50 +00:00
|
|
|
include: "rules/validate.smk"
|
2021-07-01 18:09:04 +00:00
|
|
|
|
2020-07-08 14:34:15 +00:00
|
|
|
|
|
|
|
if config["foresight"] == "overnight":
|
2020-07-30 06:27:33 +00:00
|
|
|
|
2023-03-08 16:29:01 +00:00
|
|
|
include: "rules/solve_overnight.smk"
|
2020-07-30 06:27:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
if config["foresight"] == "myopic":
|
2020-07-07 16:30:37 +00:00
|
|
|
|
2023-03-08 16:29:01 +00:00
|
|
|
include: "rules/solve_myopic.smk"
|
2023-03-08 17:15:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
rule purge:
|
2023-03-08 18:22:29 +00:00
|
|
|
message:
|
2023-03-15 16:00:06 +00:00
|
|
|
"Purging generated resources, results and docs. Downloads are kept."
|
2023-03-08 17:43:52 +00:00
|
|
|
run:
|
2023-03-09 10:04:41 +00:00
|
|
|
rmtree("resources/", ignore_errors=True)
|
|
|
|
rmtree("results/", ignore_errors=True)
|
2023-03-15 16:00:06 +00:00
|
|
|
rmtree("doc/_build", ignore_errors=True)
|
2023-03-08 17:43:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
rule dag:
|
2023-03-08 18:22:29 +00:00
|
|
|
message:
|
|
|
|
"Creating DAG of workflow."
|
2023-03-08 17:45:11 +00:00
|
|
|
output:
|
|
|
|
dot=RESOURCES + "dag.dot",
|
|
|
|
pdf=RESOURCES + "dag.pdf",
|
2023-03-08 18:22:29 +00:00
|
|
|
png=RESOURCES + "dag.png",
|
|
|
|
conda:
|
|
|
|
"envs/environment.yaml"
|
2023-03-08 17:45:11 +00:00
|
|
|
shell:
|
2023-03-08 17:45:32 +00:00
|
|
|
"""
|
|
|
|
snakemake --rulegraph all | sed -n "/digraph/,\$p" > {output.dot}
|
|
|
|
dot -Tpdf -o {output.pdf} {output.dot}
|
|
|
|
dot -Tpng -o {output.png} {output.dot}
|
2023-03-08 18:22:29 +00:00
|
|
|
"""
|
2023-03-09 12:28:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
rule doc:
|
|
|
|
message:
|
|
|
|
"Build documentation."
|
|
|
|
output:
|
2023-03-09 12:29:13 +00:00
|
|
|
directory("doc/_build"),
|
2023-03-09 12:28:42 +00:00
|
|
|
shell:
|
|
|
|
"make -C doc html"
|
2023-07-03 15:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
rule sync:
|
|
|
|
params:
|
|
|
|
cluster=f"{config['remote']['ssh']}:{config['remote']['path']}",
|
|
|
|
shell:
|
|
|
|
"""
|
|
|
|
rsync -uvarh --no-g --ignore-missing-args --files-from=.sync-send . {params.cluster}
|
2023-07-05 09:07:36 +00:00
|
|
|
rsync -uvarh --no-g {params.cluster}/results results
|
|
|
|
rsync -uvarh --no-g {params.cluster}/logs logs
|
2023-07-03 15:14:50 +00:00
|
|
|
"""
|