This repository provides a Python script to automate the workflow of running OSeMOSYS models (created using the MUIO interface) with advanced solvers such as CPLEX, Gurobi, GLPK, or CBC from the command line.
Since the MUIO interface for OSeMOSYS does not support solvers like CPLEX and Gurobi directly, this script enables users to preprocess their input files, convert data formats using Otoole, run the model using their preferred solver, and export the results.
- Automates the workflow for solving OSeMOSYS models from
.txtinput files. - Supports multiple solvers:
cplex,gurobi,glpk,cbc. - Uses
otoolefor data conversion and results export. - Automatically cleans up intermediate files after execution.
- Logs execution steps with timestamps for easier debugging.
-
Install Anaconda:
https://www.anaconda.com/products/distribution -
Clone this repository:
git clone https://github.com/ShravanKumar23/OSeMOSYS-Solver-script.git
cd osemosys-solver-runner- Create the required conda environment using the provided
otoole.ymlfile:
conda env create -f otoole.yml
conda activate otoole-envThe
otoole.ymlfile should include dependencies such asotoole,python,pyyamland any solver-specific packages (if needed).
This script supports .txt input files generated from both OSeMOSYS MUIO Version 4.6 and Version 5.2.
There are two separate runner scripts provided for handling these versions:
| Version | Script to Use | Notes |
|---|---|---|
| 4.6 | Run_CLEWs_4.6.py |
For input files created using Version 4.6 of MUIO. |
| 5.2 | Run_CLEWs_5.2.py |
For input files created using Version 5.2 of MUIO. |
Please ensure that you use the correct script corresponding to the version of your
.txtinput file.
After activating the environment, run the script using:
python Run_CLEWs_4.6.py <input_file> <solver>python Run_CLEWs_5.2.py <input_file> <solver>| Argument | Description | Example |
|---|---|---|
<input_file> |
The .txt data file generated from MUIO (OSeMOSYS user interface). This file contains the model data. |
my_model.txt |
<solver> |
The solver to use for optimization. Must be one of: cplex, gurobi, glpk, cbc. |
gurobi |
python Run_CLEWs_5.2.py data.txt gurobiThis command will:
- Convert the MUIO
.txtfile to Otoole CSV format. - Preprocess the data.
- Generate the
.lpfile (linear program). - Solve the model using Gurobi.
- Export results to CSV format in the
results/directory. - Clean up temporary files.
| File/Folder | Description |
|---|---|
results/ |
Contains the model results in CSV format. |
data/ |
Intermediate Otoole CSV files from data conversion. |
my_model.lp |
The model file in LP format used by the solver. |
my_model.sol |
The solution file generated by the solver. |
.
├── Run_CLEWs_5.2.py
├── Run_CLEWs_4.6.py
├── otoole.yml
├── model.v.5.2.txt
├── osemosys_preprocessing_v45_DR_mod.txt
├── config_com.yaml
├── config_com_4.6.yaml
├── preprocess_data.py
├── my_model.txt
├── data/
│ └── ...
├── results/
│ └── ...
-
Make sure the following files exist in the same folder as
run_solver.pybefore running:model.v.5.2.txt— Your OSeMOSYS model formulation file.config_com.yaml— Otoole configuration file for mapping input/output parameters.preprocess_data.py— Your preprocessing script (e.g., data cleaning, validation).
-
Solver binaries (like CPLEX or Gurobi) must be installed and available in your system PATH.
- If any command fails, check the error logs printed in the terminal.
- Common issues include:
- Incorrect input file format.
- Solver license or installation errors.
- Missing files in the directory.
MIT License