Skip to content

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.

Notifications You must be signed in to change notification settings

ShravanKumar23/OSeMOSYS-Solver-script

Repository files navigation

OSeMOSYS Solver Script

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.


Features

  • Automates the workflow for solving OSeMOSYS models from .txt input files.
  • Supports multiple solvers: cplex, gurobi, glpk, cbc.
  • Uses otoole for data conversion and results export.
  • Automatically cleans up intermediate files after execution.
  • Logs execution steps with timestamps for easier debugging.

Prerequisites

  1. Install Anaconda:
    https://www.anaconda.com/products/distribution

  2. Clone this repository:

git clone https://github.com/ShravanKumar23/OSeMOSYS-Solver-script.git
cd osemosys-solver-runner
  1. Create the required conda environment using the provided otoole.yml file:
conda env create -f otoole.yml
conda activate otoole-env

The otoole.yml file should include dependencies such as otoole, python, pyyaml and any solver-specific packages (if needed).


Supported Input Versions

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 .txt input file.


Usage

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>

Arguments

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

Example Command

python Run_CLEWs_5.2.py data.txt gurobi

This command will:

  1. Convert the MUIO .txt file to Otoole CSV format.
  2. Preprocess the data.
  3. Generate the .lp file (linear program).
  4. Solve the model using Gurobi.
  5. Export results to CSV format in the results/ directory.
  6. Clean up temporary files.

Output Structure

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.

Example Folder Structure After Running

.
├── 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/
│   └── ...

Notes

  • Make sure the following files exist in the same folder as run_solver.py before 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.


Troubleshooting

  • 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.

License

MIT License


Acknowledgements

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages