Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include parametric uncertainty #2

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from itertools import product
from numpy import unique

configfile: "config.yaml"

wildcard_constraints:
Expand Down Expand Up @@ -49,8 +52,47 @@ rule solve_all_bases:
# based on the variables of the original problem the search directions
# of the MGA iterations are inferred.

def get_wildcard_sets(config):
wildcard_sets = [
{**config['scenario-totals'], **config['alternative-totals']}
]
if config['include_groups']:
wildcard_sets.append(
{**config['scenario-groups'], **config['alternative-groups']}
)
if config['include_hypercube']:
wildcard_sets.append(
{**config['scenario-hypercube'], **config['alternative-hypercube']}
)
return wildcard_sets


def add_cost_opts(wildcards_opts):
if "cost-uncertainty" not in config.keys():
return wildcards_opts
factors = config["cost-uncertainty"]
carrier, values = zip(*factors.items())
cost_sets = [dict(zip(carrier, v)) for v in product(*values)]

new_opts = []
for opts in wildcards_opts:
for cost_set in cost_sets:
cost_opts = "-".join([f"{c}+{v}" for c, v in cost_set.items()])
new_opts.append(f"{opts}-{cost_opts}")

return new_opts


def get_checkpoint_opts(config):
wcs_set = get_wildcard_sets(config)
opts = []
for wcs in wcs_set:
opts.extend(add_cost_opts(wcs["opts"]))
return unique(opts)


checkpoint generate_list_of_alternatives:
input: "results/networks/elec_s_{clusters}_ec_lcopt_{opts}.nc"
input: expand("results/networks/elec_s_{clusters}_ec_lcopt_{opts}.nc", opts=get_checkpoint_opts(config), allow_missing=True)
output: "results/alternatives/elec_s_{clusters}_ec_lcopt_{opts}_cat-{category}.txt"
script: "scripts/generate_list_of_alternatives.py"

Expand All @@ -67,28 +109,14 @@ rule generate_alternative:
script: "scripts/generate_alternative.py"


def get_wildcard_sets(config):
wildcard_sets = [
{**config['scenario-totals'], **config['alternative-totals']}
]
if config['include_groups']:
wildcard_sets.append(
{**config['scenario-groups'], **config['alternative-groups']}
)
if config['include_hypercube']:
wildcard_sets.append(
{**config['scenario-hypercube'], **config['alternative-hypercube']}
)
return wildcard_sets


def input_generate_clusters_alternatives(w):
wildcard_sets = get_wildcard_sets(config)
input = []
for wildcards in wildcard_sets:
for clusters in wildcards["clusters"]:
if int(clusters) == int(w.clusters):
for opts in wildcards['opts']:
wildcards_opts = add_cost_opts(wildcards["opts"])
for opts in wildcards_opts:
for epsilon in wildcards['epsilon']:
for category in wildcards['category']:
alternatives = checkpoints.generate_list_of_alternatives.get(
Expand Down
19 changes: 13 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
logging_level: INFO

scenario-totals:
clusters: [100]
opts: [2H]
clusters: [37]
opts: [4H]

alternative-totals:
epsilon: [0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]
category: ['totals']

scenario-groups:
clusters: [100]
opts: [2H]
clusters: []
opts: []

alternative-groups:
epsilon: [0.05]
category: ['groups']
epsilon: []
category: []

cost-uncertainty:
onwind: [0.5, 1.0, 1.5]
offwind: [0.5, 1.0, 1.5]
solar: [0.5 ,1.0, 1.5]
H2: [0.5, 1.0, 1.5]
battery: [0.5, 1.0, 1.5]

solving:
options:
Expand Down
5 changes: 5 additions & 0 deletions cost-uncertainty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
onwind: [0.5,1.0,1.5]
offwind: [0.5,1.0,1.5]
solar: [0.5,1.0,1.5]
H2: [0.5,1.0,1.5]
battery: [0.5,1.0,1.5]
2 changes: 1 addition & 1 deletion pypsa-eur
Submodule pypsa-eur updated 107 files
Loading