-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
176 lines (143 loc) · 4.54 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
configfile: "config.yaml"
wildcard_constraints:
policy="[\-a-zA-Z0-9\.]+",
RDIR = os.path.join(config["results_dir"], config["run"])
CDIR = config["costs_dir"]
RUN = config["run"]
rule merge_all_plots:
input:
expand(
RDIR + "/plots/{participation}/{year}/{zone}/{palette}/SUMMARY.pdf",
**config["scenario"]
),
rule plot_summary_all_networks:
input:
expand(
RDIR + "/plots/{participation}/{year}/{zone}/{palette}/used.pdf",
**config["scenario"]
),
rule make_summary_all_networks:
input:
expand(
RDIR + "/csvs/{participation}/{year}/{zone}/{palette}/summary.csv",
**config["scenario"]
),
rule summarise_all_networks:
input:
expand(
RDIR + "/summaries/{participation}/{year}/{zone}/{palette}/{policy}.yaml",
**config["scenario"]
),
rule solve_all_networks:
input:
expand(
RDIR + "/networks/{participation}/{year}/{zone}/{palette}/{policy}.nc",
**config["scenario"]
),
rule merge_plots:
input:
used=RDIR + "/plots/{participation}/{year}/{zone}/{palette}/used.pdf",
config=RDIR + "/configs/config.yaml",
output:
final=RDIR + "/plots/{participation}/{year}/{zone}/{palette}/SUMMARY.pdf",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/merge_plots.py"
rule plot_summary:
input:
summary=RDIR + "/csvs/{participation}/{year}/{zone}/{palette}/summary.csv",
config=RDIR + "/configs/config.yaml",
output:
used=RDIR + "/plots/{participation}/{year}/{zone}/{palette}/used.pdf",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/plot_summary.py"
rule make_summary:
input:
expand(
RDIR + "/summaries/{participation}/{year}/{zone}/{palette}/{policy}.yaml",
**config["scenario"]
),
output:
summary=RDIR + "/csvs/{participation}/{year}/{zone}/{palette}/summary.csv",
threads: 2
resources:
mem_mb=2000,
script:
"scripts/make_summary.py"
if config["solve_network"] == "solve":
rule solve_network:
input:
network2030=config["n_2030"],
network2025=config["n_2025"],
costs2030=CDIR + "/costs_2030.csv",
costs2025=CDIR + "/costs_2025.csv",
output:
network=RDIR
+ "/networks/{participation}/{year}/{zone}/{palette}/{policy}.nc",
grid_cfe=RDIR
+ "/networks/{participation}/{year}/{zone}/{palette}/{policy}.csv",
log:
solver=RDIR
+ "/logs/{participation}/{year}/{zone}/{palette}/{policy}_solver.log",
python=RDIR
+ "/logs/{participation}/{year}/{zone}/{palette}/{policy}_python.log",
memory=RDIR
+ "/logs/{participation}/{year}/{zone}/{palette}/{policy}_memory.log",
threads: 12
resources:
mem=8000,
script:
"scripts/solve_network.py"
rule summarise_network:
input:
network=RDIR + "/networks/{participation}/{year}/{zone}/{palette}/{policy}.nc",
grid_cfe=RDIR + "/networks/{participation}/{year}/{zone}/{palette}/{policy}.csv",
output:
yaml=RDIR + "/summaries/{participation}/{year}/{zone}/{palette}/{policy}.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"
# additional rules for cluster communication -> not included into a workflow
rule sync_solution:
params:
cluster=f"[email protected]:/scratch/iegor.riepin/247-procurement-paper/results/{RUN}",
shell:
"""
rsync -uvarh --no-g {params.cluster} results/
"""
rule sync_plots:
params:
cluster=f"[email protected]:/scratch/iegor.riepin/247-procurement-paper/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}
"""