Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs #151

Merged
merged 34 commits into from
Nov 24, 2022
Merged

Docs #151

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2478d84
clean up arg in modules
ahalev Nov 19, 2022
8f184ba
add Microgrid docstring
ahalev Nov 19, 2022
5583f1b
remove traceback in modularmicrogrid attributeerrors
ahalev Nov 19, 2022
6de7de6
clean up get_forecaster docstring
ahalev Nov 19, 2022
e09fa7d
better GridModule docstring
ahalev Nov 19, 2022
07321b5
allow accessing values by keys in module pointers
ahalev Nov 19, 2022
a95ec82
clean up _ModuleSubContainer
ahalev Nov 19, 2022
2315fa0
add docs
ahalev Nov 19, 2022
39d1071
update setup.py for docs
ahalev Nov 22, 2022
3127488
add pymgrid import to conf.py
ahalev Nov 22, 2022
2dc09f0
copyright total
ahalev Nov 22, 2022
db88d48
add version link
ahalev Nov 22, 2022
0dc2b11
use pydata theme
ahalev Nov 22, 2022
c403929
update index.rst
ahalev Nov 22, 2022
fc5b271
update modular microgrid docstring
ahalev Nov 22, 2022
745f0c5
add getting started
ahalev Nov 22, 2022
7ce6a6f
add reference docs
ahalev Nov 22, 2022
e93eeb1
add empty examples docs
ahalev Nov 22, 2022
c943df4
add autosummary to autodocs
ahalev Nov 23, 2022
eaf6471
add ability to exclude class methods from docs
ahalev Nov 23, 2022
1d389fb
update index tree
ahalev Nov 23, 2022
182ea82
add microgrid rst file
ahalev Nov 23, 2022
ee36e2b
add modules index rst file
ahalev Nov 23, 2022
53f3168
add autosummary templates
ahalev Nov 23, 2022
5201d82
update location of module autosummaries
ahalev Nov 23, 2022
a452424
ignore autogen autosummaries
ahalev Nov 23, 2022
363989a
change some grid methods to properties
ahalev Nov 24, 2022
163919f
fix grid module docstring
ahalev Nov 24, 2022
e21e220
change get_bounds() to _get_bounds()
ahalev Nov 24, 2022
260b492
fix doc in microgrid
ahalev Nov 24, 2022
52ff59a
add autodoc exclusions to microgrid
ahalev Nov 24, 2022
09c67fb
add microgrid docstrings
ahalev Nov 24, 2022
cb57146
fix indentation
ahalev Nov 24, 2022
d530b31
fix comment indentation
ahalev Nov 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parts/
sdist/
var/
wheels/
docs/source/reference/api/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
5 changes: 5 additions & 0 deletions docs/source/_templates/autosummary/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ objname | escape | underline }}

.. currentmodule:: {{ module }}

.. auto{{ objtype }}:: {{ objname }}
34 changes: 34 additions & 0 deletions docs/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

{% block methods %}

{% if methods %}
.. rubric:: {{ _('Methods') }}

.. autosummary::
:toctree: generated/

{% for item in methods %}
{% if item != "__init__" %}
~{{ name }}.{{ item }}
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
:toctree: generated/

{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
68 changes: 68 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent.parent))

import pymgrid

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'pymgrid'
copyright = '2022, TotalEnergies'
author = 'Avishai Halev'
release = pymgrid.__version__
version = pymgrid.__version__

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.duration',
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.autosummary',
# 'sphinx.ext.napoleon',
'sphinx.ext.doctest'
]

templates_path = ['_templates']
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'pydata_sphinx_theme'

html_theme_options = {
"primary_sidebar_end": ["indices.html", "sidebar-ethical-ads.html"]
}

html_static_path = ['_static']


def autodoc_skip_member(app, what, name, obj, skip, options):

if what != 'method':
return None

try:
exclusions = obj.__self__.__autodoc_exclusions__
except AttributeError: # not a method of an object, or object has no attribute '__autodoc_exclusions__'
return None

if name in exclusions:
return True

return None


def setup(app):
app.connect('autodoc-skip-member', autodoc_skip_member)
4 changes: 4 additions & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Examples
========

