pymgrid (PYthon MicroGRID) is a python library to generate and simulate a large number of microgrids.
Use the package manager pip to install pymgrid. You can clone and cd in the repo and then do:
pip install .
You can also run this pip command:
pip install git+https://github.com/Total-RD/pymgrid/
And in Google Colab:
!pip install git+https://github.com/Total-RD/pymgrid/
You can easily import the library from pip, and then import MicrogridGenerator from pymgrid.
from pymgrid import MicrogridGenerator as mg
m_gen=mg.MicrogridGenerator()
m_gen.generate_microgrid()
By default, this command will let you generate 10 microgrids. The object m_gen will have a list of microgrids that you can use.
First, you can get the control information with this command:
m_gen.microgrids[0].get_control_info()
pymgrid contains OpenAI Gym environments, you can use the following command to generate one:
from pymgrid.Environments.pymgrid_cspla import MicroGridEnv
from pymgrid import MicrogridGenerator as m_gen
#these line will create a list of microgrid
env = m_gen.MicrogridGenerator(nb_microgrid=25)
pymgrid25 = env.load('pymgrid25')
mg = pymgrid25.microgrids
#you can pass any of the microgrid to environment class:
env = MicroGridEnv({'microgrid':mg[0]})
#example of codes to to interact with the environment:
episode_reward = 0
done = False
obs = env.reset()
while not done:
action = #your algorithm to select the next action
obs, reward, done, info = env.step(action)
episode_reward += reward
The control_dict dictionnary it the main way you will interact with the microgrid class. It