Ensure envs are closed
This commit is contained in:
parent
f1d3b5333f
commit
da042eebd9
@ -41,6 +41,7 @@ def example_mp(env_name="fancy_ProMP/HoleReacher-v0", seed=1, iterations=1, rend
|
|||||||
if terminated or truncated:
|
if terminated or truncated:
|
||||||
print(reward)
|
print(reward)
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
env.close()
|
||||||
|
|
||||||
|
|
||||||
def example_custom_mp(env_name="fancy_ProMP/Reacher5d-v0", seed=1, iterations=1, render=True):
|
def example_custom_mp(env_name="fancy_ProMP/Reacher5d-v0", seed=1, iterations=1, render=True):
|
||||||
@ -80,6 +81,7 @@ def example_custom_mp(env_name="fancy_ProMP/Reacher5d-v0", seed=1, iterations=1,
|
|||||||
print(i, reward)
|
print(i, reward)
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
|
||||||
|
env.close()
|
||||||
return obs
|
return obs
|
||||||
|
|
||||||
class Custom_MPWrapper(fancy_gym.envs.mujoco.reacher.MPWrapper):
|
class Custom_MPWrapper(fancy_gym.envs.mujoco.reacher.MPWrapper):
|
||||||
@ -147,12 +149,12 @@ def example_fully_custom_mp(seed=1, iterations=1, render=True):
|
|||||||
|
|
||||||
env = gym.make(custom_env_id_ProMP, render_mode='human' if render else None)
|
env = gym.make(custom_env_id_ProMP, render_mode='human' if render else None)
|
||||||
|
|
||||||
if render:
|
|
||||||
env.render()
|
|
||||||
|
|
||||||
rewards = 0
|
rewards = 0
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
|
||||||
|
if render:
|
||||||
|
env.render()
|
||||||
|
|
||||||
# number of samples/full trajectories (multiple environment steps)
|
# number of samples/full trajectories (multiple environment steps)
|
||||||
for i in range(iterations):
|
for i in range(iterations):
|
||||||
ac = env.action_space.sample()
|
ac = env.action_space.sample()
|
||||||
@ -164,6 +166,12 @@ def example_fully_custom_mp(seed=1, iterations=1, render=True):
|
|||||||
rewards = 0
|
rewards = 0
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
|
||||||
|
try: # Some mujoco-based envs don't correlcty implement .close
|
||||||
|
env.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def example_fully_custom_mp_alternative(seed=1, iterations=1, render=True):
|
def example_fully_custom_mp_alternative(seed=1, iterations=1, render=True):
|
||||||
"""
|
"""
|
||||||
Instead of defining the mp_args in a new custom MP_Wrapper, they can also be provided during registration.
|
Instead of defining the mp_args in a new custom MP_Wrapper, they can also be provided during registration.
|
||||||
@ -200,12 +208,12 @@ def example_fully_custom_mp_alternative(seed=1, iterations=1, render=True):
|
|||||||
|
|
||||||
env = gym.make(custom_env_id_ProMP, render_mode='human' if render else None)
|
env = gym.make(custom_env_id_ProMP, render_mode='human' if render else None)
|
||||||
|
|
||||||
if render:
|
|
||||||
env.render()
|
|
||||||
|
|
||||||
rewards = 0
|
rewards = 0
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
|
||||||
|
if render:
|
||||||
|
env.render()
|
||||||
|
|
||||||
# number of samples/full trajectories (multiple environment steps)
|
# number of samples/full trajectories (multiple environment steps)
|
||||||
for i in range(iterations):
|
for i in range(iterations):
|
||||||
ac = env.action_space.sample()
|
ac = env.action_space.sample()
|
||||||
@ -234,6 +242,12 @@ def example_fully_custom_mp_alternative(seed=1, iterations=1, render=True):
|
|||||||
rewards = 0
|
rewards = 0
|
||||||
obs = env.reset()
|
obs = env.reset()
|
||||||
|
|
||||||
|
try: # Some mujoco-based envs don't correlcty implement .close
|
||||||
|
env.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
render = False
|
render = False
|
||||||
# DMP
|
# DMP
|
||||||
|
Loading…
Reference in New Issue
Block a user