From cb70bf6b237518d8388c20db1979e4b9edb4e314 Mon Sep 17 00:00:00 2001 From: Mike Trzaska <76908324+HokageM@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:28:06 +0100 Subject: [PATCH] feat: flake8 Job (#13) * feat: Pylint Job * only test for python 3.10 * Move direct scirpts out of src * use flake8 * set max line length to 120 * fixe format --- .github/workflows/flake8.yml | 23 +++++++++++++++++++ .../direct_train_deep_max_entropy_irl.py | 2 +- .../direct_train_deep_max_entropy_rl.py | 0 setup.cfg | 2 +- src/irlwpython/MaxEntropyIRL.py | 4 ++-- src/irlwpython/main.py | 3 ++- 6 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/flake8.yml rename {src/irlwpython/scripts => scripts}/direct_train_deep_max_entropy_irl.py (99%) rename {src/irlwpython/scripts => scripts}/direct_train_deep_max_entropy_rl.py (100%) diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml new file mode 100644 index 0000000..f7c2a87 --- /dev/null +++ b/.github/workflows/flake8.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 + - name: Analysing the code with flake8 + run: | + flake8 $(git ls-files 'src/**.py') diff --git a/src/irlwpython/scripts/direct_train_deep_max_entropy_irl.py b/scripts/direct_train_deep_max_entropy_irl.py similarity index 99% rename from src/irlwpython/scripts/direct_train_deep_max_entropy_irl.py rename to scripts/direct_train_deep_max_entropy_irl.py index 212a7e8..eddd8cd 100644 --- a/src/irlwpython/scripts/direct_train_deep_max_entropy_irl.py +++ b/scripts/direct_train_deep_max_entropy_irl.py @@ -124,7 +124,7 @@ def get_demonstrations(self, env): env_high = env.observation_space.high env_distance = (env_high - env_low) / self.one_feature - raw_demo = np.load(file="../expert_demo/expert_demo.npy") + raw_demo = np.load(file="../src/irlwpython/expert_demo/expert_demo.npy") demonstrations = np.zeros((len(raw_demo), len(raw_demo[0]), 3)) for x in range(len(raw_demo)): for y in range(len(raw_demo[0])): diff --git a/src/irlwpython/scripts/direct_train_deep_max_entropy_rl.py b/scripts/direct_train_deep_max_entropy_rl.py similarity index 100% rename from src/irlwpython/scripts/direct_train_deep_max_entropy_rl.py rename to scripts/direct_train_deep_max_entropy_rl.py diff --git a/setup.cfg b/setup.cfg index b390e37..28d9d26 100644 --- a/setup.cfg +++ b/setup.cfg @@ -112,7 +112,7 @@ formats = bdist_wheel [flake8] # Some sane defaults for the code style checker flake8 -max_line_length = 88 +max_line_length = 120 extend_ignore = E203, W503 # ^ Black-compatible # E203 and W503 have edge cases handled by black diff --git a/src/irlwpython/MaxEntropyIRL.py b/src/irlwpython/MaxEntropyIRL.py index a692377..58d50d8 100644 --- a/src/irlwpython/MaxEntropyIRL.py +++ b/src/irlwpython/MaxEntropyIRL.py @@ -5,7 +5,6 @@ # import numpy as np -import matplotlib.pyplot as plt from irlwpython.FigurePrinter import FigurePrinter @@ -135,7 +134,8 @@ def train(self, theta_learning_rate, episode_count=30000): score_avg = np.mean(scores) print('{} episode score is {:.2f}'.format(episode, score_avg)) self.printer.save_plot_as_png(episodes, scores, - f"src/irlwpython/learning_curves/maxent_{episode_count}_{episode}_qtable.png") + f"src/irlwpython/learning_curves/" + f"maxent_{episode_count}_{episode}_qtable.png") self.printer.save_heatmap_as_png(learner.reshape((20, 20)), f"src/irlwpython/heatmap/learner_{episode}_flat.png") self.printer.save_heatmap_as_png(self.theta.reshape((20, 20)), diff --git a/src/irlwpython/main.py b/src/irlwpython/main.py index c04cb1b..91721e8 100644 --- a/src/irlwpython/main.py +++ b/src/irlwpython/main.py @@ -32,7 +32,8 @@ def parse_args(args): version=f"IRLwPython {__version__}", ) parser.add_argument('algorithm', metavar='ALGORITHM', type=str, - help='Currently supported training algorithm: [max-entropy, max-entropy-deep, max-entropy-deep-rl]') + help='Currently supported training algorithm: ' + '[max-entropy, max-entropy-deep, max-entropy-deep-rl]') parser.add_argument('--training', action='store_true', help="Enables training of model.") parser.add_argument('--testing', action='store_true', help="Enables testing of previously created model.")