Package: openmodelica-microgrid-gym
OpenModelica Microgrid GymThe OpenModelica Microgrid Gym (OMG) package is a software toolbox for the
simulation and control optimization of microgrids based on energy conversion by power electronic converters.The main characteristics of the toolbox are the plug-and-play grid design and simulation in OpenModelica as well as
the ready-to-go approach of intuitive reinfrocement learning (RL) approaches through a Python interface.The OMG toolbox is built upon theOpenAI Gymenvironment definition framework.
Therefore, the toolbox is specifically designed for running reinforcement
learning algorithms to train agents controlling power electronic converters in microgrids. Nevertheless, also arbritary classical control approaches can be combined and tested using the OMG interface.Free software: GNU General Public License v3Documentation:https://upb-lea.github.io/openmodelica-microgrid-gymVideo TutorialFollowing is a short YouTube video introduction, to get a fist impression how to use OMG.https://www.youtube.com/watch?v=rwBNFvCi_dYInstallationInstall Python EnvironmentThis is the short installation guide for Windows and Linux.OpenModelicais hardly supported for Mac, they suggest to install in a Linux VM. For this reason, running OMG in a Linux VM is strongly recommended for Mac users!Since it is not possible to installPyFMI, a package which is necessary for the communication between the python interface and the environment, via pip, we recommend to install this package in advance in a conda environment.
As of now, only Windows and Linux are supported officially.If conda is NOT installed on your PC, installminicondafor python 3.8Create a new conda environment (e.g. in PyCharm)Install PyFMI from the conda-forge channel in the terminal:$ conda install -c conda-forge pyfmiInstall OpenModelica MicrogridGym from PyPI (recommended):$ pip install openmodelica_microgrid_gymInstallation of OpenModelicaOMG was create by usingOMEditv1.16In case of installation issues you can resort to their pre-builtvirtual machine.Getting startedThe environment is initialized and run like any other OpenAI Gymimportgymif__name__=='__main__':env=gym.make('openmodelica_microgrid_gym:ModelicaEnv-v1',max_episode_steps=None,net='../net/net.yaml',model_path='../omg_grid/grid.network.fmu')env.reset()for_inrange(1000):env.render()env.step(env.action_space.sample())# take a random actionenv.close()OMG uses theFMI standardfor the exchange of the model between OpenModelica and Python.An example network consisting out of two inverters, three filters and an inductive load.You can either use one of the provided FMUs (Windows and Linux, 64-bit, both included in the grid.network.fmu) or create your own by running:openmodelica_microgrid_gym\fmu> omc create_fmu.mosWindows users might need to open the terminal out of OpenModelica by clicking ‘tools’ => ‘OpenModelica Command Prompt’ to make sure that the command ‘omc’ gets recognized.Running thestaticctrl.pystarts a simulation with a manually tuned cascaded PIPI controllerA save Bayesian approach of a reinforcement learning agent is provided under examples/berkamkamp.py.Using pytestOMG provides a big range of tests to ensure correct working toolbox after changes are done.
On some windows machines, the tests can only be started from the terminal via ‘pytest’.The standard test OS for the development is Linux. In some cases, we have noticed that the test_modelica.py on windows PCs might throw an error.
Since on Linux everything works fine, it seems to be a numerical issue connected with the FMUs.Citation & white paperPlease find a white paper on the OMG toolbox including an exemplary usage scenario here:https://arxiv.org/abs/2005.04869Please use the following BibTeX entry for citing us:@article{OMG-code2020,
    title = {OMG: A Scalable and Flexible Simulation and Testing Environment Toolbox for Intelligent Microgrid Control},
    author = {Stefan Heid and Daniel Weber and Henrik Bode and Eyke Hüllermeier and Oliver Wallscheid},
    year = {2020},
    doi = {10.21105/joss.02435},
    url = {https://doi.org/10.21105/joss.02435},
    publisher = {The Open Journal},
    volume = {5},
    number = {54},
    pages = {2435},
    journal = {Journal of Open Source Software}
}

@article{OMG-whitepaper2020,
    title={Towards a Scalable and Flexible Simulation and
           Testing Environment Toolbox for Intelligent Microgrid Control},
    author={Henrik Bode and Stefan Heid and Daniel Weber and Eyke Hüllermeier and Oliver Wallscheid},
    year={2020},
    eprint={http://arxiv.org/abs/2005.04869},
    archivePrefix={arXiv},
    primaryClass={eess.SY}
}ContributingPlease refer to thecontribution guide.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.HistoryNext0.4.0 (2021-04-07)ChangesModelicaEnv:Introduced action clippingmodel_params: None values are not passed to the OpenModelica env to allow initializationmodel_params: negative time values are introduced for initialization (fix)Introduced abort reward in env if episode is terminatedIntroduced obs_output to define a subset of history given as observation to the agentFixomg.net.MasterInverter:default values used to overwrite passed valuesAddRandom Process wrapperObsTempl testreset test for initialized env0.3.0 (2020-12-18)APIModelicaEnv:Uses Network__init__:
- removed: timestep, model_output, model_input
- added: networkDelay bufferNetwork and Components:Specify class structure using config file corresponding to fmu (see net-folder)added noiseSafeoptAgent:__init__: Performance parameters and calculationaux_ctl.Contoller:__init__: timestep and undersampling changedadded output clippingPlotmanagerExamplesupdated to changed APIExperimentsmodel validation:experiment filesexperiment environment managing testbench connection via SSHDependenciesDecreased Language Level to Python 3.70.2.0 (2020-05-27)APIModelicaEnv:reward function parametervis_cols now also supports Plotting templatesEmptyHistory and descendant: update(), append()Agent: added propertiesStaticControlAgent and descendant: small changes in constructor params, specifically obs_template, added propertiesSafeOptAgent: added propertiesRunner: plotting can be disabledExamplesadded example for plottingPerformance6.6× speedupDependenciesIncreased Language Level to Python 3.80.1.3 (2020-05-13)best parameter set output after termination of SafeOpt agent (#7)proper action and observation space (#14)resolved problem related to environmentmodel_params(#21)documentation improvements (more examples, installation)0.1.2 (2020-05-04)corrected pip install requirements0.1.1 (2020-04-22)First release on PyPI.