Skip to content

Commit

Permalink
Unwrap gymnasium Env before accessing mobile-env attributes (#59)
Browse files Browse the repository at this point in the history
* Run test notebook in CI

* WIP support gym v1.0 - BLOCKER: sb3 support

Seems like the latest sb3 2.3.2 does not yet support gymnasium 1.0.0 --> shouldn't require it for mobile-env then

* Lift gymnasium version requirements

* Add sb3 to test requirements

* Unwrap gym env inside Ray wrapper
  • Loading branch information
stefanbschneider authored Nov 18, 2024
1 parent 9e68760 commit c24f31d
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 364 deletions.
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

0 comments on commit c24f31d

Please sign in to comment.