-
Notifications
You must be signed in to change notification settings - Fork 7
/
Snakefile
200 lines (160 loc) · 5.21 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from shutil import copyfile, move
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
HTTP = HTTPRemoteProvider()
configfile: "config.yaml"
wildcard_constraints:
policy="[\-a-zA-Z0-9\.]+",
RDIR = os.path.join(config["results_dir"], config["run"])
RUN = config["run"]
# Technology data inputs
version = config["technology_data"]["version"]
year = config["technology_data"]["year"]
url = f"https://raw.githubusercontent.com/PyPSA/technology-data/{version}/outputs/costs_{year}.csv"
rule merge_all_plots:
input:
expand(
RDIR + "/plots/{year}/{zone}/{palette}/{policy}/SUMMARY.pdf",
**config["scenario"]
),
rule plot_summary_all_networks:
input:
expand(
RDIR + "/plots/{year}/{zone}/{palette}/{policy}/capacity.pdf",
**config["scenario"]
),
rule make_summary_all_networks:
input:
expand(
RDIR + "/csvs/{year}/{zone}/{palette}/{policy}/summary.csv",
**config["scenario"]
),
rule summarise_all_networks:
input:
expand(
RDIR + "/summaries/{year}/{zone}/{palette}/{policy}/{participation}.yaml",
**config["scenario"]
),
rule solve_all_networks:
input:
expand(
RDIR + "/networks/{year}/{zone}/{palette}/{policy}/{participation}.nc",
**config["scenario"]
),
rule merge_plots:
input:
plot=RDIR + "/plots/{year}/{zone}/{palette}/{policy}/capacity.pdf",
config=RDIR + "/configs/config.yaml",
output:
final=RDIR + "/plots/{year}/{zone}/{palette}/{policy}/SUMMARY.pdf",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/merge_plots.py"
rule plot_summary:
input:
grid_cfe=RDIR + "/networks/{year}/{zone}/{palette}/{policy}/0.csv",
networks=RDIR + "/networks/{year}/{zone}/{palette}/{policy}/0.nc",
summary=RDIR + "/csvs/{year}/{zone}/{palette}/{policy}/summary.csv",
config=RDIR + "/configs/config.yaml",
output:
plot=RDIR + "/plots/{year}/{zone}/{palette}/{policy}/capacity.pdf",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/plot_summary.py"
rule make_summary:
input:
expand(
RDIR + "/summaries/{year}/{zone}/{palette}/{policy}/{participation}.yaml",
**config["scenario"]
),
output:
summary=RDIR + "/csvs/{year}/{zone}/{palette}/{policy}/summary.csv",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/make_summary.py"
if config["solve_network"] == "solve":
rule solve_network:
input:
network=config[f'n_{year}_{config["time_sampling"]}'],
costs="input/costs_{year}.csv",
output:
network=RDIR
+ "/networks/{year}/{zone}/{palette}/{policy}/{participation}.nc",
grid_cfe=RDIR
+ "/networks/{year}/{zone}/{palette}/{policy}/{participation}.csv",
log:
solver=RDIR
+ "/logs/{year}/{zone}/{palette}/{policy}/{participation}_solver.log",
python=RDIR
+ "/logs/{year}/{zone}/{palette}/{policy}/{participation}_python.log",
memory=RDIR
+ "/logs/{year}/{zone}/{palette}/{policy}/{participation}_memory.log",
threads: 12
resources:
mem=8000,
script:
"scripts/solve_network.py"
rule summarise_network:
input:
network=RDIR + "/networks/{year}/{zone}/{palette}/{policy}/{participation}.nc",
grid_cfe=RDIR + "/networks/{year}/{zone}/{palette}/{policy}/{participation}.csv",
output:
yaml=RDIR + "/summaries/{year}/{zone}/{palette}/{policy}/{participation}.yaml",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/summarise_network.py"
rule copy_config:
output:
RDIR + "/configs/config.yaml",
threads: 1
resources:
mem_mb=1000,
script:
"scripts/copy_config.py"
if config.get("retrieve_cost_data", True):
rule retrieve_cost_data:
input:
HTTP.remote(url, keep_local=True),
output:
f"input/costs_{year}.csv",
# log: f"logs/{RDIR}retrieve_cost_data_{year}.log"
resources:
mem_mb=1000,
run:
move(input[0], output[0])
# additional rules for cluster communication -> not included into a workflow
rule sync_solution:
params:
cluster=f"iegor.riepin@gateway.hpc.tu-berlin.de:/scratch/iegor.riepin/247-cfe/results/{RUN}",
shell:
"""
rsync -uvarh --no-g {params.cluster} results/
"""
rule sync_plots:
params:
cluster="iegor.riepin@gateway.hpc.tu-berlin.de:/scratch/iegor.riepin/247-cfe/results/report/plots/",
shell:
"""
rsync -uvarh --no-g {params.cluster} report/plots
"""
# illustrate workflow
rule dag:
message:
"Plot dependency graph of the workflow."
output:
dot="workflow/dag.dot",
graph="workflow/graph.dot",
pdf="workflow/graph.pdf",
shell:
"""
snakemake --rulegraph > {output.dot}
sed -e '1,2d' < {output.dot} > {output.graph}
dot -Tpdf -o {output.pdf} {output.graph}
"""