update solve smk files to properly consider scenanrios

This commit is contained in:
Fabian 2023-09-22 13:58:08 +02:00
parent c7e6d36014
commit f96c2d0589
5 changed files with 44 additions and 37 deletions

View File

@ -10,7 +10,10 @@ def get_config(config, keys, default=None):
"""Retrieve a nested value from a dictionary using a tuple of keys.""" """Retrieve a nested value from a dictionary using a tuple of keys."""
value = config value = config
for key in keys: for key in keys:
value = value.get(key, default) if isinstance(value, list):
value = value[key]
else:
value = value.get(key, default)
if value == default: if value == default:
return default return default
return value return value
@ -40,7 +43,7 @@ def static_getter(wildcards, keys, default):
def dynamic_getter(wildcards, keys, default): def dynamic_getter(wildcards, keys, default):
"""Getter function for dynamic config values based on scenario.""" """Getter function for dynamic config values based on scenario."""
if "run" not in wildcards: if "run" not in wildcards.keys():
return get_config(config, keys, default) return get_config(config, keys, default)
scenario_name = wildcards.run scenario_name = wildcards.run
if scenario_name not in scenarios: if scenario_name not in scenarios:

View File

@ -5,11 +5,11 @@
rule solve_network: rule solve_network:
params: params:
solving=config["solving"], solving=config_provider("solving"),
foresight=config["foresight"], foresight=config_provider("foresight"),
planning_horizons=config["scenario"]["planning_horizons"], planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config["sector"].get( co2_sequestration_potential=config_provider(
"co2_sequestration_potential", 200 "sector", "co2_sequestration_potential", default=200
), ),
input: input:
network=resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"), network=resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"),
@ -27,7 +27,7 @@ rule solve_network:
threads: 4 threads: 4
resources: resources:
mem_mb=memory, mem_mb=memory,
walltime=config["solving"].get("walltime", "12:00:00"), walltime=config_provider("solving", "walltime", default="12:00:00"),
shadow: shadow:
"minimal" "minimal"
conda: conda:
@ -38,7 +38,7 @@ rule solve_network:
rule solve_operations_network: rule solve_operations_network:
params: params:
options=config["solving"]["options"], options=config_provider("solving", "options"),
input: input:
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
output: output:
@ -58,7 +58,7 @@ rule solve_operations_network:
threads: 4 threads: 4
resources: resources:
mem_mb=(lambda w: 10000 + 372 * int(w.clusters)), mem_mb=(lambda w: 10000 + 372 * int(w.clusters)),
walltime=config["solving"].get("walltime", "12:00:00"), walltime=config_provider("solving", "walltime", default="12:00:00"),
shadow: shadow:
"minimal" "minimal"
conda: conda:

View File

