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

Unwrap gymnasium Env before accessing mobile-env attributes #59

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ jobs:
- name: Run tests with pytest
run: |
pytest

- name: Run test notebook
run: |
pytest --nbmake examples/test.ipynb
641 changes: 313 additions & 328 deletions examples/demo.ipynb

Large diffs are not rendered by default.

105 changes: 82 additions & 23 deletions examples/rllib.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mobile_env/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def reset(self, *, seed=None, options=None):
self.rng = np.random.default_rng(self.seed)

# extra options currently not supported
if options is not None:
if options is not None and options != {}:
raise NotImplementedError(
"Passing extra options on env.reset() is not supported."
)
Expand Down
11 changes: 8 additions & 3 deletions mobile_env/wrappers/multi_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@


class RLlibMAWrapper(MultiAgentEnv):
def __init__(self, env: MComCore):
def __init__(self, env: gymnasium.Env):
super().__init__()

# class wrapps environment object
self.env = env
# Keep a reference to the mobile-env base environment, which is wrapped by this class.
# Remove any gymnasium wrappers first if needed.
if isinstance(env, MComCore):
self.env: MComCore = env
else:
assert isinstance(env.unwrapped, MComCore), "The unwrapped env should be a mobile-env."
self.env = env.unwrapped

# set max. number of steps for RLlib trainer
self.max_episode_steps = self.env.EP_MAX_TIME
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


requirements = [
"gymnasium<1.0.0",
"gymnasium",
"matplotlib",
"numpy",
"pandas",
Expand All @@ -20,7 +20,7 @@

setup(
name="mobile-env",
version="2.0.3",
version="2.1.0",
author="Stefan Schneider, Stefan Werner",
description="mobile-env: An Open Environment for Autonomous Coordination in "
"Wireless Mobile Networks",
Expand Down
12 changes: 5 additions & 7 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# extra requirements for testing
pre-commit
# limit importlib to avoid flake8 error: https://stackoverflow.com/a/73932581/2745116
importlib-metadata<5.0
importlib-metadata
flake8
pytest
nbmake
# Older stable baselines versions do not support gymnasium
#stable-baselines3>=2.0.0
sb3_contrib>=2.0.0a1
# Only Ray 2.3+ supports gymnasium
# TODO: enable ray later; conflicts with sb3; not needed for tests
#ray[rllib]>=2.3.0
stable-baselines3>=2.0.0
# Only Ray 2.3+ supports gymnasium. Ray 2.39 needs gymnasium 1.0 and isn't fully supported yet.
#ray[rllib]>=2.3.0, <2.39