Skip to content

Commit

Permalink
Added parallel workflow using glpk
Browse files Browse the repository at this point in the history
  • Loading branch information
willu47 committed Sep 13, 2019
1 parent 46623fa commit fb3365f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.snakemake
processed_data/*
results/*
4 changes: 4 additions & 0 deletions env/dag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
channels:
- anaconda
dependencies:
- graphviz
5 changes: 5 additions & 0 deletions env/osemosys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
channels:
- conda-forge
- defaults
dependencies:
- glpk
8 changes: 8 additions & 0 deletions scripts/osemosys_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
MODELRUN=$1
RESULTS="results\/$MODELRUN"
echo $RESULTS
mkdir results/$MODELRUN
mkdir processed_data/$MODELRUN
cat model/model.txt > processed_data/$MODELRUN/osemosys.txt
sed -i '' "s/res\/csv/$RESULTS/g" processed_data/$MODELRUN/osemosys.txt
35 changes: 35 additions & 0 deletions snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
MODELRUNS = ['bau', 'currentpolicies', 'sdg7']

rule all:
input: ["results/{modelrun}/csv/AccumulatedNewCapacity.csv".format(modelrun=x) for x in MODELRUNS]
message: "Running pipeline to generate the files '{input}'"

rule prepare_model:
output: "processed_data/{modelrun}/osemosys.txt"
params: modelrun="{modelrun}"
shell:
"bash scripts/osemosys_run.sh {params.modelrun}"

rule solve:
input: data="data/data_{modelrun}.txt", model="processed_data/{modelrun}/osemosys.txt"
output: results="results/{modelrun}.sol",csv="results/{modelrun}/csv/AccumulatedNewCapacity.csv"
log: "processed_data/{modelrun}/glpsol.log"
conda: "env/osemosys.yaml"
shell:
"glpsol -d {input.data} -m {input.model} -o {output.results} > {log}"

rule clean:
shell:
"rm -f processed_data/*/*.pdf processed_data/*/*.sol processed_data/*/*.csv *.png"

rule make_dag:
output: pipe("dag.txt")
shell:
"snakemake --dag > {output}"

rule plot_dag:
input: "dag.txt"
output: "dag.png"
conda: "env/dag.yaml"
shell:
"dot -Tpng {input} > dag.png && open dag.png"

0 comments on commit fb3365f

Please sign in to comment.