@ -5,10 +5,10 @@
rule add_existing_baseyear: rule add_existing_baseyear:
params: params:
baseyear=config["scenario"]["planning_horizons"][0], baseyear=config_provider("scenario", "planning_horizons", 0),
sector=config["sector"], sector=config_provider("sector"),
existing_capacities=config["existing_capacities"], existing_capacities=config_provider("existing_capacities"),
costs=config["costs"], costs=config_provider("costs"),
input: input:
network=RESULTS network=RESULTS
+ "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
@ -16,7 +16,9 @@ rule add_existing_baseyear:
busmap_s=resources("busmap_elec_s{simpl}.csv"), busmap_s=resources("busmap_elec_s{simpl}.csv"),
busmap=resources("busmap_elec_s{simpl}_{clusters}.csv"), busmap=resources("busmap_elec_s{simpl}_{clusters}.csv"),
clustered_pop_layout=resources("pop_layout_elec_s{simpl}_{clusters}.csv"), clustered_pop_layout=resources("pop_layout_elec_s{simpl}_{clusters}.csv"),
costs="data/costs_{}.csv".format(config["scenario"]["planning_horizons"][0]), costs=lambda w: "data/costs_{}.csv".format(
config_provider("scenario", "planning_horizons", 0)(w)
),
cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"), cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"),
cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"), cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"),
existing_heating="data/existing_infrastructure/existing_heating_raw.csv", existing_heating="data/existing_infrastructure/existing_heating_raw.csv",
@ -27,7 +29,7 @@ rule add_existing_baseyear:
RESULTS RESULTS
+ "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
wildcard_constraints: wildcard_constraints:
planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear planning_horizons=config_provider("scenario", "planning_horizons", 0), #only applies to baseyear
threads: 1 threads: 1
resources: resources:
mem_mb=2000, mem_mb=2000,
@ -47,9 +49,11 @@ rule add_existing_baseyear:
rule add_brownfield: rule add_brownfield:
params: params:
H2_retrofit=config["sector"]["H2_retrofit"], H2_retrofit=config_provider("sector", "H2_retrofit"),
H2_retrofit_capacity_per_CH4=config["sector"]["H2_retrofit_capacity_per_CH4"], H2_retrofit_capacity_per_CH4=config_provider(
threshold_capacity=config["existing_capacities"]["threshold_capacity"], "sector", "H2_retrofit_capacity_per_CH4"
),
threshold_capacity=config_provider("existing_capacities", " threshold_capacity"),
input: input:
network=RESULTS network=RESULTS
+ "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
@ -82,11 +86,11 @@ ruleorder: add_existing_baseyear > add_brownfield
rule solve_sector_network_myopic: rule solve_sector_network_myopic:
params: params:
solving=config["solving"], solving=config_provider("solving"),
foresight=config["foresight"], foresight=config_provider("foresight"),
planning_horizons=config["scenario"]["planning_horizons"], planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config["sector"].get( co2_sequestration_potential=config_provider(
"co2_sequestration_potential", 200 "sector", "co2_sequestration_potential", default=200
), ),
input: input:
network=RESULTS network=RESULTS
@ -105,8 +109,8 @@ rule solve_sector_network_myopic:
+ "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log", + "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log",
threads: 4 threads: 4
resources: resources:
mem_mb=config["solving"]["mem"], mem_mb=config_provider("solving", "mem"),
walltime=config["solving"].get("walltime", "12:00:00"), walltime=config_provider("solving", "walltime", default="12:00:00"),
benchmark: benchmark:
( (
BENCHMARKS BENCHMARKS

View File

@ -5,11 +5,11 @@
rule solve_sector_network: rule solve_sector_network:
params: params:
solving=config["solving"], solving=config_provider("solving"),
foresight=config["foresight"], foresight=config_provider("foresight"),
planning_horizons=config["scenario"]["planning_horizons"], planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config["sector"].get( co2_sequestration_potential=config_provider(
"co2_sequestration_potential", 200 "sector", "co2_sequestration_potential", default=200
), ),
input: input:
network=RESULTS network=RESULTS
@ -27,8 +27,8 @@ rule solve_sector_network:
+ "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log", + "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log",
threads: config["solving"]["solver"].get("threads", 4) threads: config["solving"]["solver"].get("threads", 4)
resources: resources:
mem_mb=config["solving"]["mem"], mem_mb=config_provider("solving", "mem"),
walltime=config["solving"].get("walltime", "12:00:00"), walltime=config_provider("solving", "walltime", default="12:00:00"),
benchmark: benchmark:
( (
BENCHMARKS BENCHMARKS

View File

@ -137,10 +137,10 @@ def add_co2_sequestration_limit(n, limit=200):
n.add( n.add(
"GlobalConstraint", "GlobalConstraint",
"co2_sequestration_limit", "co2_sequestration_limit",
sense="<=", sense=">=",
constant=limit, constant=-limit,
type="primary_energy", type="operational_limit",
carrier_attribute="co2_absorptions", carrier_attribute="co2 sequestered",
) )