A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

pymgrid

A Python library to generate and simulate a large number of microgrids.
https://github.com/Total-RD/pymgrid

Keywords

control energy-management-systems microgrid microgrid-model reinforcement-learning

Last synced: about 1 year ago
JSON representation

Acceptance Criteria

Repository metadata

pymgrid is a python library to generate and simulate a large number of microgrids.

README.md

pymgrid

Important Notice

The person that has been maintaining pymgrid since 2020 has moved future development to python-microgrid for the foreseeable future, a drop in replacement for pymgrid, and pymgrid may not be receiving any future updates. Please open any new issues in python-microgrid.

Build

pymgrid (PYthon MicroGRID) is a python library to generate and simulate a large number of microgrids.

For more context, please see the presentation done at Climate Change AI
and the documentation.

Installation

The easiest way to install pymgrid is with pip:

pip install -U pymgrid

Alternatively, you can install from source. First clone the repo:

git clone https://github.com/Total-RD/pymgrid.git

Then navigate to the root directory of pymgrid and call

pip install .

Getting Started

Microgrids are straightforward to generate from scratch. Simply define some modules and pass them
to a microgrid:

import numpy as np
from pymgrid import Microgrid
from pymgrid.modules import GensetModule, BatteryModule, LoadModule, RenewableModule


genset = GensetModule(running_min_production=10,
                      running_max_production=50,
                      genset_cost=0.5)

battery = BatteryModule(min_capacity=0,
                        max_capacity=100,
                        max_charge=50,
                        max_discharge=50,
                        efficiency=1.0,
                        init_soc=0.5)

# Using random data
renewable = RenewableModule(time_series=50*np.random.rand(100))

load = LoadModule(time_series=60*np.random.rand(100),
                  loss_load_cost=10)

microgrid = Microgrid([genset, battery, ("pv", renewable), load])

This creates a microgrid with the modules defined above, as well as an unbalanced energy module --
which reconciles situations when energy demand cannot be matched to supply.

Printing the microgrid gives us its architecture:

>> microgrid

Microgrid([genset x 1, load x 1, battery x 1, pv x 1, balancing x 1])

A microgrid is contained of fixed modules and flex modules. Some modules can be both -- GridModule, for example
-- but not at the same time.

A fixed module has requires a request of a certain amount of energy ahead of time, and then attempts to
produce or consume said amount. LoadModule is an example of this; you must tell it to consume a certain amount of energy
and it will then do so.

A flex module, on the other hand, is able to adapt to meet demand. RenewableModule is an example of this as
it allows for curtailment of any excess renewable produced.

A microgrid will tell you which modules are which:

>> microgrid.fixed_modules

{
 "genset": "[GensetModule(running_min_production=10, running_max_production=50, genset_cost=0.5, co2_per_unit=0, cost_per_unit_co2=0, start_up_time=0, wind_down_time=0, allow_abortion=True, init_start_up=True, raise_errors=False, provided_energy_name=genset_production)]",
 "load": "[LoadModule(time_series=<class 'numpy.ndarray'>, loss_load_cost=10, forecaster=NoForecaster, forecast_horizon=0, forecaster_increase_uncertainty=False, raise_errors=False)]",
 "battery": "[BatteryModule(min_capacity=0, max_capacity=100, max_charge=50, max_discharge=50, efficiency=1.0, battery_cost_cycle=0.0, battery_transition_model=None, init_charge=None, init_soc=0.5, raise_errors=False)]"
}

>>microgrid.flex_modules

{
 "pv": "[RenewableModule(time_series=<class 'numpy.ndarray'>, raise_errors=False, forecaster=NoForecaster, forecast_horizon=0, forecaster_increase_uncertainty=False, provided_energy_name=renewable_used)]",
 "balancing": "[UnbalancedEnergyModule(raise_errors=False, loss_load_cost=10, overgeneration_cost=2)]"
}

Running the microgrid is straightforward. Simply pass an action for each fixed module to microgrid.run. The microgrid
can also provide you a random action by calling microgrid.sample_action. Once the microgrid has been run for a
certain number of steps, results can be viewed by calling microgrid.get_log.

>> for j in range(10):
>>    action = microgrid.sample_action(strict_bound=True)
>>    microgrid.run(action)

>> microgrid.get_log(drop_singleton_key=True)

      genset  ...                     balance
      reward  ... fixed_absorbed_by_microgrid
0  -5.000000  ...                   10.672095
1 -14.344353  ...                   50.626726
2  -5.000000  ...                   17.538018
3  -0.000000  ...                   15.492778
4  -0.000000  ...                   35.748724
5  -0.000000  ...                   30.302300
6  -5.000000  ...                   36.451662
7  -0.000000  ...                   66.533872
8  -0.000000  ...                   20.645077
9  -0.000000  ...                   10.632957

Benchmarking

pymgrid also comes pre-packaged with a set of 25 microgrids for benchmarking.
The config files for these microgrids are available in data/scenario/pymgrid25.
Simply deserialize one of the yaml files to load one of the saved microgrids; for example,
to load the zeroth microgrid:

import yaml
from pymgrid import PROJECT_PATH

yaml_file = PROJECT_PATH / 'data/scenario/pymgrid25/microgrid_0/microgrid_0.yaml'
microgrid = yaml.safe_load(yaml_file.open('r'))

Alternatively, Microgrid.load(yaml_file.open('r')) will perform the same deserialization.

Citation

If you use this package for your research, please cite the following paper:

