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

(v3.5.11a) - Fix compilation documentation workflow #447

Merged
merged 9 commits into from
Sep 19, 2024
1 change: 1 addition & 0 deletions .github/workflows/create_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
- name: Install dependencies
if: steps.verify-documentation-update.outputs.doc == 'true'
run: |
sudo apt install python3-enchant
sudo apt install pandoc
pip install -e .[doc]
- name: Check build docs
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/merge_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ jobs:
- name: Install dependencies
if: steps.verify-documentation-update.outputs.doc == 'true'
run: |
sudo apt install python3-enchant
sudo apt install pandoc
pip install -e .[doc]
- name: Build multiversion docs
if: steps.verify-documentation-update.outputs.doc == 'true'
run: sphinx-multiversion docs/source docs/compilation
- name: Deploy to GitHub Pages
if: steps.verify-documentation-update.outputs.doc == 'true'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "[email protected]"
git add docs/compilation
git commit -m "Deploy documentation to GitHub Pages"
git push --force origin `git subtree split --prefix build main`:github-pages
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/compilation
publish_branch: github-pages
keep_files: false

tests:
needs: [apply-autopep8]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ start_mlflow_tracking.sh
# Source docs _build directory generation using RST preview in Visual Studio Code
docs/source/_build/
docs/build/
docs/compilation/

#dist folder for pypi packages
dist/
Expand Down
21 changes: 8 additions & 13 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import sinergym.utils.logger
import os
import sys
from unittest.mock import MagicMock

sys.path.insert(0, os.path.abspath('../../sinergym'))


class WandBOutputFormatMock(MagicMock):
pass


sinergym.utils.logger.WandBOutputFormat = WandBOutputFormatMock

# -- Project information -----------------------------------------------------

project = 'sinergym'
project = 'Sinergym'
copyright = '2024, J. Jiménez, J. Gómez, M. Molina, A. Manjavacas, A. Campoy'
author = 'J. Jiménez, J. Gómez, M.l Molina, A. Manjavacas, A. Campoy'

Expand All @@ -50,9 +41,13 @@ class WandBOutputFormatMock(MagicMock):
'nbsphinx_link']

autodoc_mock_imports = ['stable_baselines3',
'wandb',
'gym',
'opyplus',
'gcloud',
'googleapiclient',
'oauth2client',
'google',
'google.cloud',
'pyenergyplus']

Expand All @@ -65,7 +60,7 @@ class WandBOutputFormatMock(MagicMock):

# VERSIONING configuration
# Whitelist pattern for tags (set to None to ignore all tags)
smv_tag_whitelist = r'^.*0$'
smv_tag_whitelist = r'^v\d+\.\d+\.0$'
# smv_tag_whitelist = None

# Whitelist pattern for branches (set to None to ignore all branches)
Expand All @@ -76,7 +71,7 @@ class WandBOutputFormatMock(MagicMock):
smv_remote_whitelist = None

# Pattern for released versions
smv_released_pattern = r'^tags/.+?0$'
smv_released_pattern = r'^tags/v\d+\.\d+\.0$'

# Format for versioned output directories inside the build directory
smv_outputdir_format = '{ref.name}'
Expand Down Expand Up @@ -121,7 +116,7 @@ class WandBOutputFormatMock(MagicMock):
html_sidebars = {'**': ['globaltoc.html',
'relations.html',
'sourcelink.html',
'searchbox.html', ]}
'searchbox.html']}

# disable nbsphinx errors to suppres imports checks not working
nbsphinx_allow_errors = True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sinergym.utils.logger.WandBOutputFormat
=======================================

.. currentmodule:: sinergym.utils.logger

.. autoclass:: WandBOutputFormat
:members:
:undoc-members:


.. automethod:: __init__


.. rubric:: Methods

.. autosummary::

~WandBOutputFormat.__init__
~WandBOutputFormat.write






1 change: 1 addition & 0 deletions docs/source/pages/modules/sinergym.utils.logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SimpleLogger
TerminalLogger
TqdmLoggingHandler
WandBOutputFormat



Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ pandas
twine
xlsxwriter
pipdeptree
wandb
tqdm
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'matplotlib', # visualization
# DRL with pytorch
'stable-baselines3',
'wandb', # logging
'pytest',
'pytest-cov',
'pytest-xdist', # Unit test repository
Expand All @@ -47,6 +48,7 @@
'pytest',
'pytest-cov',
'pytest-xdist',
'wandb',
],
'DRL': [
'stable-baselines3',
Expand Down
18 changes: 9 additions & 9 deletions sinergym/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
from typing import Any, Dict, List, Tuple, Union

import numpy as np
import pkg_resources
from tqdm import tqdm

from sinergym.utils.constants import LOG_FORMAT

required = {'stable-baselines3', 'wandb'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed
if not missing:
import wandb
from stable_baselines3.common.logger import KVWriter


class CustomFormatter(logging.Formatter):
"""Custom logger format for terminal messages"""
Expand Down Expand Up @@ -206,7 +198,9 @@ def reset_data(self) -> None:
self.custom_metrics = []


if not missing:
try:
import wandb
from stable_baselines3.common.logger import KVWriter
class WandBOutputFormat(KVWriter): # pragma: no cover
"""
Dumps key / value pairs onto WandB. This class is based on SB3 used in logger callback
Expand Down Expand Up @@ -249,3 +243,9 @@ def write(

# Log all metrics
wandb.log(metrics_to_log)
except ImportError:
class WandBOutputFormat():
"""WandBOutputFormat class for logging in WandB from SB3 logger.
"""
def __init__(self):
print('WandB or SB3 is not installed. Please install it to use WandBOutputFormat.')
2 changes: 1 addition & 1 deletion sinergym/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.11
3.5.11a
Loading