Skip to main content

Python interface to SHOP

Project description

pyshop

Status:

Latest Release build status coverage report

The nicest python interface to SHOP!

SHOP (Short-term Hydro Optimization Program) is a modeling tool for short-term hydro operation planning developed by SINTEF Energy Research in Trondheim, Norway. SHOP is used for both scientific and commerical purposes, please visit the SHOP home page for further information and inquiries regarding access and use.

The pyshop package is an open source python wrapper for SHOP, and requires the proper SHOP binaries to function (see step 2).

1 Installing pyshop

We currently offer two ways to use pyshop:

  1. Install pyshop through pypi (simple and quick)
  2. Install pyshop through Sintef's Gitlab Package Registry (useful if you want to avoid public registries)

Install pyshop using pypi

The pyshop package can be installed using pip, the package installer for python. Please visit the pip home page for installation and any pip related issues. You can install the official pyshop release through the terminal command:

pip install sintef-pyshop

You can also clone this repository and install the latest development version. To do this, open a terminal in the cloned pyshop directory and give the command:

pip install .

You should now see pyshop appear in the list of installed python modules when typing:

pip list

Install pyshop using Gitlab Package Registry

Create a personal access token.

Run the command below with your personal access token: pip install sintef-pyshop --index-url https://__token__:<your_personal_token>@gitlab.sintef.no/api/v4/projects/4012/packages/pypi/simple

2 Download the desired SHOP binaries for your system

NOTE: You may not distribute the cplex library as it requires end user license

The SHOP core is separate from the pyshop package, and must be downloaded separately. The latest SHOP binaries are found on the SHOP Portal. Access to the portal must be granted by SINTEF Energy Research.

The following binaries are required for pyshop to run:

Windows:

  • cplex2010.dll
  • shop_cplex_interface.dll
  • shop_pybind.pyd

Linux:

  • libcplex2010.so
  • shop_cplex_interface.so
  • shop_pybind.so

The solver specific binary is listed as cplex2010 here, but will change as new CPLEX versions become available. It is also possible to use the GUROBI and OSI solvers with SHOP. Note that the shop_cplex_interface.so used to contain the CPLEX binaries in the Linux distribution before SHOP version 14.3, and so older SHOP versions do not require the separate libcplex2010.so file.

3 Environment and license file

The SHOP license file, SHOP_license.dat, must always be located in the directory specified by the environment variable ICC_COMMAND_PATH. The ICC_COMMAND_PATH can be added as a persistent environment variable in the regular ways, or it can be set by pyshop on a session basis. If the keyword argument license_path is specified when creating an instance of the ShopSession class (see step 4), the environment variable is overridden in the local environment of the executing process. If SHOP complains about not finding the license file, it is likely an issue with the ICC_COMMAND_PATH not being correctly specified.

The ICC_COMMAND_PATH is also the default place pyshop will look for the SHOP binaries mentioned in step 2. If the binaries are placed elsewhere, the keyword argument solver_path must be used when a ShopSession instance is created to ensure the correct binaries are loaded. Note that SHOP versions older than 14.4.0.5 reqiuire libcplex2010.so to be placed in the '/lib' directory when running pyshop in a Linux environment. From version 14.4.0.5, the libcplex2010.so can be placed in the same directory as the other SHOP bionaries.

4 Running SHOP

Now that pyshop is installed, the SHOP binaries are downloaded, and the license file and binary paths are located, it is possible to run SHOP in python using pyshop:

import pyshop as pys

shop = pys.ShopSession(license_path="C:/License/File/Path", solver_path="C:/SHOP/versions/14")

Please visit the SHOP documentation for a detailed guides on how to use pyshop. For more in depth example you should look at the topics within the documentation. Most of the examples in the documentation are written using pyshop. E.g: Run a standard optimization

Visual Studio Code Dev Containers

Visual Studio Dev Containers lets you run a fully functional development environment using Docker and Visual Studio Code. This might simplyfy setting up pyshop for new users. Follow the guide below to setup the devcontainer for pyshop.

Installation

Install the following dependencies:

  1. Install the code editor called Visual Studio Code. Visual Studio Code is free
  2. Install a Docker GUI: Docker desktop (might require a paid license depending on your organization), or a free alternative called Podman

Setup

  1. Create a folder called .devcontainer in your root directory with a file called devcontainer.json. Your folder structure should look like the example below:

    Devcontainer folder setup

  2. Copy and paste the contents of devcontainer.json into your devcontainer.json file.

  3. Create a folder called bin in your root directory and add the following files: libcplex2010.so, shop_cplex_interface.so, your shop license e.g SHOP_license.dat, shop pybind e.g shop_pybind.cpython-312-x86_64-linux-gnu.so. Your bin folder should now look like:

    Binary folder with the required files

  4. Open your project using the devcontainer config files by running the command: Searching for devcontainer command

More in depth guides on how to customize devcontainers can be found in the devcontainer documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sintef_pyshop-1.4.12.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sintef_pyshop-1.4.12-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file sintef_pyshop-1.4.12.tar.gz.

File metadata

  • Download URL: sintef_pyshop-1.4.12.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for sintef_pyshop-1.4.12.tar.gz
Algorithm Hash digest
SHA256 4200041a60d5b7c8bfaa4d058f19f42d6643e3d596a9449b2cf3ace0e4902ffc
MD5 34d7e7dc8b9afa77fe640f0843790bec
BLAKE2b-256 56a9e009b12901a39cbe519b683ec70bc3aff3a4f641b6e73339b67de0a508c7

See more details on using hashes here.

File details

Details for the file sintef_pyshop-1.4.12-py3-none-any.whl.

File metadata

  • Download URL: sintef_pyshop-1.4.12-py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for sintef_pyshop-1.4.12-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5200d45c300b08f8fecac13b2241c09dfe8508cd4deaf3e37ebf0016956b05
MD5 ff9d832b1ad871c89311162b10bed5bd
BLAKE2b-256 0acd3a2ee2d72b56c86407e112bf7c4add24a5d19df839bb81585967946f487d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page