Skip to content

Commit

Permalink
further compat changes for gymnasium update;
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Schumacher committed Aug 14, 2024
1 parent 0fbd06e commit 3f95996
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 2,975 deletions.
2 changes: 1 addition & 1 deletion deprl/dep_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from collections import deque

import gym
import gymnasium as gym
import torch

torch.set_default_dtype(torch.float32)
Expand Down
2 changes: 1 addition & 1 deletion deprl/env_wrappers/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod

import gym
import gymnasium as gym
import numpy as np

import deprl # noqa
Expand Down
6 changes: 3 additions & 3 deletions deprl/vendor/tonic/environments/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from types import SimpleNamespace

import gym.wrappers
from gymnasium import wrappers
import numpy as np

try:
Expand Down Expand Up @@ -55,7 +55,7 @@ def _builder(name, *args, **kwargs):
environment.spec = SimpleNamespace(
max_episode_steps=time_limit, id="ostrichrl-dmcontrol"
)
return gym.wrappers.TimeLimit(environment, time_limit)
return wrappers.TimeLimit(environment, time_limit)

return build_environment(_builder, *args, **kwargs, header=None)

Expand Down Expand Up @@ -97,7 +97,7 @@ def build_environment(

# Remove the TimeLimit wrapper if needed.
if not terminal_timeouts:
if type(environment) == gym.wrappers.TimeLimit:
if type(environment) == wrappers.TimeLimit:
environment = environment.env

# Add time as a feature if needed.
Expand Down
2 changes: 1 addition & 1 deletion deprl/vendor/tonic/environments/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Environment wrappers."""

import gym
import gymnasium as gym
import numpy as np


Expand Down
7 changes: 4 additions & 3 deletions examples/example_load_baseline_myosuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@

import myosuite # noqa
from myosuite.utils import gym
from deprl import env_wrappers

import deprl

env = gym.make("myoLegWalk-v0", reset_type="random")
env = env_wrappers.GymWrapper(env)
policy = deprl.load_baseline(env)

env.seed(0)
for ep in range(10):
ep_steps = 0
ep_tot_reward = 0
state, _ = env.reset()
state = env.reset()

while True:
# samples random action
action = policy(state)
# applies action and advances environment by one step
state, reward, terminated, truncated, info = env.step(action)
state, reward, done, info = env.step(action)

ep_steps += 1
ep_tot_reward += reward
env.mj_render()
time.sleep(0.01)

# check if done
done = terminated or truncated
if done or (ep_steps >= 1000):
print(
f"Episode {ep} ending; steps={ep_steps}; reward={ep_tot_reward:0.3f};"
Expand Down
2 changes: 1 addition & 1 deletion examples/example_only_dep_myosuite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time

import gym
import myosuite # noqa
from myosuite.utils import gym

from deprl import env_wrappers
from deprl.dep_controller import DEP
Expand Down
2,960 changes: 0 additions & 2,960 deletions poetry.lock

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ numpy = "^1.22.4"
termcolor = "^2.2.0"
pandas = "^2.0.1"
gdown = "^5.1.0"
gym = "0.13.0"
gymnasium = "*"
wandb = "^0.15.4"
# torch = {version="2.1.0", source="pytorch-cpu"}
torch = ">=2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/test_settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"tonic": {
"header": "import deprl, gym, myosuite",
"header": "import deprl, myosuite; from myosuite.utils import gym",
"agent": "deprl.custom_agents.dep_factory(3, deprl.custom_mpo_torch.TunedMPO())(replay=deprl.replays.buffers.Buffer(return_steps=3, batch_size=256, steps_between_batches=1000, batch_iterations=30, steps_before_batches=2e5, size=int(1e4)))",
"environment": "deprl.environments.Gym('myoLegWalk-v0', scaled_actions=False, reset_type='random')",
"trainer": "deprl.custom_trainer.Trainer(steps=int(2e3), epoch_steps=int(1e3), save_steps=int(1e3))",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/test_settings_load.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"tonic": {
"header": "import deprl, gym, myosuite",
"header": "import deprl, myosuite; from myosuite.utils import gym",
"agent": "deprl.custom_agents.dep_factory(3, deprl.custom_mpo_torch.TunedMPO())(replay=deprl.replays.buffers.Buffer(return_steps=3, batch_size=256, steps_between_batches=1000, batch_iterations=30, steps_before_batches=2e5, size=int(1e4)))",
"environment": "deprl.environments.Gym('myoLegWalk-v0', scaled_actions=False, reset_type='random')",
"trainer": "deprl.custom_trainer.Trainer(steps=int(3e3), epoch_steps=int(1e3), save_steps=int(1e3))",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/test_settings_load_no_resume.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"tonic": {
"header": "import deprl, gym, myosuite",
"header": "import deprl, myosuite; from myosuite.utils import gym",
"agent": "deprl.custom_agents.dep_factory(3, deprl.custom_mpo_torch.TunedMPO())(replay=deprl.replays.buffers.Buffer(return_steps=3, batch_size=256, steps_between_batches=1000, batch_iterations=30, steps_before_batches=2e5, size=int(1e4)))",
"environment": "deprl.environments.Gym('myoLegWalk-v0', scaled_actions=False, reset_type='random')",
"trainer": "deprl.custom_trainer.Trainer(steps=int(3e3), epoch_steps=int(1e3), save_steps=int(1e3))",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/test_settings_load_resume.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
"tonic": {
"header": "import deprl, gym, myosuite",
"header": "import deprl, myosuite; from myosuite.utils import gym",
"agent": "deprl.custom_agents.dep_factory(3, deprl.custom_mpo_torch.TunedMPO())(replay=deprl.replays.buffers.Buffer(return_steps=3, batch_size=256, steps_between_batches=1000, batch_iterations=30, steps_before_batches=2e5, size=int(1e4)))",
"environment": "deprl.environments.Gym('myoLegWalk-v0', scaled_actions=False, reset_type='random')",
"trainer": "deprl.custom_trainer.Trainer(steps=int(3e3), epoch_steps=int(1e3), save_steps=int(1e3))",
Expand Down

0 comments on commit 3f95996

Please sign in to comment.