Merge branch 'fix_automatic_render' into pr_v0.3.0

This commit is contained in:
Dominik Moritz Roth 2024-02-16 16:48:27 +01:00
commit 1008c84a4b
12 changed files with 130 additions and 1 deletions

40
.github/workflows/host_docs_static.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Deploy static docs to Pages
on:
push:
branches: ["release"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/build/html'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

View File

@ -115,6 +115,7 @@ class AntJumpEnv(AntEnvCustomXML):
contact_force_range=contact_force_range,
reset_noise_scale=reset_noise_scale,
exclude_current_positions_from_observation=exclude_current_positions_from_observation, **kwargs)
self.render_active = False
def step(self, action):
self.current_step += 1
@ -153,8 +154,15 @@ class AntJumpEnv(AntEnvCustomXML):
}
truncated = False
if self.render_active and self.render_mode=='human':
self.render()
return obs, reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def _get_obs(self):
return np.append(super()._get_obs(), self.goal)

View File

@ -44,6 +44,7 @@ class BeerPongEnv(MujocoEnv, utils.EzPickle):
}
def __init__(self, **kwargs):
utils.EzPickle.__init__(self)
self._steps = 0
# Small Context -> Easier. Todo: Should we do different versions?
# self.xml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "beerpong_wo_cup.xml")
@ -89,7 +90,7 @@ class BeerPongEnv(MujocoEnv, utils.EzPickle):
observation_space=self.observation_space,
**kwargs
)
utils.EzPickle.__init__(self)
self.render_active = False
@property
def start_pos(self):
@ -169,8 +170,15 @@ class BeerPongEnv(MujocoEnv, utils.EzPickle):
truncated = False
if self.render_active and self.render_mode=='human':
self.render()
return ob, reward, terminated, truncated, infos
def render(self):
self.render_active = True
return super().render()
def _get_obs(self):
theta = self.data.qpos.flat[:7].copy()
theta_dot = self.data.qvel.flat[:7].copy()

View File

@ -4,6 +4,7 @@ import numpy as np
from gymnasium import utils, spaces
from gymnasium.envs.mujoco import MujocoEnv
from fancy_gym.envs.mujoco.box_pushing.box_pushing_utils import rot_to_quat, get_quaternion_error, rotation_distance
from fancy_gym.envs.mujoco.box_pushing.box_pushing_utils import rot_to_quat, get_quaternion_error, rotation_distance
from fancy_gym.envs.mujoco.box_pushing.box_pushing_utils import q_max, q_min, q_dot_max, q_torque_max
from fancy_gym.envs.mujoco.box_pushing.box_pushing_utils import desired_rod_quat
@ -60,6 +61,7 @@ class BoxPushingEnvBase(MujocoEnv, utils.EzPickle):
frame_skip=self.frame_skip,
observation_space=self.observation_space, **kwargs)
self.action_space = spaces.Box(low=-1, high=1, shape=(7,))
self.render_active = False
def step(self, action):
action = 10 * np.clip(action, self.action_space.low, self.action_space.high)
@ -108,8 +110,15 @@ class BoxPushingEnvBase(MujocoEnv, utils.EzPickle):
terminated = episode_end and infos['is_success']
truncated = episode_end and not infos['is_success']
if self.render_active and self.render_mode=='human':
self.render()
return obs, reward, terminated, truncated, infos
def render(self):
self.render_active = True
return super().render()
def reset_model(self):
# rest box to initial position
self.set_state(self.init_qpos_box_pushing, self.init_qvel_box_pushing)

View File

@ -60,7 +60,11 @@ class HalfCheetahEnvCustomXML(HalfCheetahEnv):
default_camera_config=DEFAULT_CAMERA_CONFIG,
**kwargs,
)
self.render_active = False
def render(self):
self.render_active = True
return super().render()
class HalfCheetahJumpEnv(HalfCheetahEnvCustomXML):
"""
@ -120,6 +124,9 @@ class HalfCheetahJumpEnv(HalfCheetahEnvCustomXML):
'max_height': self.max_height
}
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def _get_obs(self):

View File

@ -88,6 +88,12 @@ class HopperEnvCustomXML(HopperEnv):
**kwargs,
)
self.render_active = False
def render(self):
self.render_active = True
return super().render()
class HopperJumpEnv(HopperEnvCustomXML):
"""
@ -201,6 +207,10 @@ class HopperJumpEnv(HopperEnvCustomXML):
healthy=self.is_healthy,
contact_dist=self.contact_dist or 0
)
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def _get_obs(self):

View File

@ -140,6 +140,9 @@ class HopperJumpOnBoxEnv(HopperEnvCustomXML):
truncated = self.current_step >= self.max_episode_steps and not terminated
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def _get_obs(self):

View File

@ -61,6 +61,8 @@ class HopperThrowEnv(HopperEnvCustomXML):
exclude_current_positions_from_observation=exclude_current_positions_from_observation,
**kwargs)
self.render_active = False
def step(self, action):
self.current_step += 1
self.do_simulation(action, self.frame_skip)
@ -94,8 +96,15 @@ class HopperThrowEnv(HopperEnvCustomXML):
}
truncated = False
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def _get_obs(self):
return np.append(super()._get_obs(), self.goal)

View File

@ -68,6 +68,7 @@ class HopperThrowInBasketEnv(HopperEnvCustomXML):
reset_noise_scale=reset_noise_scale,
exclude_current_positions_from_observation=exclude_current_positions_from_observation,
**kwargs)
self.render_active = False
def step(self, action):
@ -118,8 +119,15 @@ class HopperThrowInBasketEnv(HopperEnvCustomXML):
}
truncated = False
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def _get_obs(self):
return np.append(super()._get_obs(), self.basket_x)

View File

@ -47,6 +47,8 @@ class ReacherEnv(MujocoEnv, utils.EzPickle):
**kwargs
)
self.render_active = False
def step(self, action):
self._steps += 1
@ -77,8 +79,15 @@ class ReacherEnv(MujocoEnv, utils.EzPickle):
goal=self.goal if hasattr(self, "goal") else None
)
if self.render_active and self.render_mode=='human':
self.render()
return ob, reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def distance_reward(self):
vec = self.get_body_com("fingertip") - self.get_body_com("target")
return -self._reward_weight * np.linalg.norm(vec)

View File

@ -71,6 +71,8 @@ class TableTennisEnv(MujocoEnv, utils.EzPickle):
observation_space=self.observation_space,
**kwargs)
self.render_active = False
if ctxt_dim == 2:
self.context_bounds = CONTEXT_BOUNDS_2DIMS
elif ctxt_dim == 4:
@ -158,8 +160,15 @@ class TableTennisEnv(MujocoEnv, utils.EzPickle):
terminated, truncated = self._terminated, False
if self.render_active and self.render_mode=='human':
self.render()
return self._get_obs(), reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def _contact_checker(self, id_1, id_2):
for coni in range(0, self.data.ncon):
con = self.data.contact[coni]

View File

@ -79,6 +79,8 @@ class Walker2dEnvCustomXML(Walker2dEnv):
**kwargs,
)
self.render_active = False
class Walker2dJumpEnv(Walker2dEnvCustomXML):
"""
@ -145,8 +147,15 @@ class Walker2dJumpEnv(Walker2dEnvCustomXML):
}
truncated = False
if self.render_active and self.render_mode=='human':
self.render()
return observation, reward, terminated, truncated, info
def render(self):
self.render_active = True
return super().render()
def _get_obs(self):
return np.append(super()._get_obs(), self.goal)