{"id":30957278,"url":"https://github.com/total-rd/pymgrid","last_synced_at":"2025-09-11T13:45:18.323Z","repository":{"id":41558356,"uuid":"248366886","full_name":"Total-RD/pymgrid","owner":"Total-RD","description":"pymgrid is a python library to generate and simulate a large number of microgrids.","archived":false,"fork":false,"pushed_at":"2023-09-08T19:05:43.000Z","size":53724,"stargazers_count":196,"open_issues_count":6,"forks_count":71,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-09-11T00:37:39.399Z","etag":null,"topics":["control","energy-management-systems","microgrid","microgrid-model","reinforcement-learning"],"latest_commit_sha":null,"homepage":"https://pymgrid.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Total-RD.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-18T23:37:39.000Z","updated_at":"2025-09-10T07:58:39.000Z","dependencies_parsed_at":"2023-09-21T19:18:41.782Z","dependency_job_id":"5ad68fcc-509c-4402-8811-03588d9fe56a","html_url":"https://github.com/Total-RD/pymgrid","commit_stats":{"total_commits":1290,"total_committers":10,"mean_commits":129.0,"dds":"0.21395348837209305","last_synced_commit":"7bf39516e1e91b6fe5dbe22ea2eb6caeb5ac6fb8"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/Total-RD/pymgrid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Total-RD%2Fpymgrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Total-RD%2Fpymgrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Total-RD%2Fpymgrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Total-RD%2Fpymgrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Total-RD","download_url":"https://codeload.github.com/Total-RD/pymgrid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Total-RD%2Fpymgrid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274648319,"owners_count":25324299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["control","energy-management-systems","microgrid","microgrid-model","reinforcement-learning"],"created_at":"2025-09-11T13:45:11.434Z","updated_at":"2025-09-11T13:45:18.311Z","avatar_url":"https://github.com/Total-RD.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pymgrid\n\n## Important Notice\n\n### The person that has been maintaining pymgrid since 2020 has moved future development to [python-microgrid](https://github.com/ahalev/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.\n\n\n![Build](https://github.com/Total-RD/pymgrid/workflows/build/badge.svg?dummy=unused)\n\npymgrid (PYthon MicroGRID) is a python library to generate and simulate a large number of microgrids.\n\nFor more context, please see the [presentation](https://www.climatechange.ai/papers/neurips2020/3) done at Climate Change AI\nand the [documentation](https://pymgrid.readthedocs.io).\n\n## Installation\n\nThe easiest way to install pymgrid is with pip:\n\n`pip install -U pymgrid`\n\nAlternatively, you can install from source. First clone the repo:\n \n```bash\ngit clone https://github.com/Total-RD/pymgrid.git\n``` \nThen navigate to the root directory of pymgrid and call\n\n```bash\npip install .\n```\n## Getting Started\n\nMicrogrids are straightforward to generate from scratch. Simply define some modules and pass them\nto a microgrid:\n```python\nimport numpy as np\nfrom pymgrid import Microgrid\nfrom pymgrid.modules import GensetModule, BatteryModule, LoadModule, RenewableModule\n\n\ngenset = GensetModule(running_min_production=10,\n                      running_max_production=50,\n                      genset_cost=0.5)\n\nbattery = BatteryModule(min_capacity=0,\n                        max_capacity=100,\n                        max_charge=50,\n                        max_discharge=50,\n                        efficiency=1.0,\n                        init_soc=0.5)\n\n# Using random data\nrenewable = RenewableModule(time_series=50*np.random.rand(100))\n\nload = LoadModule(time_series=60*np.random.rand(100),\n                  loss_load_cost=10)\n\nmicrogrid = Microgrid([genset, battery, (\"pv\", renewable), load])\n```\n\nThis creates a microgrid with the modules defined above, as well as an unbalanced energy module -- \nwhich reconciles situations when energy demand cannot be matched to supply.\n\nPrinting the microgrid gives us its architecture:\n\n```python\n\u003e\u003e microgrid\n\nMicrogrid([genset x 1, load x 1, battery x 1, pv x 1, balancing x 1])\n```\n\nA microgrid is contained of fixed modules and flex modules. Some modules can be both -- `GridModule`, for example\n-- but not at the same time.\n\n\nA *fixed* module has requires a request of a certain amount of energy ahead of time, and then attempts to \nproduce or consume said amount. `LoadModule` is an example of this; you must tell it to consume a certain amount of energy\nand it will then do so.\n\n A *flex* module, on the other hand, is able to adapt to meet demand. `RenewableModule` is an example of this as\n it allows for curtailment of any excess renewable produced.\n \n A microgrid will tell you which modules are which:\n \n ```python\n\u003e\u003e microgrid.fixed_modules\n\n{\n  \"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)]\",\n  \"load\": \"[LoadModule(time_series=\u003cclass 'numpy.ndarray'\u003e, loss_load_cost=10, forecaster=NoForecaster, forecast_horizon=0, forecaster_increase_uncertainty=False, raise_errors=False)]\",\n  \"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)]\"\n}\n\n\u003e\u003emicrogrid.flex_modules\n\n{\n  \"pv\": \"[RenewableModule(time_series=\u003cclass 'numpy.ndarray'\u003e, raise_errors=False, forecaster=NoForecaster, forecast_horizon=0, forecaster_increase_uncertainty=False, provided_energy_name=renewable_used)]\",\n  \"balancing\": \"[UnbalancedEnergyModule(raise_errors=False, loss_load_cost=10, overgeneration_cost=2)]\"\n}\n\n```\n\n\nRunning the microgrid is straightforward. Simply pass an action for each fixed module to `microgrid.run`. The microgrid\ncan also provide you a random action by calling `microgrid.sample_action.` Once the microgrid has been run for a\ncertain number of steps, results can be viewed by calling microgrid.get_log.\n\n```python\n\u003e\u003e for j in range(10):\n\u003e\u003e    action = microgrid.sample_action(strict_bound=True)\n\u003e\u003e    microgrid.run(action)\n\n\u003e\u003e microgrid.get_log(drop_singleton_key=True)\n\n      genset  ...                     balance\n      reward  ... fixed_absorbed_by_microgrid\n0  -5.000000  ...                   10.672095\n1 -14.344353  ...                   50.626726\n2  -5.000000  ...                   17.538018\n3  -0.000000  ...                   15.492778\n4  -0.000000  ...                   35.748724\n5  -0.000000  ...                   30.302300\n6  -5.000000  ...                   36.451662\n7  -0.000000  ...                   66.533872\n8  -0.000000  ...                   20.645077\n9  -0.000000  ...                   10.632957\n```\n\n## Benchmarking\n\n`pymgrid` also comes pre-packaged with a set of 25 microgrids for benchmarking.\nThe config files for these microgrids are available in `data/scenario/pymgrid25`.\nSimply deserialize one of the yaml files to load one of the saved microgrids; for example,\nto load the zeroth microgrid:\n\n```python\nimport yaml\nfrom pymgrid import PROJECT_PATH\n\nyaml_file = PROJECT_PATH / 'data/scenario/pymgrid25/microgrid_0/microgrid_0.yaml'\nmicrogrid = yaml.safe_load(yaml_file.open('r'))\n```\n\nAlternatively, `Microgrid.load(yaml_file.open('r'))` will perform the same deserialization.\n\n\n## Citation\n\nIf you use this package for your research, please cite the following paper:\n\n@misc{henri2020pymgrid,\n      title={pymgrid: An Open-Source Python Microgrid Simulator for Applied Artificial Intelligence Research}, \n      author={Gonzague Henri, Tanguy Levent, Avishai Halev, Reda Alami and Philippe Cordier},\n      year={2020},\n      eprint={2011.08004},\n      archivePrefix={arXiv},\n      primaryClass={cs.AI}\n}\n\nYou can find it on Arxiv here: https://arxiv.org/abs/2011.08004\n\n## Data\n\nData 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)\n\nThe CO2 data is from Jacque de Chalendar and his gridemissions API.\n\n## Contributing\nPull requests are welcome for bug fixes. For new features, please open an issue first to discuss what you would like to add.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\nThis repo is under a GNU LGPL 3.0 (https://github.com/total-sa/pymgrid/edit/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotal-rd%2Fpymgrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftotal-rd%2Fpymgrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotal-rd%2Fpymgrid/lists"}