Skip to content

Commit

Permalink
fix solve_operations_network
Browse files Browse the repository at this point in the history
  • Loading branch information
danielelerede-oet committed Aug 21, 2024
1 parent e273f4e commit f46fdee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions rules/solve_electricity.smk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ rule solve_network:
rule solve_operations_network:
params:
options=config_provider("solving", "options"),
solving=config_provider("solving"),
foresight=config_provider("foresight"),
planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config_provider(
"sector", "co2_sequestration_potential", default=200
),
custom_extra_functionality=input_custom_extra_functionality,
input:
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
output:
Expand Down
12 changes: 8 additions & 4 deletions scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,14 @@ def extra_functionality(n, snapshots):
if config["sector"]["enhanced_geothermal"]["enable"]:
add_flexible_egs_constraint(n)

if snakemake.params.custom_extra_functionality:
source_path = snakemake.params.custom_extra_functionality
if n.snakemake.params.custom_extra_functionality:
source_path = n.snakemake.params.custom_extra_functionality
assert os.path.exists(source_path), f"{source_path} does not exist"
sys.path.append(os.path.dirname(source_path))
module_name = os.path.splitext(os.path.basename(source_path))[0]
module = importlib.import_module(module_name)
custom_extra_functionality = getattr(module, module_name)
custom_extra_functionality(n, snapshots, snakemake)
custom_extra_functionality(n, snapshots, n.snakemake)


def solve_network(n, config, solving, **kwargs):
Expand Down Expand Up @@ -1093,6 +1093,10 @@ def solve_network(n, config, solving, **kwargs):

# add to network for extra_functionality
n.config = config
if "snakemake" in kwargs:
n.snakemake = kwargs.pop("snakemake")
else:
n.snakemake=snakemake

if rolling_horizon and snakemake.rule == "solve_operations_network":
kwargs["horizon"] = cf_solving.get("horizon", 365)
Expand Down Expand Up @@ -1181,4 +1185,4 @@ def solve_network(n, config, solving, **kwargs):
default_flow_style=False,
allow_unicode=True,
sort_keys=False,
)
)
4 changes: 2 additions & 2 deletions scripts/solve_operations_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

n.optimize.fix_optimal_capacities()
n = prepare_network(n, solve_opts, config=snakemake.config)
n = solve_network(n, config=snakemake.config, log_fn=snakemake.log.solver)
n = solve_network(n, config=snakemake.config, solving=snakemake.params.solving, log_fn=snakemake.log.solver, snakemake=snakemake)

n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
n.export_to_netcdf(snakemake.output[0])
n.export_to_netcdf(snakemake.output[0])

0 comments on commit f46fdee

Please sign in to comment.