@misc{henri2020pymgrid,
title={pymgrid: An Open-Source Python Microgrid Simulator for Applied Artificial Intelligence Research},
author={Gonzague Henri, Tanguy Levent, Avishai Halev, Reda Alami and Philippe Cordier},
year={2020},
eprint={2011.08004},
archivePrefix={arXiv},
primaryClass={cs.AI}
}

You can find it on Arxiv here: https://arxiv.org/abs/2011.08004

Data

Data in pymgrid are based on TMY3 (data based on representative weather). The PV data comes from DOE/NREL/ALLIANCE (https://nsrdb.nrel.gov/about/tmy.html) and the load data comes from OpenEI (https://openei.org/doe-opendata/dataset/commercial-and-residential-hourly-load-profiles-for-all-tmy3-locations-in-the-united-states)

The CO2 data is from Jacque de Chalendar and his gridemissions API.

Contributing

Pull requests are welcome for bug fixes. For new features, please open an issue first to discuss what you would like to add.

Please make sure to update tests as appropriate.

License

This repo is under a GNU LGPL 3.0 (https://github.com/total-sa/pymgrid/edit/master/LICENSE)


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: about 1 year ago

Total Commits: 1,290
Total Committers: 10
Avg Commits per committer: 129.0
Development Distribution Score (DDS): 0.214

Commits in past year: 968
Committers in past year: 2
Avg Commits per committer in past year: 484.0
Development Distribution Score (DDS) in past year: 0.001

Name Email Commits
ahalev a****v@g****m 1014
Gonzague Henri g****i@t****m 149
Gonzague Henri g****i@g****m 107
Tanguy t****2@g****m 9
Reda ALAMI 3****9 4
Yann BERTHERLOT y****t@c****m 3
pochelu p****u@t****m 1
Alexis de Talhouët a****9@g****m 1
Bipin Paudel b****l@j****u 1
RoKe2017 1****7 1

Committer domains:


Issue and Pull Request metadata

Last synced: about 1 year ago

Total issues: 57
Total pull requests: 192
Average time to close issues: 5 months
Average time to close pull requests: about 17 hours
Total issue authors: 18
Total pull request authors: 8
Average comments per issue: 1.49
Average comments per pull request: 0.05
Merged pull request: 179
Bot issues: 0
Bot pull requests: 0

Past year issues: 3
Past year pull requests: 24
Past year average time to close issues: about 8 hours
Past year average time to close pull requests: about 5 hours
Past year issue authors: 3
Past year pull request authors: 2
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.08
Past year merged pull request: 22
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/Total-RD/pymgrid

Top Issue Authors

  • GonzagueHenri (21)
  • TanguyLevent (10)
  • ahalev (4)
  • Pierrick-Pochelu (4)
  • Ralami1859 (3)
  • Brandaoss (2)
  • hh30hh (2)
  • utix (1)
  • msbomrel2020 (1)
  • mdeboute (1)
  • linker81 (1)
  • denfromufa (1)
  • ciolo (1)
  • bitterhoneyy (1)
  • aruhela (1)

Top Pull Request Authors

  • ahalev (164)
  • GonzagueHenri (14)
  • TanguyLevent (8)
  • YannBerthelot (2)
  • adetalhouet (1)
  • BipinPaudel (1)
  • RoKe2017 (1)
  • Ralami1859 (1)

Top Issue Labels

  • enhancement (3)
  • question (3)
  • bug (3)

Top Pull Request Labels


Package metadata

proxy.golang.org: github.com/total-rd/pymgrid

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/total-rd/pymgrid#section-documentation
  • Licenses: lgpl-3.0
  • Latest release: v1.2.2 (published over 2 years ago)
  • Last Synced: 2024-02-16T12:37:36.724Z (about 1 year ago)
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 1.622%
    • Average: 4.057%
    • Dependent packages count: 6.492%
proxy.golang.org: github.com/Total-RD/pymgrid

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/Total-RD/pymgrid#section-documentation
  • Licenses:
  • Latest release: v1.2.2 (published over 2 years ago)
  • Last Synced: 2024-02-16T12:37:36.620Z (about 1 year ago)
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 6.999%
    • Average: 8.173%
    • Dependent repos count: 9.346%
pypi.org: pymgrid

A simulator for tertiary control of electrical microgrids

  • Homepage:
  • Documentation: https://pymgrid.readthedocs.io/en/latest/
  • Licenses: GNU LGPL 3.0
  • Latest release: 1.2.2 (published over 2 years ago)
  • Last Synced: 2024-02-16T12:37:36.344Z (about 1 year ago)
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 64 Last month
  • Rankings:
    • Forks count: 5.48%
    • Stargazers count: 5.861%
    • Dependent packages count: 7.31%
    • Average: 14.299%
    • Dependent repos count: 22.088%
    • Downloads: 30.757%
  • Maintainers (1)

Dependencies

requirements.txt pypi
  • cufflinks *
  • cvxpy *
  • matplotlib *
  • numpy *
  • pandas *
  • plotly *
  • seaborn *
  • statsmodels *
setup.py pypi
  • cufflinks *
  • cvxpy *
  • gym *
  • matplotlib *
  • numpy *
  • pandas *
  • plotly *
  • requests *
  • statsmodels *
.github/workflows/build.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
.github/workflows/documentation-links.yaml actions
  • readthedocs/actions/preview v1 composite
.github/workflows/garage-compat.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • wei/wget v1 composite
docs/requirements.txt pypi
  • Sphinx ==5.3.0
  • nbsphinx ==0.8.10
  • nbsphinx-link ==1.3.0
  • numpydoc ==1.5.0
  • pydata_sphinx_theme ==0.12.0
pyproject.toml pypi

Score: 11.567413650254299