From 3e32dbccb5090e07803fd648ab348d00a7cd0cd0 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Wed, 24 Jan 2024 11:23:56 +0100 Subject: [PATCH] Add support for the linopy `io_api` option --- config/config.default.yaml | 1 + doc/configtables/solving.csv | 1 + doc/release_notes.rst | 2 ++ scripts/solve_network.py | 1 + 4 files changed, 5 insertions(+) diff --git a/config/config.default.yaml b/config/config.default.yaml index 98595d20..255e3869 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -687,6 +687,7 @@ solving: rolling_horizon: false seed: 123 custom_extra_functionality: "../data/custom_extra_functionality.py" + # io_api: "direct" # Increases performance but only supported for the highs and gurobi solvers # options that go into the optimize function track_iterations: false min_iterations: 4 diff --git a/doc/configtables/solving.csv b/doc/configtables/solving.csv index 6eff10ae..406fd1f9 100644 --- a/doc/configtables/solving.csv +++ b/doc/configtables/solving.csv @@ -7,6 +7,7 @@ options,,, -- rolling_horizon,bool,"{'true','false'}","Whether to optimize the network in a rolling horizon manner, where the snapshot range is split into slices of size `horizon` which are solved consecutively." -- seed,--,int,Random seed for increased deterministic behaviour. -- custom_extra_functionality,--,str,Path to a Python file with custom extra functionality code to be injected into the solving rules of the workflow relative to ``rules`` directory. +-- io_api,string,"{'lp','mps','direct'}",Passed to linopy and determines the API used to communicate with the solver. With the ``'lp'`` and ``'mps'`` options linopy passes a file to the solver; with the ``'direct'`` option (only supported for HIGHS and Gurobi) linopy uses an in-memory python API resulting in better performance. -- track_iterations,bool,"{'true','false'}",Flag whether to store the intermediate branch capacities and objective function values are recorded for each iteration in ``network.lines['s_nom_opt_X']`` (where ``X`` labels the iteration) -- min_iterations,--,int,Minimum number of solving iterations in between which resistance and reactence (``x/r``) are updated for branches according to ``s_nom_opt`` of the previous run. -- max_iterations,--,int,Maximum number of solving iterations in between which resistance and reactence (``x/r``) are updated for branches according to ``s_nom_opt`` of the previous run. diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 914617d4..b55e8ac7 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -33,6 +33,8 @@ Upcoming Release * Bugfix: Correctly read out number of solver threads from configuration file. +* Add support for the linopy ``io_api`` option; set to ``"direct"`` to increase model reading and writing performance for the highs and gurobi solvers. + PyPSA-Eur 0.9.0 (5th January 2024) ================================== diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 5d2701bb..9fc41555 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -890,6 +890,7 @@ def solve_network(n, config, solving, opts="", **kwargs): "linearized_unit_commitment", False ) kwargs["assign_all_duals"] = cf_solving.get("assign_all_duals", False) + kwargs["io_api"] = cf_solving.get("io_api", None) if kwargs["solver_name"] == "gurobi": logging.getLogger("gurobipy").setLevel(logging.CRITICAL)