pycity_scheduling
Python package pycity_scheduling is a framework for the effective development, testing, and assessment of optimization-based power scheduling algorithms for local multi-energy systems in city districts.
The framework primarily targets the elaboration of coordination concepts that can efficiently solve the power dispatch problem on the city district level.
Its target users are researchers in the field of smart grid applications and the deployment of operational flexibility for local energy systems.
Contribution
- Clone repository via SSH (
git clone git@git.rwth-aachen.de:acs/public/simulation/pycity_scheduling.git
) or clone repository via HTTPS (git clone https://git.rwth-aachen.de/acs/public/simulation/pycity_scheduling.git
) - Open an issue at https://git.rwth-aachen.de/acs/public/simulation/pycity_scheduling/-/issues
- Checkout the development branch:
git checkout development
- Update your local development branch (if necessary):
git pull origin development
- Create your feature/issue branch:
git checkout -b issueXY_explanation
- Commit your changes:
git commit -m "Add feature #XY"
- Push to the branch:
git push origin issueXY_explanation
- Submit a merge request from issueXY_explanation to development branch via https://git.rwth-aachen.de/acs/public/simulation/pycity_scheduling/-/merge_requests
- Wait for approval or revision of the new implementations.
Installation
pycity_scheduling requires at least the following Python packages:
- numpy==1.26.0
- pandas==2.1.1
- matplotlib==3.8.0
- pyomo==6.8.2
- pycity_base==0.3.3
- scikit-learn==1.3.2
- psutil==6.1.0
- ray==2.40.0
- pyarrow==17.0.0
- mpi4py==4.0.0 (optional)
- pytest==7.4.2 (optional)
- pylint (optional)
- sphinx (optional)
- numpydoc (optional)
as well as the installation of at least one mathematical programming solver for convex and/or non-convex problems, which is supported by the Pyomo optimisation modelling library.
We recommend one of the following solvers:
Installation of pycity_scheduling
The latest version of pycity_scheduling is v1.4.0.
If all the abovementioned dependencies are installed, you should be able to install package pycity_scheduling via PyPI (using Python version >= 3.9) as follows:
pip install pycity_scheduling
or to install in editable mode:
pip install -e '<your_path_to_pycity_scheduling_git_folder>'
or:
<path_to_your_python_binary> -m pip install -e '<your_path_to_pycity_scheduling_git_folder>/src'
The project can also be installed in editable mode directly from gitlab without the need for a previous download:
pip install -e "git+ssh://git.rwth-aachen.de:acs/public/simulation/pycity_scheduling.git"
or:
pip install --src <install_location> -e "git+ssh://git.rwth-aachen.de:acs/public/simulation/pycity_scheduling.git"
You can check if the installation has been successful by trying to import package pycity_scheduling into your Python environment.
This import should be possible without any errors.
import pycity_scheduling
You may also try to run the pycity_scheduling's unit tests located in folder ./src/testing using Python module pytest.
Documentation
The documentation for the latest pycity_scheduling release can be found in folder ./docs and on this GitLab page.
For further information, please also visit the FEIN Aachen association website.
Example usage
import numpy as np
import matplotlib.pyplot as plt
from pycity_scheduling.classes import *
from pycity_scheduling.algorithms import *
import pycity_scheduling.util.debug as debug
def main(do_plot=False):
print("\n\n------ Example 00: Fundamentals ------\n\n")
timer = Timer(step_size=3600, op_horizon=24, initial_date=(2015, 1, 1), initial_time=(0, 0, 0))
weather = Weather(timer=timer)
price = Prices(timer=timer)
environment = Environment(timer=timer, weather=weather, prices=price)
print('Weekday:')
print(environment.timer.weekday)
print('\nOutdoor temperature forecast:')
print(environment.weather.getWeatherForecast(getTAmbient=True)[0][:10])
print('\nDay-ahead spot market prices on 2015/01/01:')
print(environment.prices.da_prices)
building = Building(environment=environment)
apartment = Apartment(environment=environment)
bes = BuildingEnergySystem(environment=environment)
building.addMultipleEntities([apartment, bes])
load = FixedLoad(environment=environment, method=1, annual_demand=3000)
print('\nElectrical load in Watt:')
print(load.get_power(currentValues=False))
plt.plot(load.get_power(currentValues=False))
plt.xlabel('Time in hours')
plt.ylabel('Electrical power in Watt (fixed load)')
plt.title('Fixed load power curve')
if do_plot:
plt.show()
space_heating = SpaceHeating(environment=environment, method=1, living_area=150, specific_demand=100)
print('\nSpace heating power curve in Watt:')
print(space_heating.get_power(currentValues=False))
plt.plot(space_heating.get_power(currentValues=False))
plt.xlabel('Time in hours')
plt.ylabel('Thermal power in Watt (space heating)')
plt.title('Space heating power curve')
if do_plot:
plt.show()
apartment.addMultipleEntities([load, space_heating])
eh = HeatPump(environment=environment, p_th_nom=16.0)
ths = ThermalHeatingStorage(environment=environment, e_th_max=20.0, soc_init=0.5, loss_factor=0)
pv = Photovoltaic(environment=environment, method=0, peak_power=8.0)
bes.addMultipleDevices([eh, ths, pv])
print('\nBES has heatpump? : ', bes.getHasDevices(all_devices=False, heatpump=True)[0])
print('BES has thermal heating storage? : ', bes.getHasDevices(all_devices=False, ths=True)[0])
print('BES has photovoltaic? : ', bes.getHasDevices(all_devices=False, pv=True)[0])
cd = CityDistrict(environment=environment)
cd.addEntity(entity=building, position=[0, 0])
for i in range(3):
heat_demand = SpaceHeating(environment=environment, method=1, living_area=150, specific_demand=100)
el_load_demand = FixedLoad(environment=environment, method=1, annual_demand=3000)
pv = Photovoltaic(environment=environment, method=0, peak_power=5.0)
bl = Boiler(environment=environment, p_th_nom=24.0)
ap = Apartment(environment=environment)
ap.addEntity(heat_demand)
ap.addEntity(el_load_demand)
bes = BuildingEnergySystem(environment=environment)
bes.addDevice(pv)
bes.addDevice(bl)
bd = Building(environment=environment)
bd.addEntity(entity=ap)
bd.addEntity(entity=bes)
cd.addEntity(entity=bd, position=[0, i])
print('\nTotal number of buildings in city district:')
print(cd.get_nb_of_building_entities())
print("\nDetailed city district information:")
debug.print_district(cd, 3)
cd.set_objective("peak-shaving")
opt = CentralOptimization(cd)
opt.solve()
cd.copy_schedule("my_central_scheduling")
print("\nPower schedule of city district:")
print(list(cd.p_el_schedule))
plt.plot(cd.p_el_schedule, drawstyle='steps')
plt.xlabel('Time in hours')
plt.ylabel('Electrical power in Kilowatt')
plt.title('Electrical Power Schedule of CityDistrict')
if do_plot:
plt.show()
return
if __name__ == '__main__':
main(do_plot=True)
Tutorial
The pycity_scheduling package comes with several example/tutorial scripts in folder ./src/pycity_scheduling/examples
.
The unit tests can be found in folder ./src/pycity_scheduling/testing
.
Moreover, various test case studies (as thoroughly described and analyzed in different research papers) are located at ./src/pycity_scheduling/case_studies
.
License
The pycity_scheduling package is released by the Institute for Automation of Complex Power Systems (ACS), E.ON Energy Research Center (E.ON ERC), RWTH Aachen University under the MIT License.
Contact
Institute for Automation of Complex Power Systems (ACS)
E.ON Energy Research Center (E.ON ERC)
RWTH Aachen University, Germany
![](https://fein-aachen.org/img/logos/eonerc.png)