Skip to content

Commit

Permalink
change to gitignore and added numpy version wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Schumacher committed Sep 15, 2024
1 parent dbcc0b7 commit 6c27cb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ tags
# OSL logs #
osl.csv
osl.log
/workspace
/workspace

*processed.xml
2 changes: 2 additions & 0 deletions myosuite/envs/env_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from myosuite.physics.sim_scene import SimScene
import myosuite.utils.import_utils as import_utils
from myosuite.envs.env_variants import gym_registry_specs
from myosuite.utils import NPRandomVersionWrapper

# TODO
# remove rwd_mode
Expand Down Expand Up @@ -486,6 +487,7 @@ def seed(self, seed=None):
"""
self.input_seed = seed
self.np_random, seed = gym.utils.seeding.np_random(seed)
self.np_random = NPRandomVersionWrapper(self.np_random)
return [seed]


Expand Down
19 changes: 19 additions & 0 deletions myosuite/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import importlib.util
from functools import wraps


# Utility to import gym/gymnasium
def import_gym():
Expand All @@ -17,4 +19,21 @@ def import_gym():
raise ModuleNotFoundError(help)
return gg
gym = import_gym()


# utility to allow different numpy versions
class NPRandomVersionWrapper:
def __init__(self, np_random):
self.np_random = np_random

def __getattr__(self, name):
if name == 'integers':
def integers(*args, **kwargs):
try:
return self.np_random.integers(*args, **kwargs)
except AttributeError:
# Fall back to randint if integers is not available
return self.np_random.randint(*args, **kwargs)
return integers
return getattr(self.np_random, name)

0 comments on commit 6c27cb2

Please sign in to comment.