2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2020-05-29 07:50:55 +00:00
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
2019-08-11 20:34:18 +00:00
|
|
|
Solves linear optimal dispatch in hourly resolution using the capacities of
|
2019-08-13 15:52:33 +00:00
|
|
|
previous capacity expansion in rule :mod:`solve_network`.
|
2019-08-11 09:40:47 +00:00
|
|
|
|
|
|
|
Relevant Settings
|
|
|
|
-----------------
|
|
|
|
|
2019-08-11 11:17:36 +00:00
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
solving:
|
|
|
|
tmpdir:
|
|
|
|
options:
|
|
|
|
formulation:
|
|
|
|
clip_p_max_pu:
|
|
|
|
load_shedding:
|
|
|
|
noisy_costs:
|
|
|
|
nhours:
|
|
|
|
min_iterations:
|
|
|
|
max_iterations:
|
|
|
|
solver:
|
|
|
|
name:
|
2019-08-12 21:48:16 +00:00
|
|
|
(solveroptions):
|
2019-08-11 11:17:36 +00:00
|
|
|
|
2019-12-09 20:29:15 +00:00
|
|
|
.. seealso::
|
2019-08-13 08:03:46 +00:00
|
|
|
Documentation of the configuration file ``config.yaml`` at
|
|
|
|
:ref:`solving_cf`
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Inputs
|
|
|
|
------
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
- ``networks/elec_s{simpl}_{clusters}.nc``: confer :ref:`cluster`
|
|
|
|
- ``results/networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc``: confer :ref:`solve`
|
2019-08-11 20:34:18 +00:00
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
- ``results/networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_op.nc``: Solved PyPSA network for optimal dispatch including optimisation results
|
2019-08-11 20:34:18 +00:00
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Description
|
|
|
|
-----------
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
|
2018-03-13 09:47:47 +00:00
|
|
|
import numpy as np
|
2020-02-10 11:06:43 +00:00
|
|
|
import pypsa
|
2023-03-09 21:51:56 +00:00
|
|
|
from _helpers import (
|
|
|
|
configure_logging,
|
|
|
|
override_component_attrs,
|
|
|
|
update_config_with_sector_opts,
|
|
|
|
)
|
2020-02-10 11:06:43 +00:00
|
|
|
from solve_network import prepare_network, solve_network
|
2018-03-13 09:47:47 +00:00
|
|
|
from vresutils.benchmark import memory_logger
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2018-02-19 09:17:49 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
2019-12-09 20:29:15 +00:00
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2022-06-30 06:39:03 +00:00
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"solve_operations_network",
|
2023-03-09 21:51:56 +00:00
|
|
|
configfiles="test/config.test1.yaml",
|
2020-02-10 11:06:43 +00:00
|
|
|
simpl="",
|
2023-03-09 21:51:56 +00:00
|
|
|
opts="",
|
2020-02-10 11:06:43 +00:00
|
|
|
clusters="5",
|
2023-03-09 21:51:56 +00:00
|
|
|
ll="v1.5",
|
|
|
|
sector_opts="",
|
|
|
|
planning_horizons="",
|
2020-02-10 11:06:43 +00:00
|
|
|
)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
configure_logging(snakemake)
|
|
|
|
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
opts = (snakemake.wildcards.opts + "-" + snakemake.wildcards.sector_opts).split("-")
|
|
|
|
opts = [o for o in opts if o != ""]
|
|
|
|
solve_opts = snakemake.config["solving"]["options"]
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2023-03-09 21:51:56 +00:00
|
|
|
np.random.seed(solve_opts.get("seed", 123))
|
2022-09-16 13:04:04 +00:00
|
|
|
|
2022-01-24 18:48:26 +00:00
|
|
|
fn = getattr(snakemake.log, "memory", None)
|
2020-12-03 18:50:53 +00:00
|
|
|
with memory_logger(filename=fn, interval=30.0) as mem:
|
2023-03-09 21:51:56 +00:00
|
|
|
if "overrides" in snakemake.input:
|
|
|
|
overrides = override_component_attrs(snakemake.input.overrides)
|
|
|
|
n = pypsa.Network(
|
|
|
|
snakemake.input.network, override_component_attrs=overrides
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
n = pypsa.Network(snakemake.input.network)
|
|
|
|
|
|
|
|
n.optimize.fix_optimal_capacities()
|
|
|
|
n = prepare_network(n, solve_opts, config=snakemake.config)
|
2022-01-24 18:48:26 +00:00
|
|
|
n = solve_network(
|
2023-03-09 21:51:56 +00:00
|
|
|
n, config=snakemake.config, opts=opts, log_fn=snakemake.log.solver
|
2022-01-24 18:48:26 +00:00
|
|
|
)
|
2023-03-09 21:51:56 +00:00
|
|
|
|
2022-06-30 06:39:03 +00:00
|
|
|
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
2022-01-24 18:48:26 +00:00
|
|
|
n.export_to_netcdf(snakemake.output[0])
|
2018-02-19 09:17:49 +00:00
|
|
|
|
2018-03-13 09:47:47 +00:00
|
|
|
logger.info("Maximum memory usage: {}".format(mem.mem_usage))
|