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

Update Python version and refactor dataclass fields with installed packages list #72

Merged
merged 12 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For 2. follow the instructions below:

### Local Installation

Install python >= 3.8 and <= 3.12.
Install python >= 3.9 and <= 3.12.

```sh
sudo apt-get update && sudo apt-get install -y python3.12 python3-pip
Expand Down
2 changes: 1 addition & 1 deletion fast-pysf
90 changes: 90 additions & 0 deletions installed_packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
absl-py==2.1.0
ale-py==0.10.1
alembic==1.14.0
annotated-types==0.7.0
astroid==3.3.5
certifi==2024.8.30
charset-normalizer==3.4.0
click==8.1.7
cloudpickle==3.1.0
colorlog==6.9.0
contourpy==1.3.1
cycler==0.12.1
dill==0.3.9
docker-pycreds==0.4.0
Farama-Notifications==0.0.4
filelock==3.16.1
fonttools==4.55.0
fsspec==2024.10.0
gitdb==4.0.11
GitPython==3.1.43
grpcio==1.68.0
gym==0.26.2
gym-notices==0.0.8
gymnasium==1.0.0
idna==3.10
iniconfig==2.0.0
isort==5.13.2
Jinja2==3.1.4
kiwisolver==1.4.7
llvmlite==0.43.0
loguru==0.7.2
Mako==1.3.6
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==3.0.2
matplotlib==3.9.2
mccabe==0.7.0
mdurl==0.1.2
mpmath==1.3.0
networkx==3.4.2
numba==0.60.0
numpy==1.26.4
opencv-python==4.10.0.84
optuna==4.1.0
packaging==24.2
pandas==2.2.3
pillow==11.0.0
platformdirs==4.3.6
pluggy==1.5.0
protobuf==5.28.3
psutil==6.1.0
pydantic==2.9.2
pydantic_core==2.23.4
pygame==2.6.1
Pygments==2.18.0
pylint==3.3.1
pyparsing==3.2.0
-e git+https://github.com/ll7/pysocialforce-ll7@eebf30ed30893ae5628e3f123439af03de6402e1#egg=PySocialForce&subdirectory=../../fast-pysf
ll7 marked this conversation as resolved.
Show resolved Hide resolved
pytest==8.3.3
python-dateutil==2.9.0.post0
pytz==2024.2
PyYAML==6.0.2
requests==2.32.3
ll7 marked this conversation as resolved.
Show resolved Hide resolved
rich==13.9.4
-e git+https://github.com/ll7/robot_sf_ll7.git@ebfcd90eae11699941580e2d0237fd6b4e7b5200#egg=robot_sf
scalene==1.5.48
scipy==1.14.1
sentry-sdk==2.18.0
setproctitle==1.3.4
setuptools==75.5.0
Shimmy==2.0.0
six==1.16.0
smmap==5.0.1
SQLAlchemy==2.0.36
stable_baselines3==2.4.0
svgelements==1.9.6
sympy==1.13.1
tensorboard==2.18.0
tensorboard-data-server==0.7.2
tk==0.1.0
toml==0.10.2
tomlkit==0.13.2
torch==2.5.1
tqdm==4.67.0
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.2.3
wandb==0.18.7
Werkzeug==3.1.3
wheel==0.45.0
117 changes: 16 additions & 101 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,101 +1,16 @@
absl-py==2.1.0
alembic==1.13.1
appdirs==1.4.4
astroid==3.0.3
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
cloudpickle==3.0.0
colorlog==6.8.2
contourpy==1.2.0
cycler==0.12.1
dill==0.3.8
docker-pycreds==0.4.0
exceptiongroup==1.2.0
Farama-Notifications==0.0.4
filelock==3.13.1
fonttools==4.49.0
fsspec==2024.2.0
gitdb==4.0.11
GitPython==3.1.42
greenlet==3.0.3
grpcio==1.60.1
gym==0.26.2
gym-notices==0.0.8
gymnasium==0.29.1
idna==3.6
iniconfig==2.0.0
isort==5.13.2
Jinja2==3.1.3
kiwisolver==1.4.5
llvmlite==0.42.0
loguru==0.7.2
Mako==1.3.2
Markdown==3.5.2
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.6.1
mccabe==0.7.0
mdurl==0.1.2
mpmath==1.3.0
networkx==3.2.1
numba==0.59.0
numpy==1.26.4
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==8.9.2.26
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.19.3
nvidia-nvjitlink-cu12==12.3.101
nvidia-nvtx-cu12==12.1.105
optuna==3.5.0
packaging==23.2
pandas==2.2.0
Pillow==9.2.0
platformdirs==4.2.0
pluggy==1.4.0
protobuf==4.25.3
psutil==5.9.8
pyarrow==15.0.0
pygame==2.1.2
Pygments==2.17.2
pylint==3.0.3
pynvml==11.4.1
pyparsing==3.1.1
pytest==8.0.1
python-dateutil==2.8.2
pytz==2024.1
PyYAML==6.0.1
requests==2.31.0
rich==13.7.0
scalene==1.5.34
scipy==1.12.0
sentry-sdk==1.40.6
setproctitle==1.3.3
Shimmy==1.3.0
six==1.16.0
smmap==5.0.1
SQLAlchemy==2.0.27
stable-baselines3==2.2.1
sympy==1.12
tensorboard==2.16.2
tensorboard-data-server==0.7.2
tk==0.1.0
toml==0.10.2
tomli==2.0.1
tomlkit==0.12.3
torch==2.2.0
tqdm==4.66.2
triton==2.2.0
typing_extensions==4.9.0
tzdata==2024.1
urllib3==2.2.1
wandb==0.16.4
Werkzeug==3.0.1
loguru==0.7.2
svgelements==1.9.6
gymnasium
gym
ll7 marked this conversation as resolved.
Show resolved Hide resolved
loguru
ll7 marked this conversation as resolved.
Show resolved Hide resolved
numba
numpy
optuna
psutil
pygame
pytest
scalene
torch
tqdm
wandb
svgelements
stable-baselines3[extra]
shimmy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Add version constraints and remove redundant gym dependency

  • The codebase exclusively uses gymnasium (not gym) in all imports and class inheritance
  • setup.py already specifies gymnasium as a requirement and Python >=3.9
  • Key dependencies have compatible Python requirements (all support Python 3.9)

Recommendations:

  • Remove gym from requirements.txt as it's not used
  • Add version constraints aligned with setup.py:
gymnasium>=0.29.0
torch>=2.0.0
stable-baselines3[extra]>=2.0.0
  • Keep other dependencies but consider adding minimum versions
🔗 Analysis chain

Consider adding version constraints for critical dependencies

Removing all version constraints could lead to compatibility issues when new versions are released. Consider adding version constraints at least for critical dependencies like torch, gymnasium, and stable-baselines3.

Let's verify the compatibility between these packages:


Let me gather more information about the dependencies by checking setup.py and any other configuration files that might have version constraints.


Let me check the actual usage of gym vs gymnasium in those files to understand if both are really needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check compatibility between key dependencies

# Check latest versions and their Python requirements
echo "Checking Python requirements for key packages..."
for pkg in torch gymnasium stable-baselines3; do
  echo "=== $pkg ==="
  curl -s "https://pypi.org/pypi/$pkg/json" | jq -r '.info | "Latest version: " + .version + "\nPython requires: " + .requires_python'
done

Length of output: 945


Script:

#!/bin/bash
# Check setup.py and other potential dependency files
echo "=== Checking setup.py ==="
fd "setup.py|pyproject.toml" --type f --exec cat {}

echo -e "\n=== Checking for other requirement files ==="
fd "requirements.*\.txt" --type f --exec cat {}

echo -e "\n=== Checking imports of gymnasium and gym ==="
rg -l "import\s+(gym|gymnasium)" --type py

Length of output: 2289


Script:

#!/bin/bash
echo "=== Checking gymnasium/gym usage in simple_robot_env.py ==="
cat robot_sf/gym_env/simple_robot_env.py

echo -e "\n=== Checking gymnasium/gym usage in evaluate.py ==="
cat scripts/evaluate.py

Length of output: 7734

14 changes: 7 additions & 7 deletions robot_sf/gym_env/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

from typing import Union
from dataclasses import dataclass
from dataclasses import dataclass, field
ll7 marked this conversation as resolved.
Show resolved Hide resolved

from robot_sf.nav.map_config import MapDefinitionPool
from robot_sf.sensor.range_sensor import LidarScannerSettings
Expand All @@ -36,11 +36,11 @@ class EnvSettings:
"""
Data class to hold environment settings for a simulation.
"""
sim_config: SimulationSettings = SimulationSettings()
lidar_config: LidarScannerSettings = LidarScannerSettings()
robot_config: Union[DifferentialDriveSettings, BicycleDriveSettings] = \
DifferentialDriveSettings()
map_pool: MapDefinitionPool = MapDefinitionPool()
sim_config: SimulationSettings = field(default_factory=SimulationSettings)
lidar_config: LidarScannerSettings = field(default_factory=LidarScannerSettings)
robot_config: Union[DifferentialDriveSettings, BicycleDriveSettings] = field(
default_factory=DifferentialDriveSettings)
map_pool: MapDefinitionPool = field(default_factory=MapDefinitionPool)

def __post_init__(self):
"""
Expand Down Expand Up @@ -72,7 +72,7 @@ class PedEnvSettings(EnvSettings):
"""
Data class to hold environment settings for a simulation that includes an ego pedestrian.
"""
ego_ped_config: UnicycleDriveSettings = UnicycleDriveSettings()
ego_ped_config: UnicycleDriveSettings = field(default_factory=UnicycleDriveSettings)

def __post_init__(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions robot_sf/ped_ego/unicycle_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def min_velocity(self) -> float:
@dataclass
class UnicycleDriveState:
"""A class that represents the state of a unicycle drive pedestrian."""
pose: PedPose
velocity: float = field(default=0)
pose: PedPose = field(default_factory=lambda: ((0.0, 0.0), 0.0))
velocity: PolarVec2D = field(default_factory=lambda: (0.0, 0.0))

@property
def pos(self) -> Vec2D:
Expand Down Expand Up @@ -121,11 +121,11 @@ def _norm_angle(self, angle: float) -> float:


@dataclass
class UnicycleDrivePedestrian():
class UnicycleDrivePedestrian:
"""Representing a pedestrian with unicycle driving behavior"""

config: UnicycleDriveSettings
state: UnicycleDriveState = field(default=UnicycleDriveState(((0, 0), 0), 0))
state: UnicycleDriveState = field(default_factory=UnicycleDriveState)
movement: UnicycleMotion = field(init=False)

def __post_init__(self):
Expand Down
2 changes: 1 addition & 1 deletion robot_sf/render/sim_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SimulationView:
screen: pygame.surface.Surface = field(init=False)
font: pygame.font.Font = field(init=False)
redraw_needed: bool = field(init=False, default=False)
offset: np.array = field(init=False, default=np.array([0, 0]))
offset: np.array = field(default_factory=np.array([0, 0]))
caption: str = 'RobotSF Simulation'
focus_on_robot: bool = False
focus_on_ego_ped: bool = False
Expand Down
4 changes: 2 additions & 2 deletions robot_sf/robot/bicycle_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def _norm_angle(self, angle: float) -> float:


@dataclass
class BicycleDriveRobot():
class BicycleDriveRobot:
"""Representing a robot with bicycle driving behavior"""

config: BicycleDriveSettings
state: BicycleDriveState = field(default=BicycleDriveState(((0, 0), 0), 0))
state: BicycleDriveState = field(default_factory=lambda: BicycleDriveState(pose=((0.0, 0.0), 0.0)))
movement: BicycleMotion = field(init=False)

def __post_init__(self):
Expand Down
10 changes: 5 additions & 5 deletions robot_sf/robot/differential_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __post_init__(self):

@dataclass
class DifferentialDriveState:
pose: RobotPose
velocity: PolarVec2D = field(default=(0, 0))
last_wheel_speeds: WheelSpeedState = field(default=(0, 0))
wheel_speeds: WheelSpeedState = field(default=(0, 0))
pose: RobotPose = ((0.0, 0.0), 0.0)
velocity: PolarVec2D = (0.0, 0.0)
last_wheel_speeds: WheelSpeedState = (0.0, 0.0)
wheel_speeds: WheelSpeedState = (0.0, 0.0)


DifferentialDriveAction = Tuple[float, float] # (linear velocity, angular velocity)
Expand Down Expand Up @@ -193,7 +193,7 @@ class DifferentialDriveRobot():

ll7 marked this conversation as resolved.
Show resolved Hide resolved
config: DifferentialDriveSettings # Configuration settings for the robot
# Default state of the robot on initialization
state: DifferentialDriveState = field(default=DifferentialDriveState(((0, 0), 0)))
state: DifferentialDriveState = field(default_factory=DifferentialDriveState)
# Movement logic for the robot based on the config; initialized post-creation
movement: DifferentialDriveMotion = field(init=False)

Expand Down
29 changes: 14 additions & 15 deletions robot_sf/sim/sim_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@
@dataclass
class SimulationSettings:
"""
Class to hold the settings for a simulation.

This class contains various settings that control the behavior of the simulation,
such as the simulation time, the time per step, the pedestrian speed multiplier, the
difficulty level, the maximum number of pedestrians per group, the pedestrian radius,
the goal radius, the number of steps to stack in observations, whether to use the next
goal in the path as the current goal, the pedestrian-robot force configuration, and the
pedestrian density by difficulty level.

After initialization, the `__post_init__` method is called to validate the settings.
Configuration settings for the simulation.
"""

# Simulation time in seconds
Expand All @@ -40,9 +31,11 @@ class SimulationSettings:
# Whether to use the next goal in the path as the current goal
use_next_goal: bool = True
# Pedestrian-robot force configuration
prf_config: PedRobotForceConfig = PedRobotForceConfig(is_active=True)
prf_config: PedRobotForceConfig = field(default_factory=PedRobotForceConfig)
# Pedestrian density by difficulty level
ped_density_by_difficulty: List[float] = field(default_factory=lambda: [0.01, 0.02, 0.04, 0.08])
ped_density_by_difficulty: List[float] = field(
default_factory=lambda: [0.01, 0.02, 0.04, 0.08]
)

def __post_init__(self):
"""
Expand All @@ -53,7 +46,9 @@ def __post_init__(self):
"""
# Check that the simulation time is positive
if self.sim_time_in_secs <= 0:
raise ValueError("Simulation length for episodes mustn't be negative or zero!")
raise ValueError(
"Simulation length for episodes mustn't be negative or zero!"
)
# Check that the time per step is positive
if self.time_per_step_in_secs <= 0:
raise ValueError("Step time mustn't be negative or zero!")
Expand All @@ -62,7 +57,9 @@ def __post_init__(self):
raise ValueError("Pedestrian speed mustn't be negative or zero!")
# Check that the maximum number of pedestrians per group is positive
if self.max_peds_per_group <= 0:
raise ValueError("Maximum pedestrians per group mustn't be negative or zero!")
raise ValueError(
"Maximum pedestrians per group mustn't be negative or zero!"
)
# Check that the pedestrian radius is positive
if self.ped_radius <= 0:
raise ValueError("Pedestrian radius mustn't be negative or zero!")
Expand All @@ -71,7 +68,9 @@ def __post_init__(self):
raise ValueError("Goal radius mustn't be negative or zero!")
# Check that the difficulty level is within the valid range
if not 0 <= self.difficulty < len(self.ped_density_by_difficulty):
raise ValueError("No pedestrian density registered for selected difficulty level!")
raise ValueError(
"No pedestrian density registered for selected difficulty level!"
)
# Check that the pedestrian-robot force configuration is specified
if not self.prf_config:
raise ValueError("Pedestrian-Robot-Force settings need to be specified!")
Expand Down
Loading