diff --git a/rules/solve_electricity.smk b/rules/solve_electricity.smk index 389687a0f..e2dbe42ef 100644 --- a/rules/solve_electricity.smk +++ b/rules/solve_electricity.smk @@ -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: diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 99f7b5751..2cff060d9 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -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): @@ -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) @@ -1181,4 +1185,4 @@ def solve_network(n, config, solving, **kwargs): default_flow_style=False, allow_unicode=True, sort_keys=False, - ) + ) \ No newline at end of file diff --git a/scripts/solve_operations_network.py b/scripts/solve_operations_network.py index bd4ce7aaa..9fc035867 100644 --- a/scripts/solve_operations_network.py +++ b/scripts/solve_operations_network.py @@ -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]) \ No newline at end of file