Skip to content

Commit e542b31

Browse files
authored
Update environment and README to latest Python version (#322)
* Update environment and README to latest Python version * Adjust default timesteps * Add information on activating environments in README * Fix format in README
1 parent c941c45 commit e542b31

File tree

7 files changed

+132
-52
lines changed

7 files changed

+132
-52
lines changed

README.md

Lines changed: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ urbs is a [linear programming](https://en.wikipedia.org/wiki/Linear_programming)
55
[![Documentation Status](https://readthedocs.org/projects/urbs/badge/?version=latest)](http://urbs.readthedocs.io/en/latest/?badge=latest)
66
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.594200.svg)](https://doi.org/10.5281/zenodo.594200)
77

8+
## Table of Contents
9+
10+
- [Features](#features)
11+
- [Screenshots](#screenshots)
12+
- [Installation](#installation)
13+
- [Installing Python](#installing-python)
14+
- [Installing a Python IDE (optional)](#installing-a-python-ide-optional)
15+
- [Installing Git](#installing-git)
16+
- [Cloning the urbs repository](#cloning-the-urbs-repository)
17+
- [Installing your environment](#installing-your-environment)
18+
- [Solver](#solver)
19+
- [Get started](#get-started)
20+
- [Next steps and tips](#next-steps-and-tips)
21+
- [Further reading](#further-reading)
22+
- [Example uses](#example-uses)
23+
- [Contributing](#contributing)
24+
- [License](#license)
25+
826
## Features
927

1028
* urbs is a linear programming model for multi-commodity energy systems with a focus on optimal storage sizing and use.
@@ -22,40 +40,65 @@ urbs is a [linear programming](https://en.wikipedia.org/wiki/Linear_programming)
2240

2341
## Installation
2442

25-
There are 2 ways to get all required packages under Windows. We recommend using the Python distribution Anaconda. If you don't want to use it or already have an existing Python (version 3.6 **recommended**, 2.7 is supported as well) installation, you can also download the required packages by yourself..
43+
### Installing Python
2644

27-
### Anaconda/Miniconda (recommended)
45+
1) Download and install [Python 3.12](https://www.python.org/downloads/). ***Note: Make sure to check the box "Add Python to PATH" during installation.***
46+
2) Using your terminal you can check which Python versions are installed on your system with `py -0` and check your standard version with `python --version`. The output should be `Python 3.12.x` or similar.
47+
<br /> (***Note: If your standard python version is Python 2.X, you might need to call `python3` instead of `python`.***)
2848

29-
1. **[Anaconda (Python 3)](http://continuum.io/downloads)/[Miniconda](https://docs.conda.io/en/latest/miniconda.html)**. Choose the 64-bit installer if possible.
30-
During the installation procedure, keep both checkboxes "modify PATH" and "register Python" selected! If only higher Python versions are available, you can switch to a specific Python Version by typing `conda install python=<version>`
31-
2. **Packages and Solver**: [GLPK](http://winglpk.sourceforge.net/).
32-
1. Download the [environment file](https://github.com/tum-ens/urbs/blob/master/urbs-env.yml).
33-
2. Launch a new command prompt (Windows: Win+R, type "cmd", Enter)
34-
3. Install it via conda by `conda env create -f urbs-env.yml`.
35-
4. Each time you open a new terminal for running urbs, you can activate the environment by `conda activate urbs`.
49+
### Installing an IDE (optional)
3650

37-
Continue at [Get Started](#get-started).
51+
If you want to use an IDE for Python, you can install [PyCharm](https://www.jetbrains.com/pycharm/download/#section=windows) or [Visual Studio Code](https://code.visualstudio.com/). Both are free to use.
3852

39-
### Manually (the hard way)
53+
### Installing Git
4054

41-
For all packages, best take the latest release or release candidate version. Both 32 bit and 64 bit versions work, though 64 bit is recommended. The list of packages can be found in the [environment file](https://github.com/tum-ens/urbs/blob/master/urbs-env.yml).
42-
43-
## Get started
55+
1) Download and install [Git](http://git-scm.com/). Make sure to check the box "Run Git from the Windows Command Prompt" during installation.
56+
You can also use the [GitHub Desktop](https://desktop.github.com/) application if you prefer a graphical user interface.
57+
2) Check that Git is installed by running the command `git --version` in your terminal.
58+
59+
### Cloning the urbs repository
60+
61+
1) Open your terminal and navigate to your preferred directory.
62+
2) Clone the repository by running the following commands in your terminal.:
63+
- For GitLab: `git clone git@gitlab.lrz.de:tum-ens/urbs.git`
64+
- For GitHub: `git clone git@github.com:tum-ens/urbs.git`
65+
3) Navigate to the cloned repository by running `cd urbs` in your terminal.
66+
67+
### Installing your environment
4468

45-
### Developers
46-
Once installation is complete, finally [install git (for version control)](http://git-scm.com/). **Remark:** at step "Adjusting your PATH environment", select "Run Git from the Windows Command Prompt".
69+
1) In windows you can install the environment by running the batch script `prepare-virtual-environment` in the root directory of the repository.
70+
You can do so from a terminal or by double-clicking the file in the file explorer. This will create a virtual environment and install all necessary packages.
71+
2) If you want to install the environment manually, enter the commands below in your terminal:
72+
- Windows: <br />
73+
`py -3.12 -m venv urbs-env` <br />
74+
`urbs-env\Scripts\activate` <br />
75+
`python -m pip install -r urbs-env.txt`
4776

48-
Then, in a directory of your choice, clone this repository by:
77+
- Linux/MacOS: <br />
78+
`python3.12 -m venv urbs-env` <br />
79+
`source urbs-env/bin/activate` <br />
80+
`python -m pip install -r urbs-env.txt`
4981

50-
git clone https://github.com/tum-ens/urbs.git
51-
52-
Continue like the users after they downloaded the zip file.
82+
### Solver
83+
There are several solvers that can be used to solve the optimization problems. Our recommendations are the following two python libraries that have been installed in the environment.
84+
- [Highs](https://highs.dev/) (open-source)
85+
- [Gurobi](https://www.gurobi.com/) (commercial): To run this powerful solver you first need to create an account, apply for an academic license in the license center and download it ([descriptions](https://www.gurobi.com/features/academic-named-user-license/)).
5386

54-
### Users
87+
However, also other solvers such as [glpk](https://www.gnu.org/software/glpk/) (open-source) or [CPLEX](https://www.ibm.com/analytics/cplex-optimizer) (commercial) are compatible with the Pyomo interface in urbs.
5588

56-
If you are not planning on developing urbs, pick the [latest release](https://github.com/tum-ens/urbs/releases) and download the zip file.
89+
### (optional) Installing Jupyter Notebook
90+
If you want to use the Jupyter Notebook, install it by running `python -m pip install jupyter` in your terminal.
5791

58-
In the downloaded directory, open a execute the runme script by using the following on the command prompt (Windows) or Terminal (Linux). (Depending on what your standard python version is, you might need to call `python3` instead of `python`.):
92+
## Get started
93+
94+
Before running a script, ensure your environment is activated:
95+
- Either set up your interpreter in your IDE with your created environment.
96+
- Or, if running from your terminal, use the following command to activate it:
97+
- Windows: `urbs-env\Scripts\activate`
98+
- Linux/MacOS: `source urbs-env/bin/activate`
99+
100+
In the downloaded directory, open a execute the runme script by using the following on the command prompt or Terminal.
101+
<br /> (***Note: Depending on what your standard python version is, you might need to call `python3.12` instead of `python`.***):
59102

60103
python runme.py
61104

@@ -67,7 +110,7 @@ and look at the new files `result/mimo-example-.../comparison.xlsx` and `result/
67110

68111
## Next steps and tips
69112

70-
1. Head over to the tutorial at http://urbs.readthedocs.io, which goes through runme.py step by step.
113+
1. Head over to the tutorial at http://urbs.readthedocs.io, which goes through runme.py step by step or try out the Jupyter Notebook tutorial inside the teaching folder.
71114
2. Read the source code of `runme.py` and `comp.py`.
72115
3. Try adding/modifying scenarios in `scenarios.py` and see their effect on results.
73116
4. If you need a nice python editor, think about using [PyCharm](https://www.jetbrains.com/pycharm/download). It has many features including easy Git integration, package management, etc.
@@ -90,15 +133,7 @@ and look at the new files `result/mimo-example-.../comparison.xlsx` and `result/
90133
<a href="https://raw.githubusercontent.com/ojdo/urbs/1house/img/comparison.png"><img src="https://raw.githubusercontent.com/ojdo/urbs/1house/img/comparison.png" alt="Comparison plot in example study 1house."></a>
91134

92135
- Branch [haag15](https://github.com/ojdo/urbs/tree/haag15) in the forked repository [ojdo/urbs](https://github.com/ojdo/urbs) shows a larger example of a real-world use. Its input file contains a town divided into 12 regions, 12 process types, and 2 demand commodities (electricity and heat) . Patience and RAM (64 GB or more) is needed to run these scenarios with 8760 timesteps. The branch also contains three IPython notebooks that are used for result analysis and coupling to model [rivus](https://github.com/tum-ens/rivus).
93-
94-
## List of branches
95-
- ASEAN
96-
- CoTraDis
97-
- decensys
98-
- extremos
99-
- MIQCP
100-
- near_optimal
101-
- urbs_gui
136+
102137

103138
## Copyright
104139

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@echo off
2+
REM =======================================
3+
REM Batch script to set up Python environment for urbs
4+
REM =======================================
5+
6+
REM Check if the virtual environment exists
7+
if exist "urbs-env\Scripts\activate" (
8+
echo Virtual environment already exists.
9+
) else (
10+
REM Create the virtual environment
11+
echo Creating virtual environment...
12+
py -3.12 -m venv urbs-env
13+
14+
REM Check if creation was successful
15+
if not exist "urbs-env\Scripts\activate" (
16+
echo Error: Failed to create virtual environment.
17+
exit /b 1
18+
)
19+
)
20+
21+
REM Activate the virtual environment (Windows)
22+
call urbs-env\Scripts\activate
23+
echo Virtual environment has been activated.
24+
25+
REM Check if packages are already installed
26+
REM Using a dummy file to detect if packages are installed, you can also use pip freeze or similar checks
27+
if exist "urbs-env\installed.flag" (
28+
echo Required packages already installed.
29+
) else (
30+
echo Installing required packages from urbs-env.txt...
31+
python -m pip install -r urbs-env.txt
32+
33+
REM Check if the installation succeeded
34+
if %errorlevel% neq 0 (
35+
echo Error: Failed to install packages.
36+
exit /b 1
37+
)
38+
39+
REM Create a flag to indicate that packages have been installed
40+
echo Packages installed successfully > urbs-env\installed.flag
41+
echo Packages installed successfully.
42+
)
43+
44+
REM Notify the user that the process is complete
45+
echo Your urbs environment is ready to use.
46+
47+
REM Prevent the script from closing immediately
48+
pause

run_intertemporal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
solver = 'gurobi'
2929

3030
# simulation timesteps
31-
(offset, length) = (0, 24) # time step selection
31+
(offset, length) = (0, 8760) # time step selection
3232
timesteps = range(offset, offset+length+1)
3333
dt = 1 # length of each time step (unit: hours)
3434

run_single_year.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
solver = 'gurobi'
2929

3030
# simulation timesteps
31-
(offset, length) = (0, 20) # time step selection
31+
(offset, length) = (0, 8760) # time step selection
3232
timesteps = range(offset, offset+length+1)
3333
dt = 1 # length of each time step (unit: hours)
3434

runme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
solver = 'gurobi'
2525

2626
# simulation timesteps
27-
(offset, length) = (3500, 24) # time step selection
27+
(offset, length) = (0, 8760) # time step selection
2828
timesteps = range(offset, offset+length+1)
2929
dt = 1 # length of each time step (unit: hours)
3030

urbs-env.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Python venv
2+
numpy==1.26.4
3+
matplotlib==3.8.3
4+
pandas==2.2.1
5+
pandas-datareader==0.10.0
6+
tables==3.9.2 #pytables in conda
7+
openpyxl==3.1.2
8+
xlrd==2.0.1
9+
pyomo==6.7.1
10+
psutil==5.9.8
11+
pyutilib==6.0.0
12+
gurobipy
13+
highspy

urbs-env.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)