Skip to content

Commit

Permalink
added more example files for pure dep exploration
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Schumacher authored and Pierre Schumacher committed Mar 13, 2024
1 parent 2ba76ff commit 62f04b3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deprl/dep_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class DEP:
"""
DEP Implementation from Der et al.(2015).
Jax is used instead of numpy to speed up computation, GPU strongly
PyTorch is used instead of numpy to speed up computation, GPU strongly
recommended.
In the future, proper JAX features such as jit, vmap, etc
should be used.
Expand Down
25 changes: 25 additions & 0 deletions examples/example_only_dep_myosuite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import gym
import myosuite
import time
from deprl import env_wrappers
from deprl.dep_controller import DEP



env = gym.make('myoLegWalk-v0')
env = env_wrappers.GymWrapper(env)

# You can also use SconeWrapper for Wrapper
# env = env_wrappers.SconeWrapper(env)
dep = DEP()
dep.initialize(env.observation_space, env.action_space)

env.reset()
for i in range(1000):
action = dep.step(env.muscle_lengths())[0,:]
print(action.shape)
next_state, reward, done, _ = env.step(action)
time.sleep(0.01)
env.mj_render()


49 changes: 49 additions & 0 deletions examples/example_only_dep_scone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import gym
import sconegym
from deprl import env_wrappers
from deprl.dep_controller import DEP


# create the sconegym env
env = gym.make('sconewalk_h2190-v1')

# apply wrapper to environment
env = env_wrappers.SconeWrapper(env)

# create DEP, parameters are loaded from default path
dep = DEP()

# give DEP obs and action space to create right dimensions
dep.initialize(env.observation_space, env.action_space)

env.seed(0)

for ep in range(5):
if ep % 1 == 0:
env.store_next_episode() # Store results of every Nth episode

ep_steps = 0
ep_tot_reward = 0
state = env.reset()

while True:
# samples random action
action = dep.step(env.muscle_lengths())[0,:]
# applies action and advances environment by one step
state, reward, done, info = env.step(action)

ep_steps += 1
ep_tot_reward += reward

# check if done
if done or (ep_steps >= 1000):
print(
f"Episode {ep} ending; steps={ep_steps}; reward={ep_tot_reward:0.3f}; \
com={env.model.com_pos()}"
)
env.write_now()
env.reset()
break

env.close()

0 comments on commit 62f04b3

Please sign in to comment.