Skip to content

Commit

Permalink
update cli for highs
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed May 2, 2024
1 parent 188db0c commit 73d2a45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
18 changes: 8 additions & 10 deletions src/otoole/cli.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
"""Provides a command line interface to the ``otoole`` package
The key functions are **convert**, **cplex** and **viz**.
The key functions are **convert**, **results**, **validate**, and **viz**.
The ``convert`` command allows convertion of multiple different OSeMOSYS input formats
including from/to csv, an AMPL format datafile, a folder of
CSVs, an Excel workbook with one tab per parameter, an SQLite database
The ``cplex`` command provides access to scripts which transform and process a CPLEX
solution file into a format which is more readily processed - either to CBC or CSV
format.
The ``results`` command allows conversion of a results solution file into processed
tabular result file(s). Can process results from ``cplex``, ``gurobi``, ``highs``,
``cbc``, and ``glpk``.
The ``validate`` command checks the technology and fuel names
against a standard or user defined configuration file.
The **viz** command allows you to produce a Reference Energy System diagram
The ``viz`` command allows you to produce a Reference Energy System diagram
Example
-------
Ask for help on the command line::
>>> $ otoole --help
usage: otoole [-h] [--verbose] [--version] {convert,cplex,validate,viz} ...
usage: otoole [-h] [--verbose] [--version] {convert,results,validate,viz} ...
otoole: Python toolkit of OSeMOSYS users
Expand Down Expand Up @@ -167,16 +167,14 @@ def get_parser():
result_parser.add_argument(
"from_format",
help="Result data format to convert from",
choices=sorted(["cbc", "cplex", "gurobi", "glpk"]),
choices=sorted(["cbc", "cplex", "gurobi", "glpk", "highs"]),
)
result_parser.add_argument(
"to_format",
help="Result data format to convert to",
choices=sorted(["csv"]),
)
result_parser.add_argument(
"from_path", help="Path to file or folder to convert from"
)
result_parser.add_argument("from_path", help="Path to solver solution file")
result_parser.add_argument("to_path", help="Path to file or folder to convert to")

result_parser.add_argument(
Expand Down
25 changes: 17 additions & 8 deletions src/otoole/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
from otoole.exceptions import OtooleError
from otoole.input import Context, ReadStrategy, WriteStrategy
from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel
from otoole.results.results import ReadCbc, ReadCplex, ReadGlpk, ReadGurobi, ReadResults
from otoole.results.results import (
ReadCbc,
ReadCplex,
ReadGlpk,
ReadGurobi,
ReadHighs,
ReadResults,
)
from otoole.utils import _read_file, read_deprecated_datapackage, validate_config
from otoole.write_strategies import WriteCsv, WriteDatafile, WriteExcel

Expand All @@ -32,14 +39,14 @@ def read_results(
input_path: str,
glpk_model: Optional[str] = None,
) -> Tuple[Dict[str, pd.DataFrame], Dict[str, float]]:
"""Read OSeMOSYS results from CBC, GLPK, Gurobi, or CPLEX results files
"""Read OSeMOSYS results from CBC, GLPK, Gurobi, HiGHS, or CPLEX results files
Arguments
---------
config : str
Path to config file
from_format : str
Available options are 'cbc', 'gurobi', 'cplex', and 'glpk'
Available options are 'cbc', 'gurobi', 'cplex', 'highs', and 'glpk'
from_path : str
Path to source file (if datafile or excel) or folder (csv)
input_format: str
Expand Down Expand Up @@ -82,18 +89,18 @@ def convert_results(
write_defaults: bool = False,
glpk_model: Optional[str] = None,
) -> bool:
"""Post-process results from a CBC, CPLEX, Gurobi, or GLPK solution file into CSV format
"""Post-process results from a CBC, CPLEX, Gurobi, HiHGS, or GLPK solution file into CSV format
Arguments
---------
config : str
Path to config file
from_format : str
Available options are 'cbc', 'cplex' and 'gurobi'
Available options are 'cbc', 'cplex', 'highs'. 'glpk', and 'gurobi'
to_format : str
Available options are 'csv'
from_path : str
Path to cbc, cplex or gurobi solution file
Path to solution file
to_path : str
Path to destination folder
input_format: str
Expand Down Expand Up @@ -147,14 +154,14 @@ def convert_results(
def _get_read_result_strategy(
user_config, from_format, glpk_model=None
) -> Union[ReadResults, None]:
"""Get ``ReadResults`` for gurobi, cbc, cplex, and glpk formats
"""Get ``ReadResults`` for gurobi, cbc, cplex, highs and glpk formats
Arguments
---------
config : dict
User configuration describing parameters and sets
from_format : str
Available options are 'cbc', 'gurobi', 'cplex', and 'glpk'
Available options are 'cbc', 'gurobi', 'cplex', 'highs', and 'glpk'
glpk_model : str
Path to ``*.glp`` model file
Expand All @@ -171,6 +178,8 @@ def _get_read_result_strategy(
read_strategy = ReadGurobi(user_config=user_config)
elif from_format == "cplex":
read_strategy = ReadCplex(user_config=user_config)
elif from_format == "highs":
read_strategy = ReadHighs(user_config=user_config)
elif from_format == "glpk":
if not glpk_model:
raise OtooleError(resource="Read GLPK", message="Provide glpk model file")
Expand Down

0 comments on commit 73d2a45

Please sign in to comment.