diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index 5840d6bf..e29ddf3b 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -23,11 +23,9 @@ jobs: - uses: actions/setup-python@v5 - name: Install dependencies - run: python -m pip install --upgrade pip setuptools build - + run: pipx install build - name: Build sdist and wheels - run: python -m build - + run: pyproject-build - name: Store wheels uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 80ce02af..9f2cc2ab 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,9 +13,7 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - - run: python -m pip install pre-commit - - run: python -m pre_commit --version - - run: python -m pre_commit install - - run: python -m pre_commit run --all-files + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - run: pipx install pre-commit + - run: pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8770dabb..615a9b06 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-symlinks - id: destroyed-symlinks @@ -17,13 +17,13 @@ repos: - id: detect-private-key - id: debug-statements - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell args: - --ignore-words-list=reacher, mor, nowe - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.1.1 hooks: - id: flake8 args: @@ -34,16 +34,16 @@ repos: - --show-source - --statistics - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.18.0 hooks: - id: pyupgrade args: ["--py37-plus"] - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/python/black - rev: 23.9.1 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/pycqa/pydocstyle diff --git a/momaland/envs/__init__.py b/momaland/envs/__init__.py index 7368f5ac..d5e7e9c6 100644 --- a/momaland/envs/__init__.py +++ b/momaland/envs/__init__.py @@ -1,2 +1,3 @@ """Environment modules for momaland.""" + import momaland.envs.beach diff --git a/momaland/envs/beach/mobeach_v0.py b/momaland/envs/beach/mobeach_v0.py index 1f4491ac..5d3d012a 100644 --- a/momaland/envs/beach/mobeach_v0.py +++ b/momaland/envs/beach/mobeach_v0.py @@ -1,4 +1,5 @@ """Beach domain environment for multi-objective optimization.""" + from momaland.envs.beach.beach import env, parallel_env, raw_env diff --git a/momaland/envs/breakthrough/breakthrough.py b/momaland/envs/breakthrough/breakthrough.py index b88e866d..ff963b2b 100644 --- a/momaland/envs/breakthrough/breakthrough.py +++ b/momaland/envs/breakthrough/breakthrough.py @@ -11,6 +11,7 @@ | Observation Values | [0,1] | | Reward Shape | (num_objectives=4,) | """ + from __future__ import annotations from typing_extensions import override diff --git a/momaland/envs/breakthrough/mobreakthrough_v0.py b/momaland/envs/breakthrough/mobreakthrough_v0.py index 454c6826..3806c2e9 100644 --- a/momaland/envs/breakthrough/mobreakthrough_v0.py +++ b/momaland/envs/breakthrough/mobreakthrough_v0.py @@ -1,4 +1,5 @@ """Breakthrough environment with multiple objectives.""" + from momaland.envs.breakthrough.breakthrough import env, raw_env diff --git a/momaland/envs/connect4/connect4.py b/momaland/envs/connect4/connect4.py index a806de70..5b062199 100644 --- a/momaland/envs/connect4/connect4.py +++ b/momaland/envs/connect4/connect4.py @@ -11,6 +11,7 @@ | Observation Values | [0,1] | | Reward Shape | (2,) or (2+board_width,) | """ + from __future__ import annotations import os diff --git a/momaland/envs/connect4/moconnect4_v0.py b/momaland/envs/connect4/moconnect4_v0.py index ea487d3b..dd099a89 100644 --- a/momaland/envs/connect4/moconnect4_v0.py +++ b/momaland/envs/connect4/moconnect4_v0.py @@ -1,4 +1,5 @@ """Connect 4 environment with multiple objectives.""" + from momaland.envs.connect4.connect4 import env, raw_env diff --git a/momaland/envs/crazyrl/catch/catch_v0.py b/momaland/envs/crazyrl/catch/catch_v0.py index 86129fac..b58fd8ad 100644 --- a/momaland/envs/crazyrl/catch/catch_v0.py +++ b/momaland/envs/crazyrl/catch/catch_v0.py @@ -1,4 +1,5 @@ """CrazyRL/Catch environment for MOMARL.""" + from momaland.envs.crazyrl.catch.catch import env, parallel_env, raw_env diff --git a/momaland/envs/crazyrl/crazyRL_base.py b/momaland/envs/crazyrl/crazyRL_base.py index 5addf72c..d3135bd6 100644 --- a/momaland/envs/crazyrl/crazyRL_base.py +++ b/momaland/envs/crazyrl/crazyRL_base.py @@ -1,4 +1,5 @@ """The Base environment inheriting from pettingZoo Parallel environment class.""" + from copy import copy from typing import Optional from typing_extensions import override diff --git a/momaland/envs/crazyrl/escort/escort_v0.py b/momaland/envs/crazyrl/escort/escort_v0.py index 7d1005f4..e9a0a420 100644 --- a/momaland/envs/crazyrl/escort/escort_v0.py +++ b/momaland/envs/crazyrl/escort/escort_v0.py @@ -1,4 +1,5 @@ """CrazyRL/Escort environment for MOMARL.""" + from momaland.envs.crazyrl.escort.escort import env, parallel_env, raw_env diff --git a/momaland/envs/crazyrl/gl_utils.py b/momaland/envs/crazyrl/gl_utils.py index 057a59c2..666462a5 100644 --- a/momaland/envs/crazyrl/gl_utils.py +++ b/momaland/envs/crazyrl/gl_utils.py @@ -1,4 +1,5 @@ """Graphical representation of the UAV in 3D space. the reference is based on the Crazyflie position reference: https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/functional-areas/lighthouse/terminology_definitions/ .""" + import numpy as np from OpenGL.GL import ( GL_LINES, diff --git a/momaland/envs/crazyrl/surround/surround.py b/momaland/envs/crazyrl/surround/surround.py index 1b265144..dcd256dd 100644 --- a/momaland/envs/crazyrl/surround/surround.py +++ b/momaland/envs/crazyrl/surround/surround.py @@ -1,4 +1,5 @@ """Surround environment for Crazyflie 2. Each agent is supposed to learn to surround a common target point.""" + from typing_extensions import override import numpy as np diff --git a/momaland/envs/crazyrl/surround/surround_v0.py b/momaland/envs/crazyrl/surround/surround_v0.py index b0912ed0..53839e6b 100644 --- a/momaland/envs/crazyrl/surround/surround_v0.py +++ b/momaland/envs/crazyrl/surround/surround_v0.py @@ -1,4 +1,5 @@ """CrazyRL/Surround environment for MOMARL.""" + from momaland.envs.crazyrl.surround.surround import env, parallel_env, raw_env diff --git a/momaland/envs/gem_mining/mogem_mining_v0.py b/momaland/envs/gem_mining/mogem_mining_v0.py index b43fbb80..8e88e037 100644 --- a/momaland/envs/gem_mining/mogem_mining_v0.py +++ b/momaland/envs/gem_mining/mogem_mining_v0.py @@ -1,4 +1,5 @@ """Gem mining environment for multi-objective optimization.""" + from momaland.envs.gem_mining.gem_mining import env, parallel_env, raw_env diff --git a/momaland/envs/ingenious/ingenious.py b/momaland/envs/ingenious/ingenious.py index fbccf7ef..ac7ae4de 100644 --- a/momaland/envs/ingenious/ingenious.py +++ b/momaland/envs/ingenious/ingenious.py @@ -185,9 +185,11 @@ def __init__( "board": Box( 0, len(ALL_COLORS), shape=(2 * self.board_size - 1, 2 * self.board_size - 1), dtype=np.float32 ), - "racks": Box(0, self.num_colors, shape=(num_agents, self.init_draw, 2), dtype=np.int32) - if self.fully_obs - else Box(0, self.num_colors, shape=(self.init_draw, 2), dtype=np.int32), + "racks": ( + Box(0, self.num_colors, shape=(num_agents, self.init_draw, 2), dtype=np.int32) + if self.fully_obs + else Box(0, self.num_colors, shape=(self.init_draw, 2), dtype=np.int32) + ), "scores": Box(0, self.game.max_score, shape=(num_agents, self.num_colors), dtype=np.int32), } ), diff --git a/momaland/envs/ingenious/ingenious_check.py b/momaland/envs/ingenious/ingenious_check.py index 6295917a..92c186bb 100644 --- a/momaland/envs/ingenious/ingenious_check.py +++ b/momaland/envs/ingenious/ingenious_check.py @@ -343,7 +343,12 @@ def check_two_team(): ig_env.step(action) observation, reward, termination, truncation, _ = ig_env.last() print("Observations: ", observation["observation"]) - print("Rewards: ", reward, "_accumulate_reward(from gymnasium code)", ig_env._cumulative_rewards) + print( + "Rewards: ", + reward, + "_accumulate_reward(from gymnasium code)", + ig_env._cumulative_rewards, + ) print("Truncation: ", truncation) print("Termination: ", termination) done = truncation or termination @@ -372,7 +377,12 @@ def check_collaborative(): ig_env.step(action) observation, reward, termination, truncation, _ = ig_env.last() print("Observations: ", observation["observation"]) - print("Rewards: ", reward, "_accumulate_reward(from gymnasium code)", ig_env._cumulative_rewards) + print( + "Rewards: ", + reward, + "_accumulate_reward(from gymnasium code)", + ig_env._cumulative_rewards, + ) print("Truncation: ", truncation) print("Termination: ", termination) done = truncation or termination @@ -441,5 +451,5 @@ def check_parameter_range(): # check collaborative mode through simulation, it could be found that every players always share the same score in score board. check_collaborative() - # check parameter range by ramdom choose. + # check parameter range by random choice. check_parameter_range() diff --git a/momaland/envs/ingenious/moingenious_v0.py b/momaland/envs/ingenious/moingenious_v0.py index 7f82f262..99b8ca24 100644 --- a/momaland/envs/ingenious/moingenious_v0.py +++ b/momaland/envs/ingenious/moingenious_v0.py @@ -1,4 +1,5 @@ """Multi-objective Ingenious Game.""" + from momaland.envs.ingenious.ingenious import env, raw_env diff --git a/momaland/envs/item_gathering/moitem_gathering_v0.py b/momaland/envs/item_gathering/moitem_gathering_v0.py index b717faff..6e021292 100644 --- a/momaland/envs/item_gathering/moitem_gathering_v0.py +++ b/momaland/envs/item_gathering/moitem_gathering_v0.py @@ -1,4 +1,5 @@ """Item Gathering environment for multi-objective optimization.""" + from momaland.envs.item_gathering.item_gathering import env, parallel_env, raw_env diff --git a/momaland/envs/multiwalker_stability/momultiwalker_stability_v0.py b/momaland/envs/multiwalker_stability/momultiwalker_stability_v0.py index 994f4c25..24a3620c 100644 --- a/momaland/envs/multiwalker_stability/momultiwalker_stability_v0.py +++ b/momaland/envs/multiwalker_stability/momultiwalker_stability_v0.py @@ -1,4 +1,5 @@ """Multiwalker-Stability domain environment for MOMARL.""" + from momaland.envs.multiwalker_stability.momultiwalker_stability import ( env, parallel_env, diff --git a/momaland/envs/route_choice/moroute_choice_v0.py b/momaland/envs/route_choice/moroute_choice_v0.py index d1bfc3c3..59aa1cb2 100644 --- a/momaland/envs/route_choice/moroute_choice_v0.py +++ b/momaland/envs/route_choice/moroute_choice_v0.py @@ -1,4 +1,5 @@ """Route choice environment for multi-objective optimization.""" + from momaland.envs.route_choice.route_choice import env, parallel_env, raw_env diff --git a/momaland/envs/route_choice/networks/utils.py b/momaland/envs/route_choice/networks/utils.py index b2f89a4e..6c06334d 100644 --- a/momaland/envs/route_choice/networks/utils.py +++ b/momaland/envs/route_choice/networks/utils.py @@ -9,6 +9,7 @@ * "od": a list of possible origin-destination (OD) pairs in the network * "routes": a dictionary which contains routes for OD-pairs """ + import json import os diff --git a/momaland/envs/samegame/mosame_game_v0.py b/momaland/envs/samegame/mosame_game_v0.py index 16b3ed70..17c23adf 100644 --- a/momaland/envs/samegame/mosame_game_v0.py +++ b/momaland/envs/samegame/mosame_game_v0.py @@ -1,4 +1,5 @@ """Connect 4 environment with multiple objectives.""" + from momaland.envs.samegame.same_game import env, raw_env diff --git a/momaland/learning/iql/pf_bpd.py b/momaland/learning/iql/pf_bpd.py index 3c4b4945..44f57c69 100644 --- a/momaland/learning/iql/pf_bpd.py +++ b/momaland/learning/iql/pf_bpd.py @@ -6,6 +6,7 @@ - exp1: 50 agents, 5 sections, 3 capacity, type distribution [35, 15] - exp2: 100 agents, 5 sections, 5 capacity, type distribution [70, 30] """ + import argparse from itertools import product diff --git a/momaland/learning/iql/train_iql_bpd.py b/momaland/learning/iql/train_iql_bpd.py index 6fa5c722..4c9e3363 100644 --- a/momaland/learning/iql/train_iql_bpd.py +++ b/momaland/learning/iql/train_iql_bpd.py @@ -1,4 +1,5 @@ """Train IQL on the Beach Problem Domain, under linear scalarization, and save the results to a csv file.""" + import argparse import random import time diff --git a/momaland/learning/iql/train_iql_route_choice.py b/momaland/learning/iql/train_iql_route_choice.py index 219e1af1..9a3f3261 100644 --- a/momaland/learning/iql/train_iql_route_choice.py +++ b/momaland/learning/iql/train_iql_route_choice.py @@ -1,4 +1,5 @@ """Train IQL on the route choice problem domain, under linear scalarization, and save the results to a csv file.""" + import argparse import os import random diff --git a/momaland/test/wrapper_test.py b/momaland/test/wrapper_test.py index 06ae0ef9..a6b9d6ba 100644 --- a/momaland/test/wrapper_test.py +++ b/momaland/test/wrapper_test.py @@ -1,4 +1,5 @@ """Testing file for the wrappers.""" + import numpy as np import momaland.utils.aec_wrappers as AECWrappers diff --git a/momaland/utils/aec_wrappers.py b/momaland/utils/aec_wrappers.py index ebd161d2..b432eb9e 100644 --- a/momaland/utils/aec_wrappers.py +++ b/momaland/utils/aec_wrappers.py @@ -1,4 +1,5 @@ """Various wrappers for AEC MO environments.""" + from typing import Optional import numpy as np diff --git a/momaland/utils/env.py b/momaland/utils/env.py index 7eb90fce..d19ad7a8 100644 --- a/momaland/utils/env.py +++ b/momaland/utils/env.py @@ -1,4 +1,5 @@ """Overrides PZ types to enforce multi objective rewards.""" + import warnings from typing import Dict from typing_extensions import override diff --git a/momaland/utils/parallel_wrappers.py b/momaland/utils/parallel_wrappers.py index 51999d1f..806512f2 100644 --- a/momaland/utils/parallel_wrappers.py +++ b/momaland/utils/parallel_wrappers.py @@ -1,4 +1,5 @@ """Various wrappers for Parallel MO environments.""" + from collections import namedtuple from typing import Optional diff --git a/py.typed b/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/pyproject.toml b/pyproject.toml index 922b40a2..6009823f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,8 @@ learning = [ "tqdm >=4.66.1", "pandas >=2.0.3", "matplotlib >=3.7.4", - "morl_baselines[all]" + "morl_baselines[all]", + "pycddlib==2.1.6", ] all = [ # All dependencies above except accept-rom-license @@ -76,7 +77,8 @@ all = [ "tqdm >=4.66.1", "pandas >=2.0.3", "matplotlib >=3.7.4", - "morl_baselines[all]" + "morl_baselines[all]", + "pycddlib==2.1.6", ] testing = ["pytest ==7.1.3"] @@ -93,15 +95,15 @@ include-package-data = true include = ["momaland", "momaland.*"] [tool.setuptools.package-data] -mo_gymnasium = [ +momaland = [ "**/*.json", "**/assets/*", + "py.typed", ] # Linters and Test tools ####################################################### [tool.black] -safe = true line-length = 127 target-version = ['py38', 'py39', 'py310', 'py311'] include = '\.pyi?$'