From dca9de38c34a3af9e8fcd952cc9f91919524cc88 Mon Sep 17 00:00:00 2001 From: Florian Felten Date: Thu, 17 Oct 2024 09:49:25 +0200 Subject: [PATCH] pre-commit --- momaland/envs/__init__.py | 1 + momaland/envs/beach/mobeach_v0.py | 1 + momaland/envs/breakthrough/breakthrough.py | 1 + momaland/envs/breakthrough/mobreakthrough_v0.py | 1 + momaland/envs/connect4/connect4.py | 1 + momaland/envs/connect4/moconnect4_v0.py | 1 + momaland/envs/crazyrl/catch/catch_v0.py | 1 + momaland/envs/crazyrl/crazyRL_base.py | 1 + momaland/envs/crazyrl/escort/escort_v0.py | 1 + momaland/envs/crazyrl/gl_utils.py | 1 + momaland/envs/crazyrl/surround/surround.py | 1 + momaland/envs/crazyrl/surround/surround_v0.py | 1 + momaland/envs/gem_mining/mogem_mining_v0.py | 1 + momaland/envs/ingenious/ingenious.py | 8 +++++--- momaland/envs/ingenious/ingenious_check.py | 16 +++++++++++++--- momaland/envs/ingenious/moingenious_v0.py | 1 + .../envs/item_gathering/moitem_gathering_v0.py | 1 + .../momultiwalker_stability_v0.py | 1 + momaland/envs/route_choice/moroute_choice_v0.py | 1 + momaland/envs/route_choice/networks/utils.py | 1 + momaland/envs/samegame/mosame_game_v0.py | 1 + momaland/learning/iql/pf_bpd.py | 1 + momaland/learning/iql/train_iql_bpd.py | 1 + momaland/learning/iql/train_iql_route_choice.py | 1 + momaland/test/wrapper_test.py | 1 + momaland/utils/aec_wrappers.py | 1 + momaland/utils/env.py | 1 + momaland/utils/parallel_wrappers.py | 1 + pyproject.toml | 1 - 29 files changed, 44 insertions(+), 7 deletions(-) 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/pyproject.toml b/pyproject.toml index defbff9a..98ae9df4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,6 @@ momaland = [ # Linters and Test tools ####################################################### [tool.black] -safe = true line-length = 127 target-version = ['py38', 'py39', 'py310', 'py311'] include = '\.pyi?$'