This page is under development.
40 changes: 40 additions & 0 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Getting Started
===============

.. _installation:

Installation
------------

The easiest way to install *pymgrid* is with pip:

.. code-block:: console

$ pip install -U pymgrid

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

.. code-block:: bash

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

Then navigate to the root directory of pymgrid and call

.. code-block:: bash

$ pip install .

Advanced Installation
---------------------

To use the included model predictive control algorithm <link> on microgrids containing gensets,
additional dependencies are required as the optimization problem becomes mixed integer.

The packages MOSEK and CVXOPT can both handle this case; you can install both by calling

.. code-block:: bash

$ pip install pymgrid[genset_mpc]

Note that MOSEK requires a license; see https://www.mosek.com/ for details.
Academic and trial licenses are available.
51 changes: 51 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. pymgrid documentation master file, created by
sphinx-quickstart on Sat Nov 19 12:49:18 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

*********************
pymgrid documentation
*********************

**Version**: |version|

*pymgrid* is a Python library to simulate tertiary control of electrical microgrids. *pymgrid* allows
users to create and customize microgrids of their choosing. These microgrids can then be controlled using a user-defined
algorithm or one of the control algorithms contained in *pymgrid*: rule-based control and model predictive control.

Environments corresponding to the OpenAI-Gym API are also provided, with both continuous and discrete action space
environments available. These environments can be used with your choice of reinforcement learning algorithm to train
a control algorithm.

*pymgrid* attempts to offer the simplest and most intuitive API possible, allowing the user to
focus on their particular application.

See the :doc:`getting_started` section for further information, including instructions on how to
:ref:`install <installation>` the project.

**Useful links**:
`Binary Installers <https://pypi.org/project/pymgrid/>`__ |
`Source Repository <https://github.com/Total-RD/pymgrid>`__


.. note::

This project is under active development.

Contents
========

.. toctree::
:maxdepth: 3

getting_started
reference/index
examples/index


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
10 changes: 10 additions & 0 deletions docs/source/reference/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
API reference
=============

This page contains an overview of all public *pymgrid* objects and functions.

.. toctree::
:maxdepth: 2

microgrid
modules/index
40 changes: 40 additions & 0 deletions docs/source/reference/microgrid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _api.microgrid:


Microgrid
=================

.. currentmodule:: pymgrid

Constructor
-----------
.. autosummary::
:toctree: api/microgrid/

Microgrid

Methods
-------
.. autosummary::

:toctree: api/microgrid/

Microgrid.run
Microgrid.reset
Microgrid.sample_action
Microgrid.get_log
Microgrid.get_forecast_horizon
Microgrid.get_empty_action

Serialization/IO/Conversion
---------------------------
.. autosummary::

:toctree: api/microgrid/

Microgrid.load
Microgrid.dump
Microgrid.from_nonmodular
Microgrid.from_scenario
Microgrid.serialize
Microgrid.to_nonmodular
44 changes: 44 additions & 0 deletions docs/source/reference/modules/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. _api.modules:

Modules
=======

.. currentmodule:: pymgrid.modules

The modules defined here are commonly found in microgrids.
Pass any combination of modules to :ref:`Microgrid <api.microgrid>` to define and run a microgrid.

Timeseries Modules
------------------

Modules that are temporal in nature.



.. autosummary::
:toctree: ../api/modules/

GridModule
LoadModule
RenewableModule

Non-temporal Modules
-------------

Modules that do not depend on an underlying timeseries.

.. autosummary::
:toctree: ../api/modules/

BatteryModule
GensetModule

Helper Module
--------------

A module that cleans up after all the other modules are deployed.

.. autosummary::
:toctree: ../api/modules/

UnbalancedEnergyModule
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@

EXTRAS = dict()
EXTRAS["genset_mpc"] = ["Mosek", "cvxopt"]
EXTRAS["dev"] = ["pytest", "flake8", *EXTRAS["genset_mpc"]]
EXTRAS["dev"] = [
"pytest",
"flake8",
"sphinx",
"pydata_sphinx_theme",
"numpydoc",
*EXTRAS["genset_mpc"]]
EXTRAS["all"] = list(set(sum(EXTRAS.values(), [])))


Expand Down
